Home Java Learn-java-in-a-day Create First Program
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Create First Program

Advertisement
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 RoseIndia.net" on the console. 

 

 

 

Here is the code of createfirstprogram.java file:

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

Download this example.

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

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).
out
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 createfirstprogram.java) . After compiling successfully, you can run it. Java uses the "java" command to execute your program (Type java createfirstprogram). It will print  "Welcome to RoseIndia.net".

Output of program:

C:\vinod>javac createfirstprogram.java

C:\vinod>java createfirstprogram
Welcome to RoseIndia.net

C:\vinod>_
Advertisements

Liked it!  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.

Posted on: February 25, 2008

Ask Questions?    Discuss: Create First Program   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Pankaj Bawane
May 30, 2011
Thanks

This is very nicely explained
Abdulmanaf J.K.
July 7, 2011
About java software

i want to learn more about how to make a jave software like this simple example.
ram sharma
October 10, 2011
core java

I like your site
Karthik
February 14, 2013
CS

how to link two modules and also create a prototype for cricket player database?
EZE UCHECHUKWU ONYEKA
December 7, 2011
help

I want to know which software application I can use to learn java programming, and also how to create a graphic users interface with java for a software? Please I need help urgently. Thank you
vikas
December 12, 2011
app

i want to know how to integrate all the frames that i have created, so that it will work like a software. i mean i want an executable file that will open up my main window. simply a n executable file for windows platform. if you know anything about this then kindly mail me at vikasdevde@gmail.com thanks
khushahal
December 20, 2011
java

I am khushahal singh.
suresh
December 29, 2011
My name is suresh

I want java software
qaqnass
January 2, 2012
fff

thaks
Osama bin laden
January 9, 2012
very good thx

Thanks for teaching me java, I now know how to develop air missles, and war shit.
ablaze
March 30, 2012
java

really helpfull...............
lavikant
April 27, 2012
java

this is best
amanjot
June 8, 2012
ty

this information was really helpful to me..keep posting the programs with easy method and easy understanding especially based on constructors and functions.step wise .thnx
Aravindan
June 24, 2012
Use of string[] args

Why we are specifically using string[] and args words there..whats the use of it..
ankit
July 24, 2012
java

why we need class in java ?? we can make also by using variables??
Rameshwar Kushwaha
July 27, 2012
java

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

sent java program
ashok
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
ashok
December 22, 2012
hai

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
BELETE BEKELE
November 16, 2012
object oriented programming

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

How to run and create a simple program in JAVA.?
Cara
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
java

Plese explain the word "static" in java?
DMCA.com