Hello world in Java programming

 Hello world in Java programming


Hello world in Java programming

Hello world! in Java programming, hello world is the general starting of all programs it is just a tribute to "Dennis Ritchie" father of computer science.

Steps to build Hello World! program

1. Install JDK, Textpad, test
2. IDE (Integrated Development Environment)
3. Build Development Environment set the temporary path in command prompt by using "SET path=YOUR_PATH_JDK/bin".
4. Build HelloWorld.java
5. compile to  HelloWorld.class
6. Run and test it.

Program(HelloWorld.java)


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

Explanation


The public is an access specifier in the header (public class HelloWorld) of the class which means the class can be accessible publically.

The other way of declaring class is just to remove the access specifier which mean that the class will be accessible by package member-only, consider a package as a folder, and class as a file inside it so all the other class inside the package can access the HelloWorld class.

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

*There is no other way of defining class.

main() method


The header of the main method is fixed
public static void main(string[] args)
{
}

The main method has to strictly follow its syntax; otherwise, JVM will not be able to locate it and your program will not run.

public: They are public because they must be accessible to the JVM to begin the execution of the program.
If it is not public then only the class and the package members can access it and JVM cannot.
Main is the first method that would get executed in any class.
 
static: They are static because they must be available for execution without an object instance.

void: void means return type is nothing and  As soon as the main() method terminates, the java program terminates too. 
Hence, it doesn’t make any sense to return from the main() method as JVM can’t do anything with the return value of it.

main: It is the name of Java's main method. It is the identifier that the JVM looks for as the starting point of the java program. It’s not a keyword.

String[] args: It stores Java command-line arguments and is an array of type java. lang.String class. 
Here, the name of the String array is args but it is not fixed and the user can use any name in place of it.

System.out.println("Hello World!"); it is a statement inside the main method which calls another method println() which takes a parameter as a string and returns the string as output.

*Always terminate statement with a semicolon ";".

Members of class(what might be inside a class)


1. methods
2. variables
3. inner class
4. constructors
5. initializer

Best Practice for programming.

Naming Conventions are:

Class: Start with uppercase + Camel case

variable and method: Starts with lower case+ Camel case.

Coding convention:

1. check for JDK
2. TEST
3. SET DEVLOPMENT ENVIRONMENT
a). Source(.java)
b). classes(.class)
c). library
4. code
5. test

Java Complete Course

1. What is Java?

2. Hello world in Java programming, the first program.

3. Variables in Java programming.





No comments:

For Query and doubts!

Powered by Blogger.