kirran

Monday, May 28, 2012

welcome to hello word program

Here let us c the how a basic java program works


class HelloWorld                            // here classname is hello world
{
   public static void main(String args[])
   {
      System.out.println("Hello World");
   }
}
 
 
Basic structure of java program is 
 
class classname                          
{
   public static void main(String args[])
   {
      statement 1;
      statement 2;  
      statement 3; 
      statement 4;  
 
 } 
 } 
 
 WHATEVER I SPECIFIED IN RED COLOR ,IT IS MUST FOR ANY A JAVA PROGRAM.
 
public: public is an access specifier,it can be available anywhere.
public functions are everywhere available.Jvm can be able to call correspondence 
main() function.
 
static: whenever we mention static keyword ,according to java it can be 
called by classname.Static functions are common functions,they can be called 
without the helpof object.according to java,JVM can be able to call main function
 with the help ofclassname.
  
void: whenever the main function execution is completed
 
In c/c++ it has to return a value to the os,since application is directly 
interacting with os .If main function is not returning a value ,
the os is unable to understand the program memory and it is ready to clean up .
That's why to cleanthe memory ,main function has to return a value in c/c++.
 
Best example is,my mom kept food for me,in the middle i went out what should
my mom think ? similarly os also unable to understand .This problem will be 
identified at large projects in real time,memory is not handling properly,
that is chance of system performance down.
 
but in java ,we will go for void after complication of program ,JVM will take care .
so no chance of memory wastage. 


 
 
main() : main is a name of a function,where program execution is started.

main is the starting point of the program execution and it is ending point 
of program execution.

Every program execution is done inside the stack memory.

when main() is started,stack memory is started,when main is completed stack memory 
also completed.
 

Wednesday, May 23, 2012

How to install JDK 1.7.0 and how to set path and classpath variables

JDK 1.7

How to Install

Java Development Kit (JDK) 1.7 or SE 7, which is freely available from Sun Microsystems (now part of Oracle), is needed for writing Java programs. 

JDK can be downloaded from the Java mother site @ http://java.sun.com 

How To Install JDK 1.7.0

JDK or JRE?
JRE (Java Runtime Environment) is needed for running Java programs. 

JDK (Java Development Kit), which includes JRE plus the development tools (such as compiler and debugger), is need for writing Java programs.

 Since you are supposed to write Java Programs, install JDK (which includes JRE).
STEP 0: Un-install Older Version of JDK/JRE 
If you have previously installed older version of JDK/JRE, un-install them.
 Run "Control Panel" ⇒ "Program and Features" ⇒ Un-install programs such as "Java SE Development Kit" and "Java SE Runtime". (If you are not sure whether you have older versions of JDK, check!)
STEP 1: Download JDK
  1. Goto Java SE download site @ http://www.oracle.com/technetwork/java/javase/downloads/index.html.
  2. Click the "Download" button under "JDK" of "Java SE 7".
  3. Choose your operating platform, e.g., Windows x86 (for 32-bit Windows OS - "jdk-7u2-windows-i586.exe" 84MB); or Windows x64 (for 64-bit Windows OS).
STEP 2: Install JDK/JRE
Run the downloaded installer, which installs both the JDK (Java Development Kit) and JRE (Java Runtime). By default, the JDK and JRE will be installed into directories "C:\Program Files\java\jdk1.7.0" and "C:\Program Files\java\jre7", respectively. 

here i am refering to  JDK installed directory as <JAVA_HOME>

After downloading  JDK 1.7.0,just click on it ,you will get like this ,as shown below


 click on run


 click next 



click next 


after this window,u will observe like this




you have installed successfully now,click finish.

Now we have to set PATH and CLASS PATH  variables  inorder to compile or execute java .
These are said to be environment variables.

click My computer ==> properties ==>advanced,       following window will be opened like this




Now click Environment Variables, here variables are divided into two sections 

User variables : whenever it is modified the corresponding language only effected.  

Ex: Class path , in this example class variables are always for .class values 

System variables : whenever it is modified not only a single language,  corresponding  all languages are  only effected. 

Ex:path, here the variable is searching for .exe files



 click new button



variable name = classpath

variable value =  C:\Program Files\Java\jdk1.7.0

one more environment variable ,we have to set for Java home directory similar to path and 
class path.

click new button


for java home


variable name = java_home

variable value =  C:\Program Files\Java\jdk1.7.0.

Now click ok for twice. 


now for system variables ,let us set path


click new

variable name = path

variable value = C:\Program Files\Java\jdk1.7.0\bin



IF U WANT TO VERIFY JAVA IS INSTALLED SUCCESSFULLY OR NOT ,JUST GO TO COMMAND PROMT,TYPE javac if u see java compiling commands like below ,then u have installed it successfully.




 For any clarifications or suggestions ,you can contact me through my mail,or u can comment here.