Learn how to run a Java program that prints out Hello, world! to the console. See the source in HelloWorld.java.
Run like this:
# first compile the Java code into an executable Jar file
../gradlew build
# now run the Jar
java -jar build/libs/hello-world-all.jar
# also run with some arguments
java -jar build/libs/hello-world-all.jar a b c
🔥 Note you need to run
build
only after making changes to a source file.
Learn the difference between a class and a class instance. See the source in ClassVsInstance.java.
# first compile the Java code into an executable Jar file
../gradlew build
# now run the Jar
java -cp build/libs/hello-world-all.jar coding101.helloworld.ClassVsInstance
# also run with some arguments
java -cp build/libs/hello-world-all.jar coding101.helloworld.ClassVsInstance a b c
Learn about importing "outside" classes by using a logging framework to log messages
instead of using System.out
. See the source in
ImportsAndLogging.java.
# first compile the Java code into an executable Jar file
../gradlew build
# now run the Jar
java -cp build/libs/hello-world-all.jar coding101.helloworld.ImportsAndLogging
# also run with some arguments
java -cp build/libs/hello-world-all.jar coding101.helloworld.ImportsAndLogging a b c