Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Learn Java with Projects
Learn Java with Projects

Learn Java with Projects: A concise practical guide to learning everything a Java professional really needs to know

Arrow left icon
Profile Icon Dr. Seán Kennedy Profile Icon Maaike van Putten
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Full star icon Half star icon 4.9 (51 Ratings)
Paperback Nov 2023 598 pages 1st Edition
eBook
€26.98 €29.99
Paperback
€37.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Dr. Seán Kennedy Profile Icon Maaike van Putten
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Full star icon Half star icon 4.9 (51 Ratings)
Paperback Nov 2023 598 pages 1st Edition
eBook
€26.98 €29.99
Paperback
€37.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€26.98 €29.99
Paperback
€37.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Learn Java with Projects

Getting Started with Java

Welcome to the exciting world of Java! Java is a very popular programming language. It is a multipurpose, powerful, and popular programming language that has been used by millions of developers worldwide to create a wide variety of applications. And yes, it really is multipurpose since it can be used to create all sorts of applications, from web and mobile apps to game development and beyond.

So, you’ve done a great job choosing a (new) language. We’re going to take you on a (hopefully) fascinating journey that will provide you with valuable skills and open new opportunities in the ever-evolving field of technology.

What are we waiting for? In this chapter, we’re going to cover the following main topics:

  • Java features
  • Installing Java
  • Compiling and running Java programs
  • Working with an integrated development environment (IDE)
  • Creating and running a program with an IDE

Technical requirements

Before diving into the magical world of Java programming, let’s ensure you have the right hardware. If your hardware doesn’t meet these requirements, don’t worry; online alternatives are discussed later in this chapter. If you are using your work laptop, make sure that you have download rights. Here’s a brief overview of the requirements:

  • Operating system: Java can run on various operating systems, including Windows, macOS, and Linux. Ensure that you have a recent version of one of these operating systems installed on your computer.
  • Java Development Kit (JDK): To compile and run Java programs, you’ll need the JDK installed on your system. The JDK includes the Java Runtime Environment (JRE), which contains the necessary libraries and components for running Java applications. We’ll see how to install this later.
  • System resources: More is always better, but Java isn’t too demanding. It doesn’t require high-end hardware, but it’s still a good idea to have a system with sufficient resources for a smooth development experience. The following are the minimum and recommended system requirements:
    • Minimum requirements:
      • CPU: 1 GHz or faster processor
      • RAM: 2 GB
      • Disk space: 1 GB (for JDK installation and additional files)
    • Recommended requirements:
      • CPU: 2 GHz or faster multi-core processor
      • RAM: 4 GB or more
      • Disk space: 2 GB or more (for JDK installation, additional files, and projects)

Keep in mind that these requirements may change with future updates to the JDK and related tools. We have placed the files in a GitHub repository. You can clone the projects with the use of Git and import them to your computer this way. It’s beyond the scope of explaining how to use Git here but it’s recommended to look into it independently. You can access the files and examples used in this book here: https://github.com/PacktPublishing/Learn-Java-with-Projects.

Exploring Java features

Java was developed by James Gosling at Sun Microsystems in the mid-1990s. When Java was created, it was originally designed as a language for consumer electronics. It attempted to support complex host architectures, focused on portability, and supported secure networking. However, Java outgrew its own ambitions. It quickly gained momentum as a versatile language for creating enterprise, web, and mobile applications. Today, Java no longer belongs to Sun Microsystems. Oracle Corporation acquired Sun Microsystems in 2010. And with that acquirement, Java became an integral part of Oracle’s software ecosystem.

Java was very unique at the time it was created. The huge success of Java can be attributed to some of its core features. These features were very innovative at the time but are now found in many other (competing) languages. One of the core features is object-oriented programming. OOP allows us to structure our code in a neat way that helps with reusability and maintainability. We’re going to start discussing the core features by having a look at object-oriented programming (OOP).

OOP in Java

Arguably the most important feature of Java is its support for OOP. If you ask any Java developer what Java is, the answer is often that it’s an OOP language.

It’s safe to say that OOP is a key feature. What is this OOP thing? you may wonder. OOP is a programming paradigm. It structures applications to model real-world objects and their interactions and behaviors. Let’s go over the main concepts of OOP:

  • Objects: This may be stating the obvious but, in OOP, objects are the main building blocks of your program. An object is a representation of a real-world entity, such as a user, an email, or a bank account. Each object has its own attributes (data fields) and behaviors (methods).
  • Classes: Objects are created using their class. A class is a blueprint for creating objects. It defines the attributes and methods that objects of the class should have. For example, a Car class might define attributes such as color, make, and model, and methods such as start, accelerate, and brake.
  • Inheritance: Another key feature is inheritance. Inheritance allows one class to inherit the attributes and methods of another class. For example, Car could inherit from a Vehicle class. We’re not going to cover the details here, but inheritance helps to better structure the code. The code is more reusable, and the hierarchy of related classes opens doors in terms of what we can do with our types.
  • Encapsulation: Encapsulation is giving a class control over its own data. This is done by bundling data (attributes) and methods that operate on that data. The attributes can only be accessed via these special methods from outside. Encapsulation helps to protect the internal state of an object and allows you to control how the object’s data can be accessed or modified. Don’t worry if this sounds tricky still, we’ll deal with this in more detail later.
  • Polymorphism and Abstraction: These are two key concepts of OOP that will be explained later when you’re ready for them.

Working with OOP

I can imagine this all sounds very abstract at this point, but before you know it, you’ll be creating classes and instantiating objects yourself. OOP helps to make code more maintainable, better structured, and reusable. These things really help to be able to make changes to your application, solve problems, and scale up when needed.

OOP is just one key feature of Java. Another key feature is that it’s a compiled language. Let’s make sure you understand what is meant by that now.

Compiled language

Java is a compiled programming language, which means that the source code you write must be transformed into a machine-readable format before it can be interpreted. This machine-readable format is called bytecode. This process is different from that of interpreted languages, where the source code is read, interpreted, and executed on the fly. During runtime, the computer interprets an interpreted language line by line. When a compiled language is running, the computer interprets the bytecode during runtime. We’ll dive deeper into the compilation process in just a bit when we are going to compile our own code. For now, let’s see what the benefits of compiled languages are.

Benefits of Java being a compiled language

Compiling code first requires an extra step, and it takes time in the beginning, but it brings advantages. First of all, the performance of compiled languages is typically better than interpreted languages. This is because the bytecode gets optimized for efficient execution on the target platform.

Another advantage of compilation is the early detection of syntax errors and certain other types of errors before the code is executed. This enables developers to identify and fix issues before deploying the application, reducing the likelihood of runtime errors.

Java code is turned into bytecode – a form of binary code - by the compiler. This bytecode is platform-independent. This means that it allows Java applications to run on different operating systems without modification. Platform independence is actually the key feature that we’re going to be discussing next.

Write once, run anywhere

Java’s Write Once, Run Anywhere (WORA) principle is another key feature. This used to set Java apart from many other programming languages, but now, this is rather common, and many competing languages also implemented this feature. This principle ensures that Java code can run on different platforms without requiring different versions of the Java code for each platform. This means that a Java program is not tied to any specific operating system or hardware architecture.

When you have different versions of the code for each platform, this means that you have to maintain all these versions of the code as well. Let’s say you have a code base for Linux, macOS, and Windows. When a new feature or a change is required, you need to add this to three places! You can imagine that WORA was a game-changer at the time Java came out. And it leads to an increased reach of your application – any device that can run Java applications can run yours.

Understanding the WORA elements

The WORA principle is made possible by bytecode and the Java Virtual Machine (JVM). Bytecode is the compiled Java program. The compiler turns the Java code into this bytecode, and this bytecode is platform-independent. It can run on any device that can run the bytecode executer.

This bytecode executer is called the JVM. Each platform (Windows, macOS, Linux, and so on) has its own JVM implementation, which is specifically designed to translate bytecode into native machine code for that platform. Since the bytecode remains the same across platforms, the JVM handles the differences between operating systems and hardware architectures. The WORA principle is explained in Figure 1.1.

Figure 1.1 – The WORA principle in a diagram

Figure 1.1 – The WORA principle in a diagram

You can see that the compiler creates bytecode and that this bytecode can be picked up by the JVM. The JVM is platform-specific and does the translation to the platform it’s on. There’s more that the JVM does for us, and that is automatic memory management. Let’s explore this next.

Automatic memory management

Another key feature that made Java great is its automatic memory management, which simplifies development and prevents common memory-related errors. Java handles memory allocation and garbage collection for you. The developer doesn’t need to take care of manually managing the memory.

Nowadays, this is the rule and not the exception. Most other modern languages have automatic memory management as well. However, it is important to know what automatic memory management means. The memory allocation and deallocation are done automatically. This actually leads to simplifying the code. There is no boilerplate code that just focuses on the allocation and deallocation of the memory. This also leads to fewer memory-related errors.

Let’s make sure you understand what is meant by memory allocation and deallocation.

Memory allocation

In code, you create variables. Sometimes, these variables are not simple values but complex objects with many data fields. When you create an object, this object needs to be stored somewhere in the memory of the device that it’s running on. This is called memory allocation. In Java, when you create an object, device memory is automatically allocated to store the object’s attributes and associated data. This is different from languages such as C and C++, where developers must manually allocate and deallocate memory. Java’s automatic memory allocation streamlines the development process and reduces the chances of memory leaks or dangling pointers, which can cause unexpected behavior or crashes. It also makes the code cleaner to read, since you don’t need to deal with any allocation or deallocation code.

Garbage collection

When a memory block is no longer used by the application, it needs to be deallocated. The process Java uses for this is called garbage collection. Garbage collection is the process of identifying and reclaiming memory that is no longer in use by a program. In Java, when an object is no longer accessible or needed, the garbage collector automatically frees up the memory occupied by the object. This process ensures that the memory is efficiently utilized and prevents memory leaks and the problems that come with it.

The JVM periodically runs the garbage collector to identify and clean up unreachable objects. Java’s garbage collection mechanism uses many different sophisticated algorithms to determine when an object is no longer needed.

Now that we’ve covered the basics, let’s move on to installing Java.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Gain a deep understanding of essential topics that will help you progress with Java
  • Learn by working on mini-projects to help reinforce the concepts you’ve learned
  • Gain comprehensive knowledge of the core concepts of Java
  • Purchase of the print or Kindle book includes a free PDF eBook

Description

Learn Java with Projects bridges the gap between introductory Java guides and verbose, theoretical references. This book is crafted to build a strong foundation in Java programming, starting from the Java environment itself. It goes far beyond a superficial review of the topics; it demonstrates, with practical examples, why these fundamentals are crucial for developing a deep understanding of the language. You'll not only learn about classes and objects but also see how these concepts are used in practical scenarios, enhancing your ability to write clean, efficient code. The engaging projects throughout the book provide real-world applications of complex topics, ensuring you can connect theoretical knowledge with practical skills. What makes this book stand out is the expertise of its authors. Seán, a seasoned university lecturer with over 20 years of experience, brings academic rigor and real-world insights, thanks to his work with a prestigious software company. Maaike, a passionate software developer and award-winning trainer, brings hands-on experience and a love for teaching. By the end of this book, you'll not only understand Java's core concepts and the critical advanced ones, but also gain practical experience through projects that mimic real-life challenges.

Who is this book for?

This book is for anyone looking to learn the core concepts of Java. If you’re learning programming (and Java) for the first time or want to upskill to Java (with experience in a different language), then this book is for you. Prior knowledge of programming is helpful but not necessary.

What you will learn

  • Get to grips with Java fundamentals to build a strong programming foundation
  • Gain a deep understanding of the critical object-oriented principles: encapsulation, inheritance and polymorphism
  • Apply real-world scenarios using classes, objects, and interfaces
  • Master exception handling for robust error management
  • Explore generics and collections to manage complex data structures
  • Utilize lambda expressions and streams for efficient data processing
  • Complete practical projects to reinforce theoretical knowledge

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 30, 2023
Length: 598 pages
Edition : 1st
Language : English
ISBN-13 : 9781837637188
Category :
Languages :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Nov 30, 2023
Length: 598 pages
Edition : 1st
Language : English
ISBN-13 : 9781837637188
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 120.97
50 Algorithms Every Programmer Should Know
€37.99
C# 12 and .NET 8 – Modern Cross-Platform Development Fundamentals
€44.99
Learn Java with Projects
€37.99
Total 120.97 Stars icon

Table of Contents

21 Chapters
Part 1: Java Fundamentals Chevron down icon Chevron up icon
Chapter 1: Getting Started with Java Chevron down icon Chevron up icon
Chapter 2: Variables and Primitive Data Types Chevron down icon Chevron up icon
Chapter 3: Operators and Casting Chevron down icon Chevron up icon
Chapter 4: Conditional Statements Chevron down icon Chevron up icon
Chapter 5: Understanding Iteration Chevron down icon Chevron up icon
Chapter 6: Working with Arrays Chevron down icon Chevron up icon
Chapter 7: Methods Chevron down icon Chevron up icon
Part 2: Object-Oriented Programming Chevron down icon Chevron up icon
Chapter 8: Classes, Objects, and Enums Chevron down icon Chevron up icon
Chapter 9: Inheritance and Polymorphism Chevron down icon Chevron up icon
Chapter 10: Interfaces and Abstract Classes Chevron down icon Chevron up icon
Chapter 11: Dealing with Exceptions Chevron down icon Chevron up icon
Chapter 12: Java Core API Chevron down icon Chevron up icon
Part 3: Advanced Topics Chevron down icon Chevron up icon
Chapter 13: Generics and Collections Chevron down icon Chevron up icon
Chapter 14: Lambda Expressions Chevron down icon Chevron up icon
Chapter 15: Streams – Fundamentals Chevron down icon Chevron up icon
Chapter 16: Streams: Advanced Concepts Chevron down icon Chevron up icon
Chapter 17: Concurrency Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.9
(51 Ratings)
5 star 98%
4 star 0%
3 star 0%
2 star 0%
1 star 2%
Filter icon Filter
Top Reviews

Filter reviews by




Sandra Patricia Bermudez Kasperczak Feb 22, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Feefo Verified review Feefo
N/A Feb 21, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Feefo Verified review Feefo
Armando Herrera Feb 08, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Feefo Verified review Feefo
Karol Piatek Jul 10, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
In the software engineering world dominated by Python and Golang,there is a big universe where T-Rex 21, Java, is still a first-class citizen.This book is for you if you start your journey with software developmentor Java is your bread and butter.I highly recommend all exercises, especially in my favourite chaptersabout lambda functions and primitive streams.I highly recommend the book, and I can not wait for the next editionon Java Vector API and more advanced topics.As for Sean and Maaike,they prove, that learning new skills can be a lot of fun.
Amazon Verified review Amazon
MS MARY GIBLIN Jan 26, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
As someone deeply invested in the programming world, I was eager to delve into "Learn Java with Projects" by Maaike van Putten and Dr. Sean Kennedy (Let’s Get Certified). Learn Java with Projects is a comprehensive journey into the world of Java programming. The philosophy that mastery in programming comes from hands-on practice. Is brought to life in this book. The integration of theory with practical application underpins the material, highlighting van Putten and Kennedy's extensive experience in teaching and training. The choice of examples and projects around dinosaurs is a breath of fresh air in technical education and makes for a fun learning approach. The book uses diagrams effectively to explain concepts e.g. In-memory representation of immutable types. The book delves into the nuances of java Programming which is a necessity for anyone planning to take certification exams. The full chapter on Lambda expressions greatly clarified the topic for me. Two full chapters on Streams is noteworthy for anyone developing Microservices with Java. One possible enhancement for the book could be to list or index Java 21 features separately. While these features are embedded within the chapters, having them distinctly listed or indexed would make it easier for readers to quickly reference these latest language updates. "Learn Java with Projects" is a great resource. I would recommend this book for anyone whether you are a beginner, gearing up for certification or an experience programmer that wants to brush up on your skills.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.