Top 10 Essential Tools Every Java Developers Should Know

Top 10 Essential Tools Every Java Developers Should Know

Top 10 Essential Tools Every Java Developers Should Know. A developer is only as good as their tools.

Hello, folks! We are already in the second month of 2019, and I am sure all of you have already made your goals about what to learn in 2019 and how to achieve them. I have been writing a series of articles to give you some ideas about the things you can learn and improve upon to become a better, well-rounded developer in 2019, learning new programming languages, frameworks, and libraries. These three things are extremely important to help you become a better Java developer, but as a wise person once said, “you are only as good as your tools.” You should also look to upgrade your tools, learn new tools, and improve your understanding of old tolls that are still working well.

To help you with what tools you can learn in 2019, I have come up with this list of 10 essential tools for Java developers thatI am going to share with you guys in this article. In the past, I have shared some useful testing tools for Java programmers, and this article is an extension of that, as it covers much more than automation testing tools.

The tools we will discuss include essential coding tools like IDEs, Project Management tools, including JIRA, source-control essentials like Git, and build tools like Maven and Gradle. There is a good chance that you are already familiar with some of these tools, and in that case, you can simply ignore them or further improve your understanding of them.

These are the essential tools for a Java developer in 2019; many companies expect that you already know these tools and they often screen your resume to find references to these tools. Most employers will even ignore your resume if you forget to include your experience and knowledge of these tools.

Lastly, this is my second list of tools for Java developers. Last year, I shared the top 10 tools used by Java programmers in their day-to-day life. If you need more tools, you can refer to that article to get more ideas.

10 Essential Tools for Experienced Java Programmers

When I say essential tools, I mean something that you must know, but the list also contains some tools that are more advanced, and even if you don’t know them well, knowing them will further enhance your reputation, make you more valuable, and possibly advance your career, particularly if you are looking to become a DevOps engineer.

I have tried to include tools from code repository, project planning, build and deployment, testing automation, and infrastructure automation. As a senior Java developer who is responsible for managing the project end to end, these tools will help you to do your job more effectively.

Anyway, without any further ado, let’s look at some of the essential tools for Java programmers.

1. Git

I think Git and GitHub should be the most essential tools that all Java programmers learn and master. I know many of you already know Git, but those who are still working in SVN and CVS seriously consider learning Git and GitHub this year.

There is no way you can avoid Git anymore, even if you don’t use it in your current project. It has become a standard for source code repository and the newest development is using Git.

If you are a beginner, I suggest you check out the GitHub Ultimate course to start with. Even if you know Git, you can still learn things, e.g. the Git command line, to further improve your knowledge. All the time and money you invest in learning Git will pay off in the long run.

2. JIRA

After Git, I think JIRA is the second most important tool for any Java developer or, say, any programmer out there. It has quickly become the #1 planning and bug tracking tool for many organizations.

If you are working on an Agile team, following Sprint schedules, and attending Scrum meetings, then JIRA is even more important. With all its capabilities to support Agile methodologies, its a must-know tool for Agile teams.

You can even impress your manager and colleague by knowing JIRA in-depth. You can help your team to create Sprint dashboard. If you are serious about learning JIRA, check out this course Learn JIRA with real-world examples to get you started.

3. Maven

This is another essential tool for Java programmers, which helps you build and manage your Java projects. It’s been there for quite some time, and there’s a good chance that you may have already heard about Maven.

It not only helps you build your project, e.g. compile source files, but it can also run your unit tests and deploy your artifacts or deliverables to live environments. It also helps with managing dependencies, e.g. all third-party JAR files you use in your projects.

4. Jenkins

Jenkins is another essential tool for Java developers, particularly those who are hoping to become a DevOps professional. This is a continuous integration tool, which means it can continuously build, test, and deploy your projects.

In our case, Jenkins automatically runs the build every time someone checks in to their code. IT also has a scheduled nightly and hourly build to automatically build and test our project.

If you are a senior Java developer, e.g. someone with more than 5 years of experience, and you don’t know Jenkins, then you should seriously consider learning it. If you decide to learn Jenkins, the Learn DevOps: Jenkins CI/CD with Docker is a fantastic course to start with.

5. Selenium

This is another great tool for Java developers, particularly Java web developers. Selenium is a tool for web browser automation, which means you can test your web pages, like both JSP and static pages written using HTML and JavaScript, using Selenium.

It provides a playback tool for authoring tests without the need to learn a test scripting language. It’s becoming very popular nowadays, and that’s why learning it will not only help you write better code but can make you more valuable.

6. Docker

Docker is a tool that allows users to quickly assemble apps from components and work collaboratively. If you are working on web development, e.g. developing and deploying applications on the cloud, then Docker is an essential tool to learn.

This is appropriate for managing containers of an app as a single group and clustering an application’s containers to optimize resources and provide high availability. If you are serious about learning Docker, then I suggest you first go through this Docker and Kubernetes Complete Guide before using it in your project.

7. Gradle

This is another important build tool for Java developers. Similar to Maven, it also helps you to build, test, and deploy projects. It also manages dependencies, like Maven does, but it uses Groovy to write build script, as compared to XML, which is used by Maven.

This means you can write more powerful and cleaner build scripts than Maven.

8. Splunk

This is another useful monitoring tool that many companies are introducing in their development life-cycle. This is meant to help you write better code by indexing your log files and using machine learning to analyze the content.

It turns machine data into answers with the leading platform to tackle the toughest IT, IoT, and security challenges.

Many companies are using Splunk to search, monitor, analyze, and visualize machine data.

9. Chef

This is another great tool for infrastructure automation to build a new server and install your application. The chef is a configuration management tool written in Ruby and Erlang.

It uses a pure-Ruby, domain-specific language for writing system configuration “recipes.” With Chef, you can manage servers with a large number of serves easily.

Time-consuming activities like manual patching, configuration updates, and service installations for every server can all be automated. In short, this is a good tool for both senior Java developers responsible for managing their environments and DevOps engineers.

10. IntelliJ IDEA

Finally, the most important tool for a Java developer is an IDE. I am sure you have already used an IDE, as I hardly know a Java developer who doesn’t use an IDE, but most users just learn one IDE, like Eclipse or NetBeans, and simply ignore others.

The IntelliJ IDEA is one of them, which is ignored by many Java developers who use Eclipse, but it offers a lot more, and you can learn it to further improve your productivity if you happen to know Eclipse already.

I have generally found that many complex projects are better to work on in IntelliJ IDEA; their Java 8 support is also much better than Eclipse.

That’s all for now on some of the most useful tools Java developers can learn and master in 2019 to make themselves more valuable and improve their productivity. As the saying goes, “you are only as good as your tools,” it becomes increasingly important for Java developers to get familiar with modern tools that can improve coding, unit testing, development, deployment, infrastructure automation, and continuous integration, especially if you want to become a DevOps Engineer.

Learn More

Complete Java Masterclass

Complete Step By Step Java For Testers

Java Web Service Complete Guide - SOAP + REST + Buide App

Selenium WebDriver with Java - Basics to Advanced& Interview

Java Persistence: Hibernate and JPA Fundamentals

Java Swing (GUI) Programming: From Beginner to Expert

Java Basics: Learn to Code the Right Way

How to import an existing Maven project into IntelliJ IDEA?

How to import an existing Maven project into IntelliJ IDEA?

This tutorial explains how to import an existing Maven project into IntelliJ IDEA and how to create a running configuration for a Maven goal. This is useful, for example, when using the Jetty Maven plugin that allows you to quickly deploy and run a Java web application using this popular server.

This tutorial explains how to import an existing Maven project into IntelliJ IDEA and how to create a running configuration for a Maven goal. This is useful, for example, when using the Jetty Maven plugin that allows you to quickly deploy and run a Java web application using this popular server.

Maven is a project management tool that goes beyond dependency management. See Learning Maven Concepts to learn more.

Download an Existing Maven Project

This tutorial uses a Maven archetype that generates a web application with a preconfigured Jetty Maven Plugin in it:

mvn -B archetype:generate -DarchetypeGroupId=com.vaadin -DarchetypeArtifactId=vaadin-archetype-application -DarchetypeVersion=LATEST -DgroupId=org.test -DartifactId=webapp -Dversion=1.0-SNAPSHOT

NOTE: If you prefer, you can generate a ZIP file with the project at https://vaadin.com/start/latest or https://start.vaadin.com. Make sure you select the Plain Java Servlet option before downloading the project.

The project should include a directory with a Maven project in it:

NOTE: You need Node.js installed on your computer to compile the example application.

Import the Project

There are several ways to import a Maven project in IntelliJ IDEA. The most common approach is to open the pom.xml file directly. You can do it in the welcome screen by clicking Open:

NOTE: Import Project gives you more options to tweak the import process. However, this is out of the scope of this tutorial.

Select the pom.xml file of the Maven project you want to import and click Open as Project.

NOTE: The welcome window is only shown when you close all projects in IntelliJ IDEA. If you don’t want to close your currently opened projects, you can select File > Open on the menu instead.

Running Maven Goals

IntelliJ IDEA has excellent integration with Maven. You can run common commands such as mvn install or mvn jetty:runwithout having to leave the IDE.

Open the Maven view by clicking the corresponding option on the left side of the IntelliJ IDEA window:

This view shows all the available Maven projects and their build phases and build goals. Let’s say you want to run mvn install. To do that, expand the project tree in the Maven view to show the corresponding lifecycle phase and then double-click install:

You’ll see how IntelliJ IDEA executes the install build phase (and all the previous phases in the Maven’s default lifecycle) that downloads dependencies and copies the generated artifacts into your local Maven repository, among other things.

You can use a similar approach to run any Maven goal. For example, you can double-click the jetty:run goal in the Plugins sub-tree to deploy and run the web application implemented in the project you imported. Similarly, if you are using Spring, you can double-click spring-boot:run to run the application.

Creating a Running Configuration

Since using the jetty:run goal could be a frequent task during the development of a Java web application, you may prefer to create a running configuration for it.

A running configuration is a shortcut to run a specific task from within the IDE. Let’s create a running configuration for the jetty:run Maven goal to make it simpler to run the web application.

Right-click the jetty:run option in the Maven view and select Create 'webapp [jetty:run]':

For simplicity, change the name of the configuration to Run on Jetty and click OK:

NOTE: If you are using a multi-module Maven project, make sure you select the correct module when creating the running configuration.

You should see the new option on the top right corner of IntelliJ IDEA:

Now you can deploy and run the web application by clicking the run (or the debug) icon in the toolbar:

NOTE: If you use the Vaadin project used in the tutorial, you can invoke the web application at http://localhost:8080.

That’s it. Now you can use IntelliJ IDEA to develop your Maven application!

Java 12 and IntelliJ IDEA

Java 12 and IntelliJ IDEA

Java 12 and IntelliJ IDEA. In this article, we’ll cover the pain points of using existing switch statements, define switch expressions, and explain why they are good for you.

With switch expressions, Java 12 is enhancing one of its basic language constructs – switch – to improve everyday coding experience for developers. Benefits are multi-fold. As compared to the ‘traditional’ switch constructs, switch expressions can return a value. The ability to define multiple constants with a switch branch, and improved code semantics, makes it concise. By removing default fall-through switch branches, you are less likely to introduce a logical error in a switch expression.


Let’s get started.


Traditional switch constructs

If you think of a switch construct as a multi-way condition, using an expression seems to be a better fit. However, switch could only be used as a statement until now. The current switch syntax is constrained and verbose. It often leads to error-prone code that is difficult to debug.

Here’s an example that uses a switch statement to calculate the height of a chair, based on the size value passed to it:

public enum Size {S, M, L, XL};
public class Chair {
    public void calcHeight(Size size) {
        int height = 0; 
        switch (size) {
            case S:
                height = 18;
            case M:
                height = 20;
                break;
            case L:
                height = 25;
                break;
        }
    }
}

The preceding code has multiple issues:

  • Repetitive break and assignment statements add noise to code.
  • Code verbosity makes it difficult to comprehend the code.
  • Default fall-through in switch branches sneaks in a logical error – the missing break statement for case label S lets the control fall through to case label M. This results in assignment of 20 instead of 18 to height when you execute calcHeight(Size.S).
Switch expressions

Let’s rewrite the preceding example using a switch expression. In IntelliJ IDEA, you can use Alt+Enter on the switch keyword to see the suggestions. Select ‘Replace with enhanced ‘switch’ statement’ to convert the traditional switch statement to a switch expression:

The preceding code offers multiple benefits:

  • Code in a switch branch is concise and easy to read. You define what to execute to the right of ->.
  • Switch branches can return a value, which can be used to assign value to a variable.
  • Switch branches don’t need a break statement to mark their end. In absence of a break statement, the control doesn’t fall through the switch labels – which helps avoid logical errors.
Returning value vs. executing statements

When you aren’t using a switch expression to return a value, a switch branch can choose to execute a statement or block of statements, or even throw an exception:

public enum Size {S, M, L, XL};
public class NotReturningValueFromSwitchLabel {
    public void calcHeight(Size size) {
        int height = 0; 
        switch (size) {
            case S -> height = 18;
            case M -> { 
                           height = 20; 
                           System.out.println(height);
                      }
            case L -> height = 25;
        }
    }
}
Handling all possible argument values

When you are using a switch expression to return a value, it should be able to handle all possible values that you could pass to it as an argument. For instance, if you miss a case label corresponding to an enum constant, IntelliJ IDEA detects it. It offers to insert the specific case label or default case label.

By default, IntelliJ IDEA inserts a default value depending on the variable type. You can edit the placeholder value:

Types other than an enum can have infinite values. When you pass types like byte, short, int, or String and miss including the default label, IntelliJ IDEA can detect and fix it:


Define multiple constants in the same case label

Unlike switch statements, switch expressions allow you to define comma-separated multiple constants in a case label. This cuts down code redundancy – you can execute the same code for all case labels.

If you define redundant code for your case labels in a switch expression, IntelliJ IDEA can fix it for you:


Local variables and break statements in switch branches

With switch expressions, you can define local variables in switch branches. The block must include a break statement specifying the value to return:

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

enum Size {S, M, L, XL};

public class LocalVariablesWithSwitch {
public void assignValue(Size size) {
int height = 0;
height = switch(size) {
case S -> 18;
case M -> {
int weight = 19;
break (weight > 10 ? 15 : 20);
}
case L, XL -> 25;
};
}
}

The case label for value M defines a block statement. A block can also define local variables (weight in this case). The scope and accessibility of the local variable weight is limited to the case label M. Notice how a switch expression uses a break statement to return a value.

Just in case you miss defining a return value for a switch branch, IntelliJ IDEA underlines the keyword case. When you hover the mouse pointer over it, you can view the message about the missing return value:


Preview language feature

Switch expressions is a preview language feature. This essentially means that even though it is complete, it has a possibility of not being confirmed as a permanent feature in a future Java release. This happens for a reason.

Java runs on billions of devices and is used by millions of developers. Risks are high for any mistake in a new Java language feature. Before permanently adding a language feature to Java, the architects of Java evaluate what the developers have to say about it – how good or bad it is. Depending on the feedback, a preview feature might be refined before it’s added to Java SE, or dropped completely. So, if you have any feedback on Switch expressions, please share it here.


IntelliJ IDEA Configuration

Since Switch expressions is a Java 12 language feature, please download and install OpenJDK 12 and configure it to use with IntelliJ IDEA:

Java is evolving and switch expressions is one of the welcome changes in Java 12.

Happy Coding!


Originally published by Mala Gupta at https://blog.jetbrains.com

Main class not found in project IntelliJ IDEA: Java Application

IntelliJ does not find a main class in my Java application project. The project was cloned from a git repository so had no run configuration. I go to Edit Configurations, add a new Application template, go to Main class: and it says "No matches found in project".

IntelliJ does not find a main class in my Java application project. The project was cloned from a git repository so had no run configuration. I go to Edit Configurations, add a new Application template, go to Main class: and it says "No matches found in project".

So, manually searching through the hierarchy I find the .java file that contains the main function but it will not accept it as the main class. I've pasted the file below to prove that it has the correct main function.

public class AdvanceWarsGameHandler implements IGame
{
private Image mImage;
private String mTitle;

public AdvanceWarsGameHandler()
{
    mTitle = "Advance Wars Game";
    mImage = new Image("/OffBrandCerealOopsAllCarries2-01.png");
}

//Game logic unrelated to graphics goes here
@Override
public void update(Game game, float deltaTime) 
{

}

//Update, but for graphics
@Override
public void render(Game game, Renderer renderer) 
{
    renderer.drawImage(mImage, game.getInput().getMouseX(), game.getInput().getMouseY());
}

 public static void main(final String args[])
{
    //Creating and starting an instance of AdvanceWarsGameHandler
    AdvanceWarsGameHandler advancewars = new AdvanceWarsGameHandler();
    Game myGame = new Game(advancewars);
    myGame.start();
}

public String getTitle()
{
    return mTitle;
}

}

So the question is, why is the IntelliJ project not recognizing the main function in this file, or what is IntelliJ looking for as the "Main class" of an application?