Java Basic Explanations

The program :

class HelloWorld {
public static void main(String[] args)
{
System.out.println("Hello World!"); // Display the string on a new line.
System.out.println("- Nimish Prabhu");
}
}



Firstly,

The name of the class in which main() method exists should have the name same as the file name.
In this case : HelloWorld
It is case sensitive.


System.out.println() is used to print a message on a new line.

If you want to print message on same line you can use System.out.print()



public static void main(String[] args)

The main method accepts a single argument: an array of elements of type String.

This array is the mechanism through which the runtime system passes information to your application. For example:
java MyApp arg1 arg2

Each string in the array is called a command-line argument.

Java Beginning

Before writing your first ever java program and executing it, there are few steps you should be doing.

Firstly download The Java SE Development Kit 6 (JDK 6) from this link.

Once you download and install the "JDK" (not just jre).

Open notepad and start writing your first java program as follows


class HelloWorld {
public static void main(String[] args)
{
System.out.println("Hello World!"); // Display the string on a new line.
System.out.println("- Nimish Prabhu");
}
}


You can try different texts instead of 'Hello World!'

Click File>Save As>HelloWorld.java



Now open Command Prompt

Firstly you will need to set path so that you can execute commands such as "javac", "java" etc to execute your java files.

You can set path as follows :

set path=C:\Program Files (x86)\Java\jdk1.6.0\bin

In your case the path to the bin folder of JDK might be different so change the command accordingly and press enter



Now we will go the location where we saved the java file

In my case it is D:\Java



and compile the file you just made by using the following command

javac HelloWorld.java

run the file using following command

java HelloWorld

Heres what you will get :



In this method you will have to set path to your bin folder every time you run a java file, inorder to avoid that we can permanently set path to bin folder as follows :

FOR VISTA/WINDOWS 7

Right Click on My Computer and Click Properties

Click Advanced System Settings

CLick Environment Variables

Select Path under System Variables

Click Edit

Go to the end of the text and add

;C:\Program Files (x86)\Java\jdk1.6.0\bin

(It will be different for you, depending on the location of your jdk bin folder)

Click Ok 3 times and Reopen Command Prompt

Now you can compile and run java programs as explained above.

How to set path for java in windows 7 and vista

------------------------------------------

Setting Path on Windows XP :

Start -> Control Panel -> System -> Advanced

Click on Environment Variables, under System Variables, find PATH, and click on it.

In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value.

Close the window.

Reopen Command prompt window, and run your java code.

Java Tutorials for Beginners



Java is a programming language originally developed by James Gosling at Sun Microsystems (which is now a subsidiary of Oracle Corporation) and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java was created with the idea of "write once, run anywhere." It started out as a popular language for building games and other programs that run within a browser; later it began to be used in consumer devices such as cell phones. To start with coding in Java follow the tutorials.