Hello Java Example Part-4 - ETL- iNFORMATICA DEVELOPER

Sunday, October 20, 2019

Hello Java Example Part-4

ktbluehost.com

In this page, we will learn how to write the hello java program. Creating hello java example is too easy. Here, we have created a class named Simple that contains only main method and prints a message hello java. It is the simple program of java. 

Requirement for Hello Java Example

For executing any java program, you need to 

create the java program.
install the JDK if you don't have installed it, download the         JDK and install it. 
set path of the bin directory under jdk.
compile and execute the program.

Creating hello java example

Let's create the hello java program: 

class Simple{
    public static void main(String args[]){
     System.out.println("Hello Java")
    }
}

save this file as Simple.java

To compile: javac Simple.java
To execute: java Simple
Output:Hello Java

Understanding first java program

Let's see what is the meaning of class, public, static, void, main, String[], System.out.println().

class is used to declare a class in java.
public is an access modifier which represents visibility, it means it is visible to all.

static is a keyword, if we declare any method as static, it is known as static method. The core 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 is the return type of the method, it means it doesn't return any value.

main represents startup of the program.
String[] args is used for command line argument. We will learn it later.

System.out.println() is used print statement.

Internal Details of Hello Java Program

n the previous page, we have learned about the first program, how to compile and how to run the first java program. Here, we are going to learn, what happens while compiling and running the java program. Moreover, we will see some quesitons based on the first program.

What happens at compile time?

At compile time, java file is compiled by Java Compiler (It does not interact with OS) and converts the java code into byte code.


What happens at runtime?

At runtime, following steps are performed:

Classloader: is the subsystem of JVM that is used to load class files.Bytecode Verifier: checks the code fragments for illegal code that can violate accesss right to objects.Interpreter: read bytecode stream then execute the instructions.



Q)Can you save a java source file by other name than the class name? 

Yes, like the figure given below illustrates:

To compile: javac Hard.java
To execute: java Simple



Q)Can you have multiple classes in a java source file?

Yes, like the figure given below illustrates:


No comments:

Post a Comment