Skip to content

Instantly share code, notes, and snippets.

@jsrpy
Last active November 18, 2018 19:30
Show Gist options
  • Save jsrpy/6028d8e49a1d7c0dfe7b36d5221631e9 to your computer and use it in GitHub Desktop.
Save jsrpy/6028d8e49a1d7c0dfe7b36d5221631e9 to your computer and use it in GitHub Desktop.
Java Hello World

Java Hello World on MacOS Sierra (10.12.6)

Copy and Create hello.java

On terminal/bash, first compile the program then run it:

  1. javac hello.java
  2. java hello

You should see 'Hello World' printed to your console.

Print Hello World in a GUI

  1. Copy and create HelloWorld.java
  2. Download acm.jar and put it in the same folder as your java files.
  3. javac -cp acm.jar HelloWorld.java
  4. java -cp acm.jar: HelloWorld

You should see a GUI coming out and prints 'Hello World' there.

These steps may or may not work in other environment, due to the variances in command line syntax of the java compiler/interpreter.

java --version

java version "10.0.1" 2018-04-17

Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)

Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)

public class hello{
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
import acm.program.*;
public class HelloWorld extends ConsoleProgram {
public void run() {
println("Hello World!");
}
}
@jsrpy
Copy link
Author

jsrpy commented Nov 18, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment