O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Java Projects - Second Edition

Book Description

Learn how to build scalable, resilient, and effective applications in Java that suit your software requirements.

Key Features

  • Explore advanced technologies that Java 11 delivers such as web programming and parallel computing
  • Discover modern programming paradigms such as microservices, cloud computing and enterprise structures
  • Build highly responsive applications with this practical introduction to Reactive programming

Book Description

Java is one of the most commonly used software languages by programmers and developers. In this book, you'll learn the new features of Java 11 quickly and experience a simple and powerful approach to software development. You'll see how to use the Java runtime tools, understand the Java environment, and create a simple namesorting Java application. Further on, you'll learn about advanced technologies that Java delivers, such as web programming and parallel computing, and will develop a mastermind game. Moving on, we provide more simple examples, to build a foundation before diving into some complex data structure problems that will solidify your Java 11 skills. With a special focus on the features of new projects: Project Valhalla, Project Panama, Project Amber, and Project Loom, this book will help you get employed as a top-notch Java developer. By the end of the book, you'll have a firm foundation to continue your journey toward becoming a professional Java developer.

What you will learn

  • Compile, package, and run a program using a build management tool
  • Get to know the principles of test-driven development
  • Separate the wiring of multiple modules from application logic
  • Use Java annotations for configuration
  • Master the scripting API built into the Java language
  • Understand static versus dynamic implementation of code

Who this book is for

This book is for anyone who wants to learn the Java programming language. No programming experience required. If you have prior experience, it will help you through the book more easily.

Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Java Projects Second Edition
  3. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  4. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Acknowledgments
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  7. Getting Started with Java 11
    1. Getting started with Java
      1. Version numbers
    2. Installing Java
      1. Installation on Windows
      2. Installation on macOS
      3. Installation on Linux
      4. Setting JAVA_HOME
    3. Executing jshell
      1. Looking at the bytecode
    4. Packaging classes into a JAR file
    5. Managing the running Java application
    6. Using an IDE
      1. NetBeans
      2. Eclipse
      3. IntelliJ
      4. IDE services
        1. IDE screen structure
        2. Editing files
        3. Managing projects
        4. Building the code and running it
        5. Debugging Java
    7. Summary
  8. The First Real Java Program - Sorting Names
    1. Getting started with sorting
      1. Bubble sort
    2. Getting started with project structure and build tools
      1. Make
      2. Ant
        1. Installing Ant
        2. Using Ant
      3. Maven
        1. Installing Maven
        2. Using Maven
      4. Gradle
        1. Installing Gradle
    3. Setting up the project with Maven
    4. Coding the sort
    5. Understanding the algorithm and language constructs
      1. Blocks
      2. Variables
      3. Types
      4. Arrays
      5. Expressions
      6. Loops
      7. Conditional execution
      8. Final variables
      9. Classes
      10. Inner, nested, local, and anonymous classes
      11. Packages
      12. Methods
      13. Interfaces
      14. Argument passing
      15. Fields
      16. Modifiers
      17. Object initializers and constructors
    6. Compiling and running the program
    7. Summary
  9. Optimizing the Sort - Making Code Professional
    1. The general sorting program
    2. A brief overview of various sorting algorithms
      1. Quicksort
    3. Project structure and build tools
      1. Maven dependency management
    4. Coding the sort
      1. Creating the interfaces
      2. Creating BubbleSort
      3. Architectural considerations
    5. Creating unit tests
      1. Adding JUnit as a dependency
      2. Writing the BubbleSortTest class
      3. Good unit tests
        1. A good unit test is readable
        2. Unit tests are fast
        3. Unit tests are deterministic
        4. Assertions should be as simple as possible
        5. Unit tests are isolated
        6. Unit tests cover the code
        7. Refactoring the test
    6. Collections with wrong elements
    7. Handling exceptions
    8. Generics
    9. Test-Driven Development
    10. Implementing QuickSort
      1. The partitioning class
      2. Recursive sorting
      3. Non-recursive sorting
      4. Implementing the API class
    11. Creating modules
      1. Why modules are needed
      2. What is a Java module?
    12. Summary
  10. Mastermind - Creating a Game
    1. The game
    2. The model of the game
    3. Java collections
      1. Interface collection
      2. Set
        1. Hash functions
        2. The equals method
        3. The hashCode method
        4. Implementing equals and hashCode
        5. HashSet
        6. EnumSet
        7. LinkedHashSet
      3. SortedSet
      4. NavigableSet
        1. TreeSet
      5. List
        1. LinkedList
        2. ArrayList
      6. Queue
      7. Deque
      8. Map
        1. HashMap
        2. IdentityHashMap
    4. Dependency injection
    5. Implementing the game
      1. ColorManager
      2. The class color
      3. JavaDoc and code comments
      4. Row
      5. Table
      6. Guesser
        1. UniqueGuesser
        2. GeneralGuesser
    6. The Game class
    7. Creating an integration test
    8. Summary
  11. Extending the Game - Run Parallel, Run Faster
    1. How to make Mastermind parallel
    2. Refactoring
    3. Processes
    4. Threads
    5. Fibers
    6. java.lang.Thread
    7. Pitfalls
      1. Deadlocks
      2. Race conditions
      3. Overused locks
      4. Starving
    8. ExecutorService
      1. Completable future
      2. ForkJoinPool
    9. Variable access
    10. The CPU heartbeat
    11. Volatile variables
    12. Synchronized block
    13. Wait and notify
    14. Lock
      1. Condition
      2. ReentrantLock
      3. ReentrantReadWriteLock
    15. Atomic variables
    16. BlockingQueue
      1. LinkedBlockingQueue
      2. LinkedBlockingDeque
      3. ArrayBlockingQueue
      4. LinkedTransferQueue
    17. IntervalGuesser
    18. ParallelGamePlayer
    19. Microbenchmarking
    20. Summary
  12. Making Our Game Professional - Do it as a Web App
    1. Web and network
      1. IP
      2. TCP/IP
      3. DNS
    2. The HTTP protocol
      1. HTTP methods
      2. Status codes
    3. HTTP/2
    4. Cookies
    5. Client server and web architecture
    6. Writing a servlet
      1. Hello world servlet
    7. JavaServer Pages
    8. HTML, CSS, and JavaScript
    9. Mastermind servlet
      1. Storing state
      2. HTTP session
      3. Storing state on the client
      4. Dependency injection with Guice
      5. The MastermindHandler class
      6. Storing state on the server
      7. The GameSessionSaver class
    10. Running the Jetty web servlet
    11. Logging
      1. Configurability
      2. Performance
      3. Log frameworks
      4. Java logging
      5. Logging practice
    12. Other technologies
    13. Summary
  13. Building a Commercial Web Application Using REST
    1. The MyBusiness web shop
    2. Sample business architecture
    3. Microservices
    4. Service interface design
    5. JSON
    6. REST
    7. Model View Controller
    8. Spring framework
      1. Architecture of Spring
      2. Spring core
    9. Service classes
    10. Compiling and running the application
    11. Testing the application
      1. Integration tests
      2. Application tests
    12. Servlet filters
    13. Audit logging and AOP
    14. Dynamic proxy-based AOP
    15. Summary
  14. Extending Our E-Commerce Application
    1. The MyBusiness ordering
    2. Setting up the project
    3. Order controller and DTOs
    4. Consistency checker
    5. Annotations
      1. Annotation retention
      2. Annotation target
      3. Annotation parameters
      4. Repeatable annotations
      5. Annotation inheritance
      6. @Documented annotation
      7. JDK annotations
    6. Using reflection
      1. Getting annotations
      2. Invoking methods
      3. Setting fields
    7. Functional programming in Java
      1. Lambda
      2. Streams
      3. Functional interfaces
      4. Method references
    8. Scripting in Java
    9. Summary
  15. Building an Accounting Application Using Reactive Programming
    1. Reactive... what?
    2. Reactive programming in a nutshell
    3. Reactive systems
      1. Responsive
      2. Resilient
      3. Elastic
      4. Message-driven
      5. Back-pressure
    4. Reactive streams
    5. Reactive programming in Java
      1. Implementing the inventory
    6. Summary
  16. Finalizing Java Knowledge to a Professional Level
    1. Java deep technologies
      1. Java agent
      2. Polyglot programming
        1. Polyglot configuration
        2. Polyglot scripting
        3. Business DSL
        4. Problems with polyglot
      3. Annotation processing
    2. Programming in the enterprise
      1. Static code analysis
      2. Source code version-control
      3. Software versioning
      4. Code review
      5. Knowledge base
      6. Issue tracking
      7. Testing
        1. Types of tests
        2. Test automation
        3. Black box versus white box
      8. Selecting libraries
        1. Fit for the purpose
        2. License
        3. Documentation
        4. An alive project
        5. Maturity
        6. Number of users
        7. The "I like it" factor
      9. Continuous integration and deployment
      10. Release management
      11. The code repository
      12. Walking up the ladder
    3. Summary
  17. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think