Java is one of the most popular programming languages in the world. It is widely-used to develop IOT appliances, Android apps, web, and enterprise applications. This article will provide a quick guide to install and configure your workstation using OpenJDK.
Installing the compiler and tools
Installing the compiler, or Java Development Kit (JDK), is easy to do in Fedora. At the time of this article, versions 8 and 9 are available. Simply open a terminal and enter:
sudo dnf install java-1.8.0-openjdk-devel
This will install the JDK for version 8. For version 9, enter:
sudo dnf install java-9-openjdk-devel
For the developer who requires additional tools and libraries such as Ant and Maven, the Java Development group is available. To install the suite, enter:
sudo dnf group install "Java Development"
To verify the compiler is installed, run:
javac -version
The output shows the compiler version and looks like this:
javac 1.8.0_162
Compiling applications
You can use any basic text editor such as nano, vim, or gedit to write applications. This example provides a simple “Hello Fedora” program.
Open your favorite text editor and enter the following:
public class HelloFedora { public static void main (String[] args) { System.out.println("Hello Fedora!"); } }
Save the file as HelloFedora.java. In the terminal change to the directory containing the file and do:
javac HelloFedora.java
The compiler will complain if it runs into any syntax errors. Otherwise it will simply display the shell prompt beneath.
You should now have a file called HelloFedora, which is the compiled program. Run it with the following command:
java HelloFedora
And the output will display:
Hello Fedora!
Installing an Integrated Development Environment (IDE)
Some programs may be more complex and an IDE can make things flow smoothly. There are quite a few IDEs available for Java programmers including:
- Geany, a basic IDE that loads quickly, and provides built-in templates
- Anjuta
- GNOME Builder, which has been covered in the article Builder – a new IDE specifically for GNOME app developers
However, one of the most popular open-source IDE’s, mainly written in Java, is Eclipse. Eclipse is available in the official repositories. To install it, run this command:
sudo dnf install eclipse-jdt
When the installation is complete, a shortcut for Eclipse appears in the desktop menu.
For more information on how to use Eclipse, consult the User Guide available on their website.
Browser plugin
If you’re developing web applets and need a plugin for your browser, IcedTea-Web is available. Like OpenJDK, it is open source and easy to install in Fedora. Run this command:
sudo dnf install icedtea-web
As of Firefox 52, the web plugin no longer works. For details visit the Mozilla support site at https://support.mozilla.org/en-US/kb/npapi-plugins?as=u&utm_source=inproduct.
Congratulations, your Java development environment is ready to use.
Mattias Bengtsson
If you’re developing web applets in 2018 you should probably sit down and reconsider your choices. :/
Steve
I develop in Java on my Linux box daily. I use IntelliJ’s IDEA IDE. I find it much more intuitive than Elcipse and less bulky than netbeans. It has a fantastic selection of tools, and very useful code completion helpers. It is available as a community edition, but is not packaged with Fedora. It is the same IDE as that which Android uses for development.
Mostafa Kamel
I expected a very powerful tools for java . Intellij has an open source version “community” . I consider it the best IDE for java . wow applet , applet is a dead man .
Geany and Eclipse isn’t powerful than IntelliJ or Netbeans . Now java8 is considered the legacy for java . the most of java developer still code by java8 .
satai
As the previous commenters
– don’t develop applets. They are dead.
– don’t start with any other IDE than IntelliJ. (Write your first Java program using an editor of choice to see how everything works behidn the scenes and then install IntelliJ. It’s possible that ypu will be forced to downgrade to Eclipse some time in the future for some reasons such as an plugin used by your employer, but don’t torture yourself from the start).
My points
– use javac for the first “hello world” project but use a project lifecycle tool for the next one (maven and gradle are probably the most popular choices right now).
– have a look at testing tools as soon as possible. It will make your life easier from the begining (JUnit is the common choice, Spock is my recomendation if you need a bit more power.)
Rene Reichenbach
“don’t start with any other IDE than IntelliJ” <– totally disagree
Choose the tooling that fits YOUR needs including any habits.
Eclipse can do it.
Apache Netbeans can do it.
Well configured VIM/Emacs can do it.
even VSCode with RedHat Java Extension can do it.
anything that edits text can do it …
If you like IntelliJ use it. Its not bad at all. But to declare it the universal truth is just wrong.
If you really “need” IntelliJ. Your Project is usually already to large and you should rethink the architecture.
And as mentioned tools like maven and gradle should be used as soon as you feel save with the language basics.
Steve
I agree that you should always go with what you feel fits your work flow the best. For instance, my choice of the IntelliJ IDE IDEA over Eclipse and Netbeans was driven from past years experiences with all of them. However I am not “married” to any one of them, and if was asked outright, would likely have a rant list for all three of things I don’t like about them. Definitely familiarization with the build system is a worthwhile effort, and one which seems to be often overlooked by many. As far as size relative to use, I will confess that it is often convenience that drives me in the end, and the desire to ‘get this done’.
judovana
Applets are dead, but ITW is also javaws (java web start ) provider. And javaws will be with us for some more time…
For fun – ITW can run also browser applets without browser – javaws –html httpx://some/page.html -as major browsers shut down npapi.
Idea have imho worst auto completion. Although in other tooling it is best. Fun is that, NetBeans autocompletion was based on Idea’s one, and then intelijidea left it, and come with the new, – current terrible one. eclipse are someewhere in the middle with autocompeltion.
weezerwill
I’m new to Java programming. Out of curiosity, what makes the auto completion bad in the IntelliJ IDE? I struggled with getting Netbeans setup and working, but IntelliJ was pretty straight forward. I’m wondering if I need to go back to Netbeans. Thanks in advance.
Rene Reichenbach
That sounds like some configuration issue. The autocompletion works quite good in Eclipse, Netbeans and IntelliJ. Make sure to use Apache Netbeans and not the “legacy 8.2” from Oracle.
Aaron
It’s also worth looking at something like SDKMAN for managing different concurrent Java Versions, if for whatever reason you need oracle too etc.
toquart
Thanks
Petr "Stone" Hracek
Here is my IntelliJ-IDEA community repo. https://github.com/phracek/IntelliJ-IDEA-community
But I did not update it a couple month ago.