Today I have been tasked with learning Java so I can implement different data structures by next week. Java is completely new to me, so I’m going in to learn it as if I’m learning programming from scratch. Luckily I have the advantage of already understanding some basic programming methods and terminology.

Hello Java

Java is a powerful, object-oriented programming language widely used for building robust applications. For beginners, understanding the basic syntax is essential to get started. What a better way to learn the basic syntax than creating a hello world function.

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

Seems like a lot of gibberish, huh? Lets break it down a little bit.

  • public class HelloWorld: Declares a public class named HelloWorld.
  • public static void main(String[] args): Defines the main method, the entry point of the program. The main method must be public, static, return void, and accept a String array as an argument.
  • System.out.println("Hello, World!");: Prints “Hello, World!” to the console.

The void part is what tripped me up the most. Void, what does it mean? Am I going to be sucked into a black hole to never return? Is it going to swallow the world I just said hello to?

It’s actually simple, the void is the type declaration in the method (methods are just functions inside classes). In this case, we aren’t returning anything, just triggering a side effect (printing hello world), so they type that is expected to be returned from this function is void (nothing returned).