Search⌘ K
AI Features

Java Program is Written Within a Class

Explore how Java programs are structured within classes, focusing on the main method and Java's compilation process into bytecode. Understand the roles of the Java Virtual Machine and Java Runtime Environment in running Java applications on different operating systems. Learn about data types, compilation versus interpretation, and how Java achieves platform independence through its unique execution model.

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”.

Java
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:

Java
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 ...