...

/

Java Program is Written Within a Class

Java Program is Written Within a Class

A detailed walkthrough of Java classes and the code execution process of Java language with interactive examples.

Coding example: 3

In this example, we will learn how a Java program is written within a class.

Consider problem three. This is a very simple program that gives an output of “Hello World”.

Press + to interact
public class Main {
public static void main(String[] args) {
System.out.println("Hello World");
}
}

Code explanation

In the above code, we can see that the program is written within a class, Main. Inside that Main class, we find a public method, main(). This main() method is also static and void. We will discuss the term static later. void means that it will not return any value.

Inside that main() method, we see this line:

Press + to interact
System.out.println("Hello World");

When you type the word System on your code editor, it represents a class in Java. After System, if you use a DOT . and add out, it represents a field of the class System. After using out, if we use a . notation and add println(), it represents a method. Inside the “println()”, we write Hello World, a string value. A string is a sequence of characters. ...

Access this course and 1400+ top-rated courses and projects.