How to Write a Simple Java Program

Java is an object-oriented language similar to C ++. However, it should be easy to rule out the possibility of making common program errors such as memory corruption, directory errors, or references.

Before you start writing JAVA milliseconds in a year Programme, you need to choose your development environment:



Use the Java Software Development Kit (SDK) and text editors such as Notepad, Edit Plus.

Use an integrated development environment (IDE) such as NetBeans, Eclipse.

Now let's look at the source code of the simplest Java program which only displays a message in the console window:

Program code

HelloWorld public class

{

public static void main (String [] args)

{

System.out.println ("Hello world!");

}}

}}

 

Start the program

If you are using a text editor, you must name the file exactly as the class name "HelloWorld" with a .java extension. Then compile the file by running this command:

$ javac HelloWorld.java

After you compile the file, the Java compiler creates a bytecode file "HelloWorld.class" from the source code. This file is executed by the Java interpreter. To do this, enter the following command:

$ java HelloWorld

 

An output is displayed in the console window:

Hello World!

If you are using an IDE, you can run this source code by clicking Start Debugging. The IDE compiles, runs the source code, and displays the output as above.

 

Code explanation:

 

You have successfully written your first Java program. Now let's look at this source code line by line:

HelloWorld public class

Everything in Java must be in the class. This class is called "HelloWorld". The public keyword is an access modifier that determines at what level of access other classes can use this code. In this case, this class can be seen by all classes everywhere.

public static void main (String [] args)

This is the only method in this class, the base method with the args parameter as a String array. Every Java program has a basic method. Static methods are methods that don't work with objects. Therefore, the base method must be static because there is no object when starting the program. The void keyword is used for a method and indicates that it will not return any data.

System.out.println ("Hello world!");

Here the body is the basic method. This class has only one expression, each expression is separated by a semicolon (;). I use this statement with a System.out object and call the println method. The println method displays the text of the parameter in the console window and ends the line.

For More Details, Visit Us:  docker invalid reference format

illegal start of expression

How to print multidimensional array in PHP using for loop

how to get multiple checkbox value in php using array

Comments

Popular posts from this blog

How to Fix Runtime Optimization Errors

Using Timers in Java