Common Output Statements in Java
Common Output Statements in Java
Certainly! This code is a basic Java program that demonstrates the structure of a Java class and
how to print a message to the console. Let's break down each part of the code:
public: This is an access modifier that specifies the visibility of the class. It means that
the class MyProgram can be accessed from other classes.
class: This keyword is used to define a new class in Java.
MyProgram: This is the name of the class. Class names in Java usually start with an
uppercase letter.
public: This is an access modifier that specifies the visibility of the method. The main
method is the entry point of the program, so it needs to be accessible from outside the
class.
static: This keyword indicates that the method belongs to the class itself, not to an
instance of the class. The main method is static because it's called before any objects of
the class are created.
void: This is the return type of the method. void means the method doesn't return any
value.
main: This is the name of the method. The main method is a special method in Java that
serves as the entry point of the program.
String[] args: This is the parameter list of the main method. It accepts an array of
strings as arguments. These arguments can be provided when running the program from
the command line.
System.out.println("Hello, Java!");
System.out: This is an instance of the PrintStream class, which is used to output text to
the console.
println: This is a method of the PrintStream class that prints a string followed by a
newline character.
"Hello, Java!": This is the string that will be printed to the console.
Java Object Oriented Programming By Zeeshan Ahmad Mughal @ GCUH CS Department 2023 (1)
}
}
The closing curly braces (}) mark the end of the main method and the end of the
MyProgram class.
Hello, Java!
This simple program demonstrates the core structure of a Java class, how to define methods, and
how to output text to the console. The main method is particularly important because it's the
method that gets executed when you run a Java program.
Java Object Oriented Programming By Zeeshan Ahmad Mughal @ GCUH CS Department 2023 (2)