Showing posts with label easy. Show all posts
Showing posts with label easy. Show all posts

Thursday, 21 September 2023

How to get started with Java as quickly as possible

Apparently, Java 21 has some new things1 to make it easier to get started with Java2 right away.

So this is the ultimate blogpost of mine to get started quickly and easily.

Fair warning: I'm using the macos version of Java, so the directory structure might be a bit different compared to other Operating Systems.

Step 1. Download java

Go to https://jdk.java.net/21 and download the build you need.

Step 2. Unpack

Unpack the archive somewhere.

% tar zxvf Downloads/openjdk-21_macos-x64_bin.tar.gz

It will unpack in directory jdk-21.jdk.

Step 3. Write a small Java program

In this instance, we'll assume the file is called HelloWorld.java.

void main() {
  System.out.println("Hello, world.");
}

Step 4. Run the small Java program

% ~/jdk-21.jdk/Contents/Home/bin/java --enable-preview --source 21 ./HelloWorld.java
Note: ./HelloWorld.java uses preview features of Java SE 21.
Note: Recompile with -Xlint:preview for details.
Hello, world.

Congratulations, you've run your first Java Program!

The other way to do it, which admittedly is even quicker, is using the Java Playground3.

References

[1] JEP 445: Unnamed Classes and Instance Main Methods (Preview)
https://openjdk.org/jeps/445
[2] Paving the on-ramp
https://randomthoughtsonjavaprogramming.blogspot.com/2022/10/paving-on-ramp.html
[3] dev.java - Java Playground
https://dev.java/playground/

Thursday, 8 September 2016

Running java programs on the web

StackOverflow, the website I use frequently when I have questions about the art of Software Design, recently started a new branch called Documentation1.

It is in Beta at the moment, but it seems already to have some valid content2.

Ideone

The Documentation section of StackOverflow seems to make extensive use of Ideone3, which I had never heard of before now.

From their website:
“Ideone is an online compiler and debugging tool which allows you to compile source code and execute it online in more than 60 programming languages.”
Besides the unfortunate large amount of adds surrounding your HelloWorld code, it seems to work pretty well, if you quickly want to try something in the Programming language of Your Choice.

References

1. StackOverflow - Documentation - The Tour
http://stackoverflow.com/tour/documentation
2. StackOverflow - Documentation - Java Language - Arrays
http://stackoverflow.com/documentation/java/99/arrays/404/creating-and-initializing-arrays#t=201609011104443665439
3. ideone.com
https://ideone.com/