Home Java Javafile Sample Java program for beginners
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Sample Java program for beginners

Advertisement
Here beginners in Java can learn to create there first Hello World program in Java. To install Java one needs JDK (Java Development Kit), which can be downloaded from Oracle site.

Here beginners in Java can learn to create there first Hello World program in Java. To install Java one needs JDK (Java Development Kit), which can be downloaded from Oracle site.

After installing JDK on your operating system, a programmer is ready to create their own Java program. Here we have also described what is Java, Java class, object and methods that will help create your first Java example

What is Java?

Java is a OOPS based programming language which performs the both compile and interpret operation on code. Java is derived from the C and C++ but is platform independent and more secure.

Java was developed by Sun Microsystem which was later acquired by Oracle in 2010. Java is at present being used in almost every field by every company that are into smartphones, web development, application development, programming, etc.

After a program is created it must be converted by Java compiler and file should be saved with a .class extension. This file is then run on JVM.
Java class, object and methods

A Java class is like a group for example Human Beings under which all objects for example you, me fall. Class has other features like creation and implementation of the object, Inheritance etc.

Java object is an instance of a Java Class. It is a software bundle of variables and related methods of the special class.

Java First Example-Hello World:

Now we will create our first program in Java. All you need is a simple text editor, JDK that should be already installed in your machine for compiling and running the program. The first program a beginner in Java will create is a Hello World program, which will simply print Hello World.

When you are writing code in text editor, remember that Java is case sensitive programming language.

Write the following code into your text editor

class HelloWorld {
public static void main(String[] args){
System.out.println("Hello World!");
}
}

Save the file- While saving the file remember the file name should be same as the class name. Save the file with a .java extension.

Now open the command prompt to compile the program. Go to the directory where you have saved the file and issue the following command:

FileLocationjavac HelloWorld.java

javac is the Java compiler that converts our program into byte code. After compilation a new file with the extension HelloWorld.class will be generated.

Run the program- To run the program give the following command:

FileLocationjava HelloWorld
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: December 13, 2013

Ask Questions?    Discuss: Sample Java program for beginners  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com