Subscribe / Unsubscribe Enewsletters | Login | Register

Pencil Banner

Learn how to code in Java on a Mac

Lucy Hattersley | March 28, 2016
Java is the hottest programming language to learn right now. Here's how to set up Java and start learning it on your Mac

If you see anything else, then go back and check the code.

Compiling Java programs from Terminal in OS X

Learn how to code in Java on a Mac: HelloWorld in Terminal

As an aside, some people prefer to create code directly in the Terminal (rather than use an SDK). Here is how to compile and run Java from the Terminal in OS X.

  1. Open Terminal.
  2. Enter mkdir HelloWorld to create a new directory and cd HelloWorld to move into it.
  3. Enter touch to create an empty Java file.
  4. Now enter nano to edit the file.
  5. In the Nano editor type out the following code:

public class HelloWorld {

   public static void main(String[] args) {




  1. Press Control-X then y and Return to save the file and exit Nano.
  2. Now compile the program by entering javac in Terminal.
  3. Enter java HelloWorld to run it.

You should see Hello World outputted into the Terminal.

Where to learn Java

You are now completely set up to learn Java on your Mac. Obviously you need to progress beyond just writing "Hello World" on the screen.

The good news is that there's absolutely no shortage of places to learn Java. Here are some of the best Java courses we know about:

Good luck learning Java!

Source: Macworld 


Previous Page  1  2 

Sign up for MIS Asia eNewsletters.