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
Arrow up icon
GO TO TOP
Java Coding Problems

You're reading from   Java Coding Problems Improve your Java Programming skills by solving real-world coding challenges

Arrow left icon
Product type Paperback
Published in Sep 2019
Publisher Packt
ISBN-13 9781789801415
Length 816 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Anghel Leonard Anghel Leonard
Author Profile Icon Anghel Leonard
Anghel Leonard
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Strings, Numbers, and Math FREE CHAPTER 2. Objects, Immutability, and Switch Expressions 3. Working with Date and Time 4. Type Inference 5. Arrays, Collections, and Data Structures 6. Java I/O Paths, Files, Buffers, Scanning, and Formatting 7. Java Reflection Classes, Interfaces, Constructors, Methods, and Fields 8. Functional Style Programming - Fundamentals and Design Patterns 9. Functional Style Programming - a Deep Dive 10. Concurrency - Thread Pools, Callables, and Synchronizers 11. Concurrency - Deep Dive 12. Optional 13. The HTTP Client and WebSocket APIs 14. Other Books You May Enjoy

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: Write a program that performs the null checks on the given reference, and if it is non-null, then return it; otherwise, return a non-null default reference.
  2. Checking the index in the range from 0 to length: Write a program that checks whether the given index is between 0 (inclusive) and the given length (exclusive). If the given index is out of the [0, given length] range, then throw IndexOutOfBoundsException.
  3. Checking the subrange in the range from 0 to length: Write a program that checks whether the given subrange [given start, given end] is within the bounds of the range from [0, given length]. If the given subrange is not in the [0, given length] range, then throw IndexOutOfBoundsException.
  4. equals() and hashCode(): Explain and exemplify how equals() and hashCode() methods work in Java.
  5. Immutable objects in a nutshell: Explain and exemplify what is an immutable object in Java.
  6. Immutable string: Explain why the String class is immutable.
  7. Writing an immutable class: Write a program that represents an immutable class.
  8. Passing/returning mutable objects to/from an immutable class: Write a program that passes and returns a mutable object to/from an immutable class.
  9. Writing an immutable class via the Builder pattern: Write a program that represents an implementation of the Builder pattern in an immutable class.
  10. Avoiding bad data in immutable objects: Write a program that prevents bad data in immutable objects.
  11. Cloning objects: Write a program that exemplifies shallow and deep cloning techniques.
  12. Overriding toString(): Explain and exemplify practices for overriding toString().
  13. switch expressions: Provide a brief overview of the switch expressions in JDK 12.
  14. Multiple case labels: Write a snippet of code for exemplifying the JDK 12 switch with multiple case labels.
  15. Statement blocks: Write a snippet of code for exemplifying the JDK 12 switch with case labels that point to a curly-braced block.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime