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 now! 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
Conferences
Free Learning
Arrow right icon
Java Coding Problems
Java Coding Problems

Java Coding Problems: Improve your Java Programming skills by solving real-world coding challenges

eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
Table of content icon View table of contents Preview book icon Preview Book

Java Coding Problems

Objects, Immutability, and Switch Expressions

This chapter includes 18 problems that involve objects, immutability, and switch expressions. The chapter starts with several problems about dealing with null references. It continues with problems regarding checking indexes, equals() and hashCode(), and immutability (for example, writing immutable classes and passing/returning mutable objects from immutable classes). The last part of the chapter deals with cloning objects and the JDK 12 switch expressions. By the end of this chapter, you will have a fundamental knowledge of objects and immutability. Moreover, you will know how to deal with the new switch expressions. These are valuable and non-optional bits of knowledge in any Java developer's arsenal.

Problems

Use the following problems to test your object, immutability, and switch expression programming prowess. I strongly encourage you to give each problem a try before you turn to the solutions and download the example programs:

  1. Checking null references in functional style and imperative code: Write a program that performs the null checks on the given references in a functional style and imperative code.
  2. Checking null references and throwing a customized NullPointerException error: Write a program that performs the null checks on the given references and throws NullPointerException with custom messages.
  3. Checking null references and throwing the specified exception (example, IllegalArgumentException): Write a program that performs the null checks on the given references and throws the specified exception.
  1. Checking null references and returning non-null default references...

Solutions

The following sections describe solutions to each of the preceding problems. Remember that there usually isn't a single correct way to solve a particular problem. Also, remember that the explanations shown here include only the most interesting and important details needed to solve the problems. Download the example solutions to see additional details and to experiment with the programs at https://github.com/PacktPublishing/Java-Coding-Problems.

40. Checking null references in functional style and imperative code

Independent of functional style or imperative code, checking null references is a common and recommended technique used for mitigating the occurrence of famous NullPointerException exception. This kind...

Summary

That's all folks! This chapter has introduced you to several problems involving objects, immutability, and the switch expressions. While the problems covering objects and immutability represent fundamental concepts of programming, the problems covering the switch expressions were dedicated to introducing the new JDK 12 features addressing this topic.

Download the applications from this chapter to see the results and to see additional details.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Solve Java programming challenges and get interview-ready by using the power of modern Java 11
  • Test your Java skills using language features, algorithms, data structures, and design patterns
  • Explore areas such as web development, mobile development, and GUI programming

Description

The super-fast evolution of the JDK between versions 8 and 12 has increased the learning curve of modern Java, therefore has increased the time needed for placing developers in the Plateau of Productivity. Its new features and concepts can be adopted to solve a variety of modern-day problems. This book enables you to adopt an objective approach to common problems by explaining the correct practices and decisions with respect to complexity, performance, readability, and more. Java Coding Problems will help you complete your daily tasks and meet deadlines. You can count on the 300+ applications containing 1,000+ examples in this book to cover the common and fundamental areas of interest: strings, numbers, arrays, collections, data structures, date and time, immutability, type inference, Optional, Java I/O, Java Reflection, functional programming, concurrency and the HTTP Client API. Put your skills on steroids with problems that have been carefully crafted to highlight and cover the core knowledge that is accessed in daily work. In other words (no matter if your task is easy, medium or complex) having this knowledge under your tool belt is a must, not an option. By the end of this book, you will have gained a strong understanding of Java concepts and have the confidence to develop and choose the right solutions to your problems.

Who is this book for?

If you are a Java developer who wants to level-up by solving real-world problems, then this book is for you. Working knowledge of Java is required to get the most out of this book.

What you will learn

  • Adopt the latest JDK 11 and JDK 12 features in your applications
  • Solve cutting-edge problems relating to collections and data structures
  • Get to grips with functional-style programming using lambdas
  • Perform asynchronous communication and parallel data processing
  • Solve strings and number problems using the latest Java APIs
  • Become familiar with different aspects of object immutability in Java
  • Implement the correct practices and clean code techniques

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 20, 2019
Length: 816 pages
Edition : 1st
Language : English
ISBN-13 : 9781789800500
Category :
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning

Product Details

Publication date : Sep 20, 2019
Length: 816 pages
Edition : 1st
Language : English
ISBN-13 : 9781789800500
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 123.97
Java Coding Problems
€41.99
Hands-On Microservices with Spring Boot and Spring Cloud
€44.99
The Complete Coding Interview Guide in Java
€36.99
Total 123.97 Stars icon

Table of Contents

14 Chapters
Strings, Numbers, and Math Chevron down icon Chevron up icon
Objects, Immutability, and Switch Expressions Chevron down icon Chevron up icon
Working with Date and Time Chevron down icon Chevron up icon
Type Inference Chevron down icon Chevron up icon
Arrays, Collections, and Data Structures Chevron down icon Chevron up icon
Java I/O Paths, Files, Buffers, Scanning, and Formatting Chevron down icon Chevron up icon
Java Reflection Classes, Interfaces, Constructors, Methods, and Fields Chevron down icon Chevron up icon
Functional Style Programming - Fundamentals and Design Patterns Chevron down icon Chevron up icon
Functional Style Programming - a Deep Dive Chevron down icon Chevron up icon
Concurrency - Thread Pools, Callables, and Synchronizers Chevron down icon Chevron up icon
Concurrency - Deep Dive Chevron down icon Chevron up icon
Optional Chevron down icon Chevron up icon
The HTTP Client and WebSocket APIs Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Most Recent
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.7
(9 Ratings)
5 star 77.8%
4 star 11.1%
3 star 11.1%
2 star 0%
1 star 0%
Filter icon Filter
Most Recent

Filter reviews by




ALEXANDRE Oct 04, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The book is fantastic but of course, you need to know if it is the right level for you. I mean, you need the prerequisite knowledge to read and understand it.I really recommend those who are willing to be prepared for technical interview questions coded by Java 8+.
Amazon Verified review Amazon
ALEXANDRE Aug 28, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
O livro me ajudou a passar em um desafio de código de nível intermediário para difícil.Muitos exemplos bons e inclusive já li e reli algumas vezes. Também comprei outro livro do mesmo autor pois também vale muito a pena para quem quer estar afiado com relação a linguagem e a forma de pensar em resolver problemas de diversas formas.
Amazon Verified review Amazon
Ivan de Oliveira Costa Junior Dec 13, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The author brings to the table a lot of content that is deeper than the other book "Complete Coding Interview" so you buy this if you need to learn things in a more profound way. I've found it very easy to read and useful as well, however isn't required for ones wishing to be prepared for an interview.
Amazon Verified review Amazon
Richard Monseglio Mar 17, 2021
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
So the book itself is great... however, yet again it was delivered 3 days late and the package looked like it was ran over by the semi, overall I am not impressed with the shipping side of Amazon.
Amazon Verified review Amazon
Prasanti Nov 03, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Excellent book for those looking for coding techniques with latest java version.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.