The Java programming process can be divided into three steps:
The program given below is the simplest Java program to print "Hello World" on the screen. Let's try to understand each piece of code step by step.
/* This is a simple Java program. FileName : "HelloWorld.java". */ class HelloWorld { // Your program begins with a call to main(). // Prints "Hello, World" to the terminal window. public static void main(String args[]) { System.out.println("Hello, World"); } }
Output:
Hello, World
"Hello World!" The program consists of three main components: the HelloWorld class definition, basic methods, and source code comments. The following explanations will give you a basic understanding of code:
class HelloWorld
HelloWorld is an identifier which is the class name. The entire class definition, including all its members, is between the opening brace {and the closing brace}
2. main method: In Java programming language, every application must contain a main
method whose signature is:
public static void main(String[] args) public: So that JVM can execute the method from anywhere. static: Main method is to be called without object. The modifiers public and static can be written in either order. void: The main method doesn't return anything. main(): Name configured in the JVM. String[]: The main method accepts a single argument: an array of elements of type String.
Like in C/C++, primary strategy is the section point for your application and will accordingly summon the wide range of various strategies needed by your program.
3. The next line of code is shown here. Notice that it occurs inside main( ).
System.out.println("Hello, World");
This line yields the string "Hello, World" trailed by another line on the screen. Yield is really cultivated by the underlying println( ) strategy. Framework is a predefined class that gives admittance to the framework, and out is the variable of type yield stream that is associated with the control center.
4. Comments: They can either be multi-line or single line comments.
/* This is a simple Java program. Call this file "HelloWorld.java". */
This is a multiline comment. This type of comment must begin with /* and end with */. For single line you may directly use // as in C/C++.
Australia
UK
UAE
Singapore
Canada
New
Zealand
Malaysia
USA
India
South
Africa
Ireland
Saudi
Arab
Qatar
Kuwait
Hongkong
Copyright 2016-2023 www.programmingshark.com - All Rights Reserved.
Disclaimer : Any type of help and guidance service given by us is just for reference purpose. We never ask any of our clients to submit our solution guide as it is, anywhere.