Java Programming basics – Part 2
• A Java program file is an ordinary text file with “.java” extension.
• Any code in java is to be written inside a class. Just like the language, the program execution starts with the main method. In C, the function main is a global function. But in java, even the main method should be inside a class.
• File name must be a class name of class having main().
• Java Sample program:
Public class Message
Public static void main(String args)
System.out.println(“ Hello World !);
• Save the file as Message.java. (file name case sensitive).
How to Compile Java program ?
• Open a command prompt.
• Go to the directory in which the source file is saved.
• Type the following command.
o javac Message.java
• The java compiler will convert the source code into the byte code.
How to Execute Java program?
• Use the following command to execute the bytecode.
o Java Message
• When the program is run, the following output is displayed;
o Hello World !