in your ~/development directory go ahead and create a new file and call it HelloJavaWorld.java
Notice the Camel Case for the file name is a general construct that Java developers adhere to.
In every Java application there is 2 parts:
class
keywordIt’ll look something like this
public class HelloJavaWorld{
}
For now, don’t get tripped up on the public
keyword, what you need to know is it exposes this class to other classes. It’s not really doing anything since we only have one.
Next up we have a main()
method which is the entry point of our application.
Java starts by looking for the main() method.
Use the java extension we installed earlier by typing main
and then selecting the expansion
What that just spit out was a bunch of boilerplate java that is similar to other languages like dart. It’s necessary for the Java runtime/compiler to have this line as an entrypoint.
Inside of that function that is created (inside of it’s {}
) you will want to add the following:
System.out.println("Hello World!");
It should look like this:
public class HelloJavaWorld{
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Save your file.
Let’s discuss a little of the line we just created.
println()
- prints a message inside it’s parenthesis to the console