First Java Program

Steps To Create a Java File :
1.Create a folder with any name. It acts as a default package.

2.Open any text editor preferably notepad, type the program (source code and save it in the directory created in step 1. File name can be anything but extension should be (.Java)

3.Compilation : Open the DOS Prompt, make that directory as the current working directory in which our java file is stored and the following command at the DOS Prompt.

Compilation Command : Javac sample.java

Observation :
A.If the program compilation is successful we get one or more class files.
B.Else we get the errors described with one or more to rectify.

4.Program Execution : After the .class file is generated, the JVM will interprets byte code of the class file into underlying operating system. JVM knows the host of the OS environment. When the program is executed, the respective output is displayed in this case it is printing the Z value.

Interpretation Command : Java sample

class sample
//class name or java file name called sample
{
public static void main(String args[])
//main method program execution will start from here
{
int z = 10 ;
//declaring the variable and assigning a value
System.out.println(“The value of z is:”+z);
//printing the value of Z value
}
}
OUTPUT :

Leave a Comment

Your email address will not be published.