In this blog, we will learn how to write simple and first java program.Before writing a simple hello java program easily we have to install jdk. Firstly, understand the Requirements to
create a simple java program:For executing any java program you need to install the JDK if you don not have installed it.
After writing first java program either in Note pad or IDE tool then save this file as Simple.java
To compile and Run Program :
To compile and Run the Java program you need to install Java Development Kit(JDK) and optionally Integrated Development Environment(IDE). To download Java SE for latest version
fallow the link: Java 8 software download
Once you installed the JDK, then open command prompt in Windows Environment then type
to compile program: javac Simple.java and to run the java program
java simple
Here javac means java compiler,this command compiles the java source code into an intermediate representation,called byte codes and saves them in class files. The java command launches a virtual machine that loads the class files and executes the byte codes. Once compiled,byte code can run on any java virtual machine.
The following is the output for the preceding program.
WELCOME TO LEARNPROGRAMINGBYLUCKYSIR
create a simple java program:For executing any java program you need to install the JDK if you don not have installed it.
- set path of the JDK/BIN directory if you do not know how to set path then see it i was already posted how to set path.
- create the java program
- compile and run the java program
Creating hello java Example:
class Simple{
pubic static void main(String args[])
{
pubic static void main(String args[])
{
System.out.println("WELCOME TO LEARNPROGRAMINGBYLUCKYSIR");
}
}
}
After writing first java program either in Note pad or IDE tool then save this file as Simple.java
To compile and Run Program :
To compile and Run the Java program you need to install Java Development Kit(JDK) and optionally Integrated Development Environment(IDE). To download Java SE for latest version
fallow the link: Java 8 software download
Once you installed the JDK, then open command prompt in Windows Environment then type
to compile program: javac Simple.java and to run the java program
java simple
Here javac means java compiler,this command compiles the java source code into an intermediate representation,called byte codes and saves them in class files. The java command launches a virtual machine that loads the class files and executes the byte codes. Once compiled,byte code can run on any java virtual machine.
The following is the output for the preceding program.
WELCOME TO LEARNPROGRAMINGBYLUCKYSIR
Now we will Understand First java program Step by Step :
class:
A class code starts with a { and ends with }. We know that a class or an object contains variables and methods. A class can define what an Object can do. Generally in java, all code defined inside a class. In the above program we made up a single class called Simple
Now we will discuss about public static void main(String[] args)
main:
main is a method name,which is declared inside a class. This is the first method that is called when the program runs.
public:
In the main() method signature the first one that is public keyword
is an access specifier,which allows the programmer to control
visibility of the class members.That means it is called by JVM from any
where. So, must be declare main() method as public,because it must be
called by code outside of its class.
Static:
main method declared as static that means the method does not operate on any objects. The main advantage of static method is that there is no need to create object to invoke the static method.The main method is executed by the JVM, so it doesn't require to create object to invoke the main method. So it saves memory.
void:
void is the return type of the method, it means it doesn't return any value.
String[] args:
It is used for command line argument. For more details about Command Line argument
System.out.println:
This statement is used to print the result. For more details about System.out.println
No comments:
Post a Comment