Running a JAVA program from Terminal on Mac

  1. Run Terminal on Mac by pressing command+spacebar and typing in Terminal in the search bar
  2. On terminal change directory to where you saved your java file (file with .java extension) by using the “cd” command on terminal
  3. You can list the content of a folder using “ls” command
  4. Compile java file using the following command
    user$ javac hello.java
  5. If you don’t have javac install terminal will prompt you to do so, repeat step 4 after installing java jdk
  6. After executing javac command you will see a file with .class extension in the same directory
  7. Next to run the program type in terminal
    user$ java hello

    Note: Don’t add .java or .class to the file name

    javaterminal.gif

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: