iT Portal

Java Programming basics – Part 2

Java Programming
• 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 (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

• The java compiler will convert the source code into the byte code.
o Message.class

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 !

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: