Gadgets

Saturday, 14 November 2015

set environment variables and first java program in detailed

set environment variables and first java program in detailed


1.    Set Permanent path:

Go to MyComputer properties à advanced tab à environment variables ànew tab of user variable à write path in variable name à write path of bin folder in variable value   à ok à ok à ok.

1.    Right click on MyComputer and select Properties

2.    Click on Advanced system settings

3.    Click on Environment Variables

4.    Click on New in user variables

5.    Copy bin folder path

6.    Write “path” in variable name and past the path of bin folder.in variable value and click on “ok”.

7.    Click on “ok”

8.    Click on “ok”


1.   
Temporary path:

Copy the bin path and past it in command prompt as
“set path= C:\Program Files\Java\jdk1.6.0\bin”

Here I set temporary path for D driveàprograms folder because I save all my programs in that folder.

First java program in detailed:

public class Test
{
  public static void main(String[] arg)
    {
           System.out.println("This is my first java program");
     }
}

Open notepad and write the above program



I saved that program as “Test.java” in drive Dàprograms folder


Compile it “javac Test.java” and after compiled it, created a .class file


Run that .class file as “java Test” command


Explanation:

public class Test

public keyword is an access modifier, it mean other classes can access this class.
class is a keyword to declare the class name.
“Test” is a class name of this program.
{ open brace, it mean starting of the class scope.

public static void main(String[] arg)

static is a keyword. If we declare a method as static, no need to create object for that method. Here no need to create object to invoke main method. The main method is executed by JVM.
void is return type. It does not return any value.
“main” is a method name. It represents startup of the program.
(String[] arg) is main method parameter, it stores the  values as String array format  “arg” is a variable, we can give other name whatever we want(a[],b[],ect..).

Example:

String a=arg[0];
String b=arg[1];
{ open brace for main method.

System.out.println("This is my first java program");

System is a class in the java.lang package.
“out” is a static member of the System class
“println” is a method of the java.io.PrintStream
} close main method
} close class

Execution:


Save the above program as: “Test.java”
Compile:  javac “Test.java”
Execution:  java “Test.java”
Output:   This is my first java program 





No comments:

Post a Comment