Java 8 for Mac OS and writing a Hello World using Lambda ⮐
Follow the instruction to download java-8 lambda featured JDK & JRE.
-
Get the java 8 lambda package
-
Unzip and put it in some folder that you wanted or preferably at
/System/Library/Java/java-8-lambda
-
Open terminal and set your
JAVA_HOME
to point to your path and now execute thejava
&javac
commands to see if the libraries are good.
If you see the above versions, then you have set the path right and got the libraries working. Write any java 8 lambda program ( click here for sample ) and compile in the same “Terminal” session.
To set the JAVA_HOME permanently, create/open the ~/.bashrc
or ~/.bash_profile
and set the JAVA_HOME path in it.
Compiling & Running Java 8 program
I’ve considered 3 choices here
- Using Terminal
- Using the Eclipse - External Tools features
- Using Apache Ant - Either in Eclipse or Terminal. I prefer Eclipse for a quick start.
Using Terminal
Whatever you did above, are all is what you need to do to run it in terminal. And preferably have it in a shell script.
Using Eclipse - External Tools
All you have to setup is these two items:
javac
java
Now run javac and then followed by java.
Using Apache Ant
This is much more customizable and easier to run. Something similar to a Terminal approach, but much nicer.
Here is my an ant script - combines java
& javac
If you are running this in a terminal, create a shell script to export the ANT_HOME
variable to the ANT path.
Running Ant in Eclipse
Make sure to update some settings in Eclipse preferences for Ant and configure the .
Hello World
And here is a Hello world using a lambda function
to test.