Notes 3-Gfg (Writing The First Program)
Notes 3-Gfg (Writing The First Program)
DSA A
Data Science
Web Tech
Courses Writing First Program in Java
The below-given program is the simplest program of Java, printing "Hello World" to
the screen. Let us try to understand every bit of the code step by step.
Java
Output:
Hello, World
The "Hello World!" program consists of three primary components: the HelloWorld
class definition, the main method, and the source code comments. The following
explanation will provide you with a basic understanding of the code:
1. Class definition: Below line uses the keyword class to declare that a new class
is being defined.
class HelloWorld
Articles Read Prev
0 of 3 Complete. (0%)
Next
Dash
1. HelloWorld is an identifier that is the name of the class. The entire class
definition, including all of its members, will be between the opening curly
brace { and the closing curly brace }.
All
2. main method: In Java programming language, every application must contain
a main method whose signature is:
1. Like in C/C++, the main method is the entry point for your application and will
Quiz
subsequently invoke all the other methods required by your program.
2. The next line of code is shown here. Notice that it occurs inside the main( ).
System.out.println("Hello, World");
1. This line outputs the string "Hello, World" followed by a new line on the screen.
Output is actually accomplished by the built-in println( ) method. System is a
predefined class that provides access to the system, and out is the variable of
type output stream that is connected to the console.
2. Comments: They can either be multi-line or single-line comments.
1. 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++.
Important Points :
The name of the class defined by the program is HelloWorld, which is the
same as the name of the file(HelloWorld.java). This is not a coincidence. In
Java, all codes must reside inside a class and there is at most one public class
which contains the main() method.
By convention, the name of the main class(a class that contains the main
Menu
method) should match the name of the file that holds the program.
Articles Read
0 of 3 Complete. (0%)
Dash
All
Mark as Read
Articles
Report An Issue
Videos
If you are facing any issue on this page. Please let us know.
Problems
Quiz
Menu
Articles Read
0 of 3 Complete. (0%)