Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Java is a widely-used programming language known for its versatility and robustness. If you’re new to Java and eager to start coding, let’s dive into a classic example: Hello World.
Follow these steps to create your first Java program:
HelloWorld
.HelloWorld
. Replace any existing code with the following: public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Let’s break down the code:
public class HelloWorld
: Defines a class named HelloWorld
.public static void main(String[] args)
: Entry point of the program. This method is executed when you run the program.System.out.println("Hello, World!");
: Outputs the string “Hello, World!” to the console.main
method. You should see Hello, World!
printed in the console.public class HelloWorld
): In Java, every program must have at least one class. Here, we declare a class named HelloWorld
.public static void main(String[] args)
): This method is where the execution of a Java program begins. public
means this method can be called from outside the class. static
allows the method to be called without creating an instance of the class. void
indicates that the method does not return any value. String[] args
is an array of strings that can be passed as parameters when the program is executed.System.out.println("Hello, World!");
): System.out
refers to the standard output stream, and println
is a method used to print a line of text. In this case, it prints "Hello, World!"
followed by a newline.Congratulations! You’ve successfully created and executed your first Java program. This example demonstrates the basic structure of a Java program and introduces you to fundamental concepts such as classes, methods, and console output. As you continue your Java journey, you’ll explore more advanced topics and build upon this foundational knowledge.
Happy coding!