Compile Java in Terminal

Last updated on:

Here is my Java class:

public class Welcome {   
    public static void main(String[] args) {
	// your code here
        System.out.println("Welcome Java Ninja!");

So how do I run my code through Terminal on Mac?!

Well, first navigate to the folder where located, then we need to compile program

slavkurochkin$ javac

Lets check if file been compiled and we got Welcome.class in our folder

iMac-Slav:company slavkurochkin$ ls -l

slavkurochkin  staff  439 Feb 16 22:22 Welcome.class
slavkurochkin  staff  180 Feb 16 22:19

And finally lets run the program

slavkurochkin$ java Welcome
Welcome Java Ninja!
View Comments

Leave a Comment

Use markdown or basic HTML and be nice.