Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Learn-java-in-a-day Create First Program

Related Tutorials


 
 

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

If you enjoyed this post then why not add us on Google+? Add us to your Circles



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

Related Tutorials

Discuss: Create First Program   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:24
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