- In this java tutorial, you will learn how to write a hello world program in java with examples.
- Hello world using manual way (hello world java in notepad)
- Hello world using Automated way (hello world in java netbeans)
I. HELLO WORLD USING MANUEL WAY
(USING NOTEPAD)
BASIC REQUIREMENT STEPS
1. Install the JDK if you don’t have it, download the JDK and install it.
2. Set path of the jdk/bin directory. (set path=<path-of-jdk/bin>
3. Create the java program (.java)
4. Compile the java program (javac)
5. Run the java program (java)
1. FILE CONFIGURATION (Saving a file)
Language : java
Application Type : Console Application
Tool Tool : Notepad
Compiler : javac
Interpreter : java
2. SOURCE CODE
(Welcome.java)
public class Welcome
{
public static void main(String[] args)
{
System.out.println(“Good Morning …”);
}
}
3. OUTPUT
II. HELLO WORLD USING AUTOMATIC WAY
(USING NETBEANS IDE)
STEP 1: PROJECT CREATION IN NETBEANS IDE (8.2)
STEP 2: CHOOSE PROJECT TYPE
STEP 3: CHOOSE PROJECT TYPE
STEP 4: PROJECT VERIFICATION IN NETBEANS
STEP 5: ADD MAIN CLASS TO CURRENT PROJECT FOLDER
STEP 6: SET NAME TO MAIN CLASS
NOTE
- Don’t add a .java extension when creating the main class / other class in the project. Because Netbeans IDE will automatically add a .java extension.
Language : java
Application Type : Console Application
Tool : NetBeans IDE
Compiler : javac
Interpreter : java
1. SOURCE CODE
(JMessage.java)
package tp;
public class JMessage
{
public static void main(String[] args)
{
System.out.println(“Welcome to chennai …”);
}
}
Where,
System -> built-in class (Pre-defined class)
out ->static object type of PrintStream class
println() ->print string (text message)
class ->reserved keyword used to define a class
public ->access modifier which gives global scope
(accessed anywhere in the programming)
void ->return type of the main() method. It does not return anything.
main -> represents the starting point of the program
(starts the program execution)
String[] args ->string array which is used to receive the command line inputs. By default, the inputs of command line
arguments must be string array (String [] args)
static -> it represents main() as a static method. The main advantage of using static method is that, there is no need create an object to call the static methods.
System.out.println() ->used for print statement. System is a built-in class, out is an object of PrintStream class and println() is an instance method of PrintStream class.
System
- It is placed in java.lang.* package
- It is used for input / output operations
- It includes built-in static class fields and methods.
Static Fields are
1. In -> used for getting input
2. Out -> used for printing output on console
3. Err -> used for printing errors as a output.
in
- It is used to read input from the standard console (Ex. keyboard)
- in is a static member of the System class and is instance of java.io.PrintStream class
- First, it is reference type (Object type) of PrintStream class
- PrintStream is Built-in class which is placed in java.io.* package
- Here in is actually defined as a static object in System class.
out
- out is a static member of the System class and is instance of java.io.PrintStream class
- First, it is reference type (Object type) of PrintStream class
- PrintStream is Built-in class which is placed in java.io.* package
- Here out is actually defined as a static object in System class.
- Here out object is used to send the data to standard output device (e.g. dos window / terminal / IDE terminal)
println()
- It is built-in instance method of PrintStream class
- PrintStream is Built-in class which is placed in java.io.* package
- Here it is used to print the message as a line.
err
- It works like out object except it is normally only used to output error tasks (print / show error message on the output screen / console)
- It is the first object of the PrintStream class and second static object of System class.
2. COMPILATION
3. EXECUTION
4. OUTPUT