Java Basics / Hello World In Java (Java)

Hello World in Java

Way back in October 2016 I completed an introduction to Java course via MadLab, and other than dipping into Java whilst looking at Android development I have not really looked at the Java language. However in recent times I’ve been dabbling with C, and that got me thinking about Java again.

Java was developed by Sun Microsystems, and was later purchased by Oracle. Like C it is a compiled object orientated language and was designed to be Wrote Once, Read Many (WORM) across multiple operating systems.

To write Java a JDK (Java Developer Kit) is required, which can be obtained from https://www.oracle.com/technetwork/java/javase/downloads/index.html

I will be using the community edition of IntellJ as my IDE whilst I learn / play with Java.

Naming Convention

Java doesn’t like white space in its naming and preference is for CamelCase. Names in Java are case sensitive so MyVariable is different to myvariable.

Comments

Single line comments are created by placing placing two slashes and then the comment, e.g.

// comment here

Multiline comments are created by placing a slash and and astrix, the comment and then a astrix and a slash, e.g.

/*

comment here

*/

Hello World

Like C, Java requires a void main to be created for its Hello World. It expects the void to be wrapped by a public class with the name matching the filename. Below is an example of Hello World written in Java.

public class HelloWorld { // Java programs start with a public class named after the file
    public static void main(String[] args) { // the public static void main is then created
        System.out.println("Hello, World complete!"); //this line prints the output
    }
}
geektechstuff_java_helloworld
Hello World in Java

To test that the Hello World program has been written correct it must be compiled/run.

geektechstuff_java_helloworld_2
Hello World success

One thought on “Java Basics / Hello World In Java (Java)

Comments are closed.