Book Image

Learn Java with Projects

By : Dr. Seán Kennedy, Maaike van Putten
5 (3)
Book Image

Learn Java with Projects

5 (3)
By: Dr. Seán Kennedy, Maaike van Putten

Overview of this book

Learn Java with Projects stands out in the world of Java guides; while some books skim the surface and others get lost in too much detail, this one finds a nice middle ground. You’ll begin by exploring the fundamentals of Java, from its primitive data types through to loops and arrays. Next, you’ll move on to object-oriented programming (OOP), where you’ll get to grips with key topics such as classes, objects, encapsulation, inheritance, polymorphism, interfaces, and more. The chapters are designed in a way that focuses on topics that really matter in real-life work situations. No extra fluff here, so that you get more time to spend on the basics and form a solid foundation. As you make progress, you’ll learn advanced topics including generics, collections, lambda expressions, streams and concurrency. This book doesn't just talk about theory—it shows you how things work with little projects, which eventually add up to one big project that brings it all together. By the end of this Java book, you’ll have sound practical knowledge of Java and a helpful guide to walk you through the important parts of Java.
Table of Contents (22 chapters)
1
Part 1: Java Fundamentals
9
Part 2: Object-Oriented Programming
15
Part 3: Advanced Topics

Working with an IDE

Creating files in text editors is a little old-fashioned. Of course, you can still do it this way – it’s actually an excellent way of becoming an amazing programmer, but it’s also a very frustrating way. There are tools available to do quite a bit of the heavy work for us and to assist us while writing our code. These tools are called IDEs.

What is an IDE?

An IDE is a software application that comes with everything you need to write, compile, run, and test your code. Using an IDE can make it easier to develop all sorts of programs. Not only that but also debugging and managing your code is easier. Comparatively, you can think of an IDE somewhat like Microsoft Office Word for me as I write this book. While I could have written it using Notepad, using Word provides significant advantages. It assists in checking for spelling errors and allows me to easily add and visualize layouts, among other helpful features. This analogy paints a picture of how an IDE doesn’t just provide a platform to write code but also offers a suite of tools to streamline and enhance your coding experience.

Choosing an IDE

When it comes to Java development, there are several IDEs available, each with its own set of features and capabilities. In this section, we will discuss the factors to consider when choosing an IDE and help you set up some popular Java IDEs. Throughout this book, we’ll be working with IntelliJ. Alternatives that are also great would be VS Code and Eclipse.

Factors to consider when choosing an IDE

Most modern IDEs have features such as code completion, debugging, version control integration, and support for third-party tools and frameworks. Some of them have better versions of these than others. Compare and contrast what you prefer when choosing or switching IDEs.

Some IDEs require a heavier system to run on than others. For example, VS Code is rather lightweight and IntelliJ is rather heavy. Also, VS Code can be used for many languages, including Java. It is uncommon to do a lot of other things with IntelliJ rather than Java. Choose an IDE that provides a balance between features and performance, especially if you have limited system resources.

And of course, it’s possible that the IDE you’d prefer is not available for the platform you’re using. Make sure that it’s available and stable for your system.

Lastly, and very importantly, think about the costs. Some IDEs are free and others require a paid license. Luckily, many of the ones that require a paid license have a free edition for non-commercial use. So, make sure to also consider your budget and the licensing you need when choosing an IDE.

In the following subsections, we’ll walk you through the steps of setting up the three (currently) most common IDEs for Java development:

  • IntelliJ
  • Eclipse
  • Visual Studio Code

Note

We’ll be working with IntelliJ for the rest of this book.

Setting up IntelliJ

So, let’s start with that one. IntelliJ IDEA is a popular Java IDE that was developed by JetBrains. It offers both a free Community Edition and a paid Ultimate Edition. It provides a wide range of features, including intelligent code completion, debugging tools, version control integration, and support for various Java frameworks.

Here are the steps for installing IntelliJ:

  1. Visit the IntelliJ IDEA download page at https://www.jetbrains.com/idea/download/.
  2. Choose the edition you prefer: the free Community Edition or the paid Ultimate Edition. For beginners, the Community Edition is truly great already.
  3. Download the installer for your operating system (Windows, macOS, or Linux).
  4. Run the installer and follow the instructions to complete the installation.
  5. Launch IntelliJ IDEA. If you’re using the Ultimate Edition, you may need to enter your JetBrains account credentials or a license key.
  6. On the Welcome screen, you can create a new project, import an existing project, or explore the available tutorials and documentation.

Setting up Eclipse

Eclipse is a free, open source Java IDE that is widely used in the Java community. It has been around for a really long time already and quite a lot of companies work with it still. It offers a variety of features, just like IntelliJ. Eclipse can be customized to suit your needs, but its interface may be less intuitive than other IDEs.

To set up Eclipse, follow these steps:

  1. Visit the Eclipse download page at https://www.eclipse.org/downloads/.
  2. Download the Eclipse installer for your operating system (Windows, macOS, or Linux).
  3. Run the installer and select Eclipse IDE for Java Developers from the list of available packages.
  4. Choose an installation folder and follow the instructions to complete the installation.
  5. Launch Eclipse and select a workspace directory. This is where your projects and settings will be stored.
  6. On the Welcome screen, you can create a new Java project, import an existing project, or explore the available tutorials and documentation.

Setting up Visual Studio Code

Visual Studio Code, often referred to as VS Code, is a lightweight, free, and open source code editor developed by Microsoft. It’s incredibly popular for all sorts of tasks because it supports a wide range of programming languages. It is a popular choice for developers who prefer a more minimalist and fast-performing environment. All sorts of additions can be added with the use of extensions.

Here are the steps for installing VS Code and preparing it for Java development:

  1. Visit the Visual Studio Code download page at https://code.visualstudio.com/download.
  2. Download the installer for your operating system (Windows, macOS, or Linux).
  3. Run the installer and follow the on-screen instructions to complete the installation.
  4. Launch Visual Studio Code.
  5. Open the Extensions view by clicking on the Extensions icon (four squares) on the left side of the window.
  6. Search for Java Extension Pack in the Extensions Marketplace and click the Install button. This extension pack includes various extensions for Java development, such as Language Support for Java (TM) by Red Hat, Debugger for Java, and Maven for Java.
  7. With the Java Extension Pack installed, you can now create or import Java projects. If it doesn’t load directly, you may need to reopen VS Code.

Now that you’ve set up an IDE, let’s create and run a program with it.