
320 pages · 2024
Java Programming Exercises
Volume One: Language Fundamentals and Core Concepts
By Christian Ullenboom
- Published
- September 4, 2024
- Imprint
- Chapman and Hall/CRC
- Edition
- 1st Edition
- ISBN
- 9781003454502
Overview
About this book
Take the first step in raising your coding skills to the next level, and test your Java knowledge on tricky programming tasks, with the help of the pirate Captain CiaoCiao. This is the first of two volumes which provide you with everything you need to excel in your Java journey, including tricks that you should know in detail as a professional, as well as intensive training for clean code and thoughtful design that carries even complex software.
Features:
About 200 tasks with commented solutions on different levels For all paradigms: object-oriented, imperative, and functional Clean code, reading foreign code, and object-oriented modeling
With numerous best practices and extensively commented solutions to the tasks, these books provide the perfect workout for professional software development with Java.
Subjects
Computer Science
Inside the book
Table of contents
Select a chapter to read its abstract.
ChapterIntroduction
Pages: 5
Many beginners in programming often ask themselves, “How can I strengthen my skills as a developer? How can I become a better programmer?” The answer is simple: study, attend webinars, learn, repeat, practice, and discuss your work with others. Many aspects of programming are similar to learning new skills. Just as a book can’t teach you how to play a musical instrument, watching the Fast and the Furious movie series won’t teach you how to drive. The brain develops patterns and structures through repeated practice. Learning a programming language and a natural language have many similarities. Consistent use of the language and the desire and need to express and communicate in it (just as you need to do so to order a burger or a beer) lead to gradual improvement in skills.
Chapter 1Introduction to the Java Ecosystem
Pages: 3
Many newcomers get caught in “tutorial hell”: they read a lot, watch countless videos. This chapter is here to help you break out of your shell and get comfortable with practical programming. You’ll not only learn your way around the development environment, but you’ll also be able to flex your skills by running programs from the command line. In the process, we will get to know our development environment better, be able to run programs from the command line, and see more clearly the division of tasks between the Java compiler and the runtime environment.
Chapter 2Imperative Programming
Pages: 69
At its core, the virtual machine does nothing more but evaluates expressions and executes statements. The exercises in this chapter focus on the different data types, various operators, and conditional execution.
Chapter 3Classes, Objects, and Packages
Pages: 8
In the previous chapters, we used classes as containers for static methods. We did not intentionally build new objects with new. In this chapter, the following exercises deal with creating new objects, object references, and the special null reference.
Chapter 4Arrays
Pages: 28
Arrays are important data structures that also appear indirectly in Java, for example, in the enhanced for loop or variable argument lists. This chapter includes exercises on creating arrays, traversing arrays, and questions about algorithms, such as how to search for elements in an array.
Chapter 5Character and String Processing
Pages: 62
For storing characters and strings, Java provides the types char, Character, String, and StringBuilder. The use of the data types must be practiced because each type has its justification. The exercises help the readers to understand the advantages and disadvantages of each data type.
Chapter 6Writing Your Own Classes
Pages: 40
We’ve already created multiple classes. However, these classes have only utilized static fields and methods, and we haven’t leveraged them to create instances yet. While we have crafted objects using classes from the Java standard library, we aim to broaden our understanding. We’re now looking to design our own classes and create instances of these custom types.
Chapter 7Records, Interfaces, Enumerations, and Sealed Classes
Pages: 22
Records are useful in Java because they provide a simple and compact way to define and use data objects with a fixed number of attributes.
Chapter 8Nested Types
Pages: 6
In the previous examples, we always had exactly one type of declaration in each file, the so-called compilation unit. However, Java also allows for nested types, where a type declaration can be placed inside another type declaration, making the relationship between them even closer. The following exercises demonstrate the usefulness of nested types, but there are also some potential issues that need to be considered. To gain a deeper understanding of nested types, several quizzes will be provided.
Chapter 9Exception Handling
Pages: 19
Unforeseen errors can occur at any time. Our programs must be prepared for them and be able to handle this situation. The next exercises will be about catching exceptions, handling them, and even reporting problems via exceptions.
Chapter 10Lambda Expressions and Functional Programming
Pages: 12
Lambda expressions are the foundation of functional programming and serve as mappings. Functional programming is centered around functions, with a focus on pure expressions that don’t have side effects. In Java, it’s not possible to pass functions (methods) directly to other functions or return them, so the workaround is to encapsulate these methods in a class and pass them as objects. Lambda expressions provide a convenient way to quickly implement a class with a specific interface. They serve as implementations of functional interfaces—interfaces with only one abstract method—and are an alternative and efficient shortcut to classes that implement interfaces. As a result, expressing program code and passing it to other methods becomes more straightforward.
Chapter 11Special Types from the Java Class Library
Pages: 20
The class library includes thousands of types, with a huge number added via the Java Enterprise Frameworks and open-source libraries. Fortunately, you don’t need to know all of these types to write software successfully. Much of Java SE is also very low level and intended more for framework developers.