Download and Install java
Before the Java virtual machine (VM) can run a Java program, the program's Java source code must be compiled into byte-code using the javac compiler. Java byte-code is a platform independent version of machine code; the target machine is the Java VM rather than the underlying architecture.
First You need to download and install JVM click this link to down load Click here
Create a Java Program
Create a new text Document and Type the following code.All this code does is print Hello World! on the
screen.Remember Java is case sensitive.
class FirstProgram {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Save this file using .java extension (Please remember the .java extension)
Now Your java file is created, now we need Compiling to bit-code File (.class extension File )
Compiling Java file
Open the Windows Command prompt and set your java bin Folder path,
this is bin folder is in java install location, now set this path to your command line,copy your bin folder path type this command in your command line
path = C:\Program Files\Java\jdk1.7.0_21\bin
Now go to your .java file location and (use cd command to locate your file path) type the following command as shown.This command would compile Program.java and produce FirstProgram .class which contains Java byte code which is machine independent.
javac your .java file
If you have any errors,you would see them on the screen.Please go back to notepad and
correct the errors and resave the file.If you see a blank output after the javac command, it
means there were no errors and you are ready to run the program.You could run the
program using the command as shown in the screen shot.
Running Java Program Using command line
after compiling your file lock your file location your can see new .class file is generated this file name same to your program class FirstProgram Generated .class file name is your class name
Basic Syntax:
About Java programs, it is very important to keep in mind the following points.Case Sensitivity - Java is case sensitive, which means identifier Hello and hello would have different meaning in Java.
Class Names - For all class names the first letter should be in Upper Case.
If several words are used to form a name of the class, each inner word's first letter should be in Upper Case.
Example class MyFirstJavaClass
Method Names - All method names should start with a Lower Case letter.
If several words are used to form the name of the method, then each inner word's first letter should be in Upper Case.
Example public void myMethodName()
Program File Name - Name of the program file should exactly match the class name.
When saving the file, you should save it using the class name (Remember Java is case sensitive) and append '.java' to the end of the name (if the file name and the class name do not match your program will not compile).
Example : Assume 'MyFirstJavaProgram' is the class name. Then the file should be saved as 'MyFirstJavaProgram.java'
public static void main(String args[]) - Java program processing starts from the main() method which is a mandatory part of every Java program..
No comments:
Post a Comment