Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
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 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>_

                         

» View all related tutorials
Related Tags: java c http tools com jsp orm date development ui form time update io download load version install test compile

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

12 comments so far (
post your own) View All Comments Latest 10 Comments:

Hi...beautifully illustrated....I got the success..:-)

Posted by Sharad on Friday, 01.30.09 @ 13:03pm | #84335

hi ter hope any one would help me to fix this...
thank u

Exception in thread "main" java.lang.NoClassDefFoundError: createfirstprogram
va
Caused by: java.lang.ClassNotFoundException: createfirstprogram.java
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: createfirstprogram.java. Program will exit.

Posted by vas on Friday, 12.12.08 @ 00:17am | #82666

Need to learn how to create databases and manipulate them in JAVA

Posted by Langson on Thursday, 11.13.08 @ 08:50am | #81645

This site is excellent all the tutorials and speciall interview questions.

Posted by neetu on Thursday, 10.30.08 @ 04:32am | #81402

Exception in thread "main" java.lang.UnsupportedClassVersionError: Divya (Unsupp
orted major.minor version 50.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

Posted by anjali on Tuesday, 09.9.08 @ 05:23am | #78144

Firsttime I run a program confidently .It worked greatly for me.Thanks RoseIndia.net

Posted by Praveena on Wednesday, 08.13.08 @ 15:29pm | #72633

i was amazed when i had seen such a good lucid understanding site with all the java stuff its really amazing world to learn!!!!

Posted by RAKESH.S on Wednesday, 05.21.08 @ 16:09pm | #60592

This didn't tell me anything and the program didn't work!

Posted by Marty on Monday, 04.28.08 @ 07:18am | #58026

in java how to connect two forms without making any validation. pls if possible send me the code. its very urgent.

Posted by varsha on Saturday, 03.29.08 @ 23:58pm | #54682

Hi

Really very useful

Posted by shoby on Saturday, 01.19.08 @ 16:15pm | #45586

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.