Share on Google+Share on Google+

Create First Program

In this section, you will learn to write a simple Java program. For developing a java program you just need a simple text editor like "notepad".

Create First Program


In this section, you will learn to write a simple Java program. For developing a java program you just need  a simple text editor like "notepad". 

Open the notepad and write your program. 

Let's create a class createfirstprogram that will print a message "Welcome to" on the console. 


Here is the video tutorial of: "Learn Java in a day - Create First Program"

Here is the code of file:

class createfirstprogram{
  public static void main(String[] args) {
  System.out.println("Welcome to");

Download this example.

Save this program in the specified directory ("C:\Vinod" in this example) with name  

This class contains  public, static and void java keywords (these are pre-defined words in java which carries specific meaning).

public keyword specifies the accessibility issues of a class. Here, It specifies that method can be accessed from anywhere.
static keyword  indicates that this method can be invoked simply by using the name of the class without creating any class-object.
void keyword specifies that this method will not return any type of data. 
main() method is the main entry point of the program, to start execution. First of all JVM calls the main method of a class and start execution .  JVM (Java Virtual Machine) is responsible for running java programs.
args is a string array that takes values from java command line. It's index starts from '0'. We can access values by writing args[0], args[1] etc.
println() function prints the output to the standard output stream (monitor).
represents the standard output stream (monitor).

Now, you are ready to compile and run this program. Open the command prompt and go to the directory ("C:\vinod" in this example) where your program is saved.

Java uses the "javac" command to compile your program (Type javac . After compiling successfully, you can run it. Java uses the "java" command to execute your program (Type java createfirstprogram). It will print  "Welcome to".

Output of program:


C:\vinod>java createfirstprogram
Welcome to




Posted on: February 25, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Create First Program   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
Rameshwar Kushwaha
July 27, 2012

Excellent program. begners easily understand this code.
July 27, 2012

sent java program
December 22, 2012
how to create java program

i dont know java program skill,now i am really interested java program ,but how to create to java program
December 22, 2012

how to create to java program,i dont know how to create java program ,now only i am really to interested in java program
Avinash Aryan
November 1, 2012
java se

i am a diploma stu
November 16, 2012
object oriented programming

I wantS any types of Object Oriented Programming
'Moksha Pandya'
December 1, 2012

How to run and create a simple program in JAVA.?
December 4, 2012
Command promt

I have followed your instruction to a T, but command prompt says there is no command/batch file. What should I do?
Neha Rawat
September 8, 2013

Plese explain the word "static" in java?