Skip to content
Ryan James
Menu

← Java10 min read

Getting Started With Java

Java is an object-oriented programming language that has been in use for a few decades now since Oracle purchased the programming language. The programming language borrows a lot of syntax from C and C++ but Java does a great job of implementing a lot of abstractions that aren't present in those lower languages.

Getting Started With Java

Java is an object-oriented programming language that has been in use for a few decades now since Oracle purchased the programming language. The programming language borrows a lot of syntax from C and C++ but Java does a great job of implementing a lot of abstractions that aren’t present in those lower languages. Java also does a great job of being able to create applications that you don’t have to have a compiler on hand to run…which means you can create a Java application and share it with someone and they don’t need any background in Java to run your program. Java is the main language used in building Android apps as well as an unknown number of other applications on other platforms.

To get started in Java, you’ll need a compiler. There are a lot of options that you can choose as your first compiler.

Java Compiling Options:

  • Compile from the command line with javac filename with a code editor like VS Code or Atom
  • Using an introductory compiler like BlueJ
  • Using a more advanced compiler like IntelliJ, Eclipse, or Visual Studio
  • Or use an online compiler like Codespaces or Repl.it

All of these are valid options. The only thing you need to write a Java program is a text editor and save your files with a .java extension. But because Java is a compiled language, you will need a compiler to compile your code for runtime which is much different from scripting languages like Python and JavaScript. For my students, they start off in BlueJ because it has a good UI for starters, shows the dependencies when doing polymorphism, and you can run code by clicking classes rather than typing out client classes. Eventually they feel comfortable with syntax and they will move onto IntelliJ when they start doing more complicated programs with a GUI interface because the autocomplete and intellisense is really useful then.

Once you choose your compiler, let’s get started with your first program to print to the screen. In most compilers you create a project folder first and then you create your files. You want to create a file or class (depending on your environment) and save the file as hello.java or save the class as hello. Make sure that the entire class looks like this now:

public class Hello
{


}

The class has the name ‘hello’ and when creating this class in a compiler, it will create a file called ‘hello.java’. It’s important not to change the name of the class or the file because they have to match.

To get something to run, we need to create a static main method. The code in this method will run when the program is loaded. In a compiler you will be able to run this method without having to create an instance of the class or without having to create a client class to test your code.

public class Hello
{

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

}

With the class as shown above, you should not have any error messages from a compiler. A few things to explain even though this is just the beginning of Java. The method is called ‘public static void main’ because it is public so someone outside of the class has access, static so it can run by itself without an instance of the class, void because it doesn’t return anything, and main because it’s the main method. The parameter inside the main method is there if a user wants to pass in any data to the main method. Inside the method is the print statement and you should notice that the statement line ends with a semi-colon. If you’re not used to semi-colons yet, you will get very used to them in Java.

To run the program, first thing is to compile the program and then run the program. Since every compiler is different, I’m not going into detail about how to accomplish this. Every compiler that I’ve used has always had good documentation that I can find online to help out.

This is just a start, but I hope this helps you feel more comfortable in a compiler based programming environment!

Keep coding!
Ryan