Java Programming Exercises. Volume One: Language Fundamentals and Core Concepts

Java Programming Exercises. Volume One: Language Fundamentals and Core Concepts

Java Programming Exercises. Volume One: Language Fundamentals and Core Concepts
Автор: Ullenboom Christian
Дата выхода: 2025
Издательство: CRC Press is an imprint of Taylor & Francis Group, LLC
Количество страниц: 321
Размер файла: 3.1 MB
Тип файла: PDF
Добавил: codelibs
 Проверить на вирусы

Cover....1

Half Title....2

Title Page....4

Copyright Page....5

Table of Contents....6

About the Author....16

Introduction....18

Previous Knowledge and Target Audience....18

Working with This Book....19

The Suggested Solutions....19

Use of This Book....20

Required Software....20

Used Java Version in the Book....21

JVM....21

Development Environment....21

Conventions....21

Helping Captain CiaoCiao and Bonny Brain....22

1 Introduction to the Java Ecosystem....23

Bytecode and JVM....23

Porting Java Programs....23

Tools for Java Developers....24

Get to Know Error Messages of the IDE....24

Suggested Solutions....25

Porting Java Programs....25

Get to Know Error Messages of the IDE....25

2 Imperative Programming....26

Screen Output....26

Learn about the SVG Specification....26

Write an SVG Circle on the Console....27

Variables and Data Types....28

Access Variables and Output Their Assignments....29

Quiz: Value Ranges....29

Quiz: Does This Add Up?....29

Generate Random Circles....30

Quiz: Dazed and Confused....31

Process User Input....31

Expressions, Operands, and Operators....31

Quiz: Check In-Between....31

Check If Loot Can Be Shared Fairly....32

Do Two Numbers Share the Same Digit?....32

Convert Currency Amount to Coins....32

One Bottle of Rum, Ten Bottles of Rum....33

Quiz: The Zero Effect....34

Control Flow....35

Payday....35

Quiz: Wrong Branching....35

Convert Liters....36

Create SVG Circles with Random Colors....36

Quiz: To Which Block Does the Else Belong?....37

Quiz: Recognize Negative Days and Hours....37

Evaluate Input Strings for Approval....37

Rewrite Switch Statement to Switch Expression....38

Loops....38

Create Rotated SVG Rectangles....38

Create SVG-Pearl-Chain....39

Sum Numbers from the Command Line....40

Go through a Mathematical Phenomenon....41

Quiz: How Many Stars?....41

Calculate Products for Faculties....42

Determine If a Number Is Formed by Factorial....42

Find the Smallest and Largest Digit of a Number....43

Quiz: Not Like This from 1 to 100....44

A Flag in the Wind through Nested Loops....45

Output Simple Chessboard....45

It’s Christmastime: Displaying Trees with Ornaments....46

Draw Fishy Stitching Motifs....47

Trying Instead of Thinking....48

Get the Number of Digits of a Number....49

Methods....50

Drawing Hearts....50

Implement Overloaded Line Methods....51

Standing Straight....51

Create a Multiplication Table....52

Cistercian Numerals Script....53

Quiz: What Does Ding-Dong Do? (Recursion)....54

Quiz: Repdigit (Recursion)....54

Calculate Collatz Sequence (Recursion)....55

Ancient Egyptian Multiplication (Recursion)....55

Suggested Solutions....57

Write an SVG Circle on the Console....57

Access Variables and Output Their Assignments....58

Quiz: Value Ranges....59

Quiz: Does This Add Up?....60

Generate Random Circles....60

Quiz: Dazed and Confused....61

Process User Input....61

Quiz: Check In-Between....61

Check If Loot Can Be Shared Fairly....62

Do Two Numbers Share the Same Digit?....62

Convert Currency Amount to Coins....63

One Bottle of Rum, Ten Bottles of Rum....64

Quiz: The Zero Effect....64

Payday....64

Quiz: Wrong Branching....65

Convert Liters....65

Create SVG Circles with Random Colors....66

Quiz: To Which Block Does the Else Belong?....67

Quiz: Recognize Negative Days and Hours....67

Evaluate Input Strings for Approval....68

Rewrite Switch Statement to Switch Expression....69

Create Rotated SVG Rectangles....69

Create SVG-Pearl-Chain....70

Sum Numbers from the Command Line....70

Go through a Mathematical Phenomenon....71

Quiz: How Many Stars?....72

Calculate Products for Faculties....72

Determine If a Number Is Formed by Factorial....74

Find the Smallest and Largest Digit of a Number....75

Quiz: Not Like This from 1 to 100....75

A Flag in the Wind through Nested Loops....76

Output Simple Chessboard....77

It’s Christmastime: Displaying Trees with Ornaments....77

Draw Fishy Stitching Motifs....78

Trying Instead of Thinking....79

Get the Number of Digits of a Number....80

Drawing Hearts....82

Implement Overloaded Line Methods....82

Standing Straight....83

Create a Multiplication Table....85

Cistercian Numerals Script....86

Quiz: What Does Ding-Dong Do? (Recursion)....89

Quiz: Repdigit (Recursion)....89

Calculate Collatz Sequence (Recursion)....90

Ancient Egyptian Multiplication (Recursion)....92

3 Classes, Objects, and Packages....95

Creating Objects....95

Draw Polygons....95

Working with References....97

Quiz: The Short Life of Points....97

Build Triangles....97

Quiz: == vs. equals(…)....98

Quiz: Protect against NullPointerException....98

Suggested Solutions....99

Draw Polygons....99

Quiz: The Short Life of Points....100

Build Triangles....100

Quiz: == vs. equals(…)....101

Quiz: Protect against NullPointerException....101

Note....102

4 Arrays....103

Everything Has a Type....103

Quiz: Array Types....103

One-Dimensional Arrays....104

Loop Arrays and Output Wind Speed, Wind Direction....104

Detect Continuous Revenue Growth....105

Array of Points....105

Search Consecutive Strings and Determine If Salty Snook Is Coming....106

Reverse an Array....106

Find the Nearest Cinema....107

Raid the Candy Store and Share Fairly....107

Enhanced for Loop....108

Numbers Well Shuffled....109

Draw Mountains....110

Two- and Multidimensional Arrays....111

Check Mini-Sudoku for Valid Solution....111

Enlarge Image....112

Variable Argument Lists....113

Create SVG Polygons with a Variable Number of Coordinates....113

Check for Approval....114

Help, Tetraphobia! Put All Fours Last....114

The Utility Class Arrays....115

Quiz: Copy Arrays....115

Quiz: Compare Arrays....115

Suggested Solutions....116

Quiz: Array Types....116

Loop Arrays and Output Wind Speed, Wind Direction....116

Reverse an Array....117

Array of Points....118

Search Consecutive Strings and Determine if Salty Snook is Coming....119

Reverse an Array....120

Find the Nearest Cinema....121

Raid the Candy Store and Share Fairly....122

Draw Mountains....123

Check Mini-Sudoku for Valid Solution....124

Enlarge Image....126

Create SVG Polygons with Variable Number of Coordinates....126

Check for Approval....127

Help, Tetraphobia! Put All Fours Last....128

Quiz: Copy Arrays....129

Quiz: Compare Arrays....129

5 Character and String Processing....131

The String Class and Its Members....131

Quiz: Is String a Built-In Keyword?....131

Building HTML Elements with Simple Concatenation....131

Check Safe Transmission by Doubling Characters....132

Swap Y and Z....133

Give Defiant Answers....134

Quiz: String Comparisons with == and Equals(…)....134

Quiz: Is Equals(…) Symmetric?....135

Test Strings for Palindrome Property....135

Check if Captain CiaoCiao is in the Middle....136

Find the Shortest Name in the Array....137

Count String Occurrences....137

Determine the Larger Crew Size....138

Build Diamonds....139

Check for a Good Password....140

Bake Peanut Butter Cookies....140

Calculate Sum of Digits....141

Decolumnize Texts....142

Draw a Meadow with Favorite Flowers....143

Detect Repetitions....145

Constrain Line Boundaries and Wrap Lines....145

Quiz: How Many String Objects?....146

Test If the Fruit Is Wrapped in Chocolate....146

From Top to Bottom, from Left to Right....147

Dynamic Strings with StringBuilder....148

Fill Strings....148

Practicing the Alphabet with a Parrot....149

Quiz: Lightly Attached....150

Convert Number to Textual Unary Encoding....150

Lose Weight by Moving Digits....151

Remove Vowels....152

Don’t Shoot the Messenger....153

Compress Repeated Spaces....154

Insert and Remove Crackles and Pops....154

Split CamelCase Strings....155

Underline Words....155

Implement Caesar Encryption....155

Suggested Solutions....157

Quiz: Is String a Built-In Keyword?....157

Building HTML Elements with Simple Concatenation....157

Check Safe Transmission by Doubling Characters....157

Swap Y and Z....158

Give Defiant Answers....160

Quiz: String Comparisons with == and Equals(…)....160

Quiz: Is Equals(…) Symmetric?....160

Test Strings for Palindrome Property....161

Check if Captain CiaoCiao is in the Middle....163

Find the Shortest Name in the Array....163

Count String Occurrences....164

Determine the Larger Crew Size....165

Build Diamonds....166

Check for a Good Password....168

Bake Peanut Butter Cookies....169

Calculate Sum of Digits....170

Decolumnize Texts....171

Draw a Meadow with Favorite Flowers....173

Detect Repetitions....175

Constrain Line Boundaries and Wrap Lines....176

Quiz: How Many String Objects?....177

Test if the Fruit is Wrapped in Chocolate....177

From Top to Bottom, from Left to Right....178

Fill Strings....179

Practicing the Alphabet with a Parrot....180

Quiz: Lightly Attached....181

Convert Number to Textual Unary Encoding....182

Lose Weight by Moving Digits....183

Remove Vowels....184

Don’t Shoot the Messenger....186

Compress Repeated Spaces....187

Insert and Remove Crackles and Pops....188

Split CamelCase Strings....189

Underline Words....190

Implement Caesar Encryption....191

6 Writing Your Own Classes....193

Class Declaration and Object Properties....194

Declare Radio with Instance Variables and a Main Program....194

Implementing Methods of a Radio....194

Private Parts: Make Instance Variables Private....195

Create Setters and Getters....195

Static Variables Methods....195

Convert Station Names to Frequencies....195

Write Log Output with a Tracer Class....196

Quiz: Nothing Stolen....197

Simple Enumerations....198

Give Radio an AM–FM Modulation....198

Set Valid Start and End Frequency for Modulation....198

Constructors....198

Writing Radio Constructors....199

Implement Copy Constructor....199

Realize Factory Methods....199

Associations....200

Connect Monitor Tube with TV....200

Quiz: Association, Composition, and Aggregation....201

Add Radios with a 1:n Association to the Ship....201

Inheritance....202

Introduce Abstraction into Electrical Devices via Inheritance....202

Quiz: Three, Two, and One....202

Quiz: Private and Protected Constructor....203

Determine the Number of Switched on Electrical Devices....203

Ship Should Hold Any Electronic Device....203

Take Working Radios on the Ship....204

Solve Equivalence Test with Pattern Variable....204

Fire Alarm Does Not Go Off: Overriding Methods....205

Calling the Methods of the Superclass....205

Polymorphism and Dynamic Binding....206

Holiday! Switch Off All Devices....206

The Big Move....207

Quiz: Bumbo Is a Great Drink....208

Quiz: Vodka with Taste....209

Quiz: Rum-Paradise....209

Abstract Classes and Abstract Methods....209

Quiz: Consumer Devices as an Abstract Superclass?....210

TimerTask as an Example for an Abstract Class....210

Suggested Solutions....211

Declare Radio with Instance Variables and a Main Program....211

Implementing Methods of a Radio....212

Private Parts: Make Instance Variables Private....213

Create Setters and Getters....214

Convert Station Names to Frequencies....215

Write Log Output with a Tracer Class....215

Quiz: Nothing Stolen....216

Give Radio an AM–FM Modulation....216

Set Valid Start and End Frequency for Modulation....217

Writing Radio Constructors....218

Implement Copy Constructor....219

Realize Factory Methods....219

Connect Monitor Tube with TV....221

Quiz: Association, Composition, and Aggregation....222

Add Radios with a 1:n Association to the Ship....222

Introduce Abstraction into Electrical Devices via Inheritance....223

Quiz: Three, Two, and One....224

Quiz: Private and Protected Constructor....225

Determine Number of Switched on Electrical Devices....225

Ship Should Hold Any Electronic Device....226

Take Working Radios on the Ship....226

Solve Equivalence Test with Pattern Variable....227

Fire Alarm Does Not Go Off: Overriding Methods....227

Calling the Methods of the Superclass....228

Holiday! Switch Off All Devices....229

The Big Move....229

Quiz: Bumbo Is a Great Drink....229

Quiz: Vodka with Taste....230

Quiz: Rum-Paradise....230

Quiz: Consumer Devices as an Abstract Superclass?....231

TimerTask as an Example for an Abstract Class....231

Note....232

7 Records, Interfaces, Enumerations, and Sealed Classes....233

Records....233

Quiz: Which Statements Are True for Records?....233

Develop Record for Complex Numbers....233

Quiz: Records with Static Variables....234

Record Patterns....234

Interfaces....235

Compare Consumption of Electrical Devices....235

Find Electronic Devices with the Highest Power Consumption....236

Use Comparator Interface for Sorting....237

Static and Default Methods in Interfaces....237

Delete Selected Elements with Predicate....237

Enumeration Types (enum)....238

Enumeration for Candy....238

Deliver Random Candies....239

Tagging Candy with Addictive Value....240

Interface Implementations via an enum....241

Quiz: Aviso and Brig....242

Suggested Solutions....242

Quiz: Which Statements Are True for Records?....242

Quiz: Records with Static Variables....243

Quiz: Records with Static Variables....244

Compare Consumption of Electrical Devices....245

Find Electronic Devices with the Highest Power Consumption....246

Use Comparator Interface for Sorting....247

Static and Default Methods in Interfaces....247

Delete Selected Elements with Predicate....248

Enumeration for Candy....249

Deliver Random Candies....250

Tagging Candy with Addictive Value....250

Interface Implementations via an enum....253

Quiz: Aviso and Brig....254

8 Nested Types....255

Declare Nested Types....255

Set AM–FM Modulation to Radio Type....255

Write Three Kinds of Watt-Comparator Implementations....256

Nested Types Quiz....256

Quiz: Pirate Could Have Waved....256

Quiz: Name in a Bottle....257

Quiz: Get Me Another Bottle of Rum....257

Suggested Solutions....258

Set AM–FM Modulation to Radio Type....258

Write Three Kinds of Watt-Comparator Implementations....259

Quiz: Pirate Could Have Waved....260

Quiz: Name in a Bottle....260

Quiz: Get Me another Bottle of Rum....260

9 Exception Handling....261

Catching Exceptions....261

Get the Longest Line of a File....261

Identify Exceptions, Laughing All the Time....262

Convert String Array to Int Array and Be Lenient on Nonnumbers....262

Quiz: And Finally....263

Quiz: A Lonely Try....263

Quiz: Well Caught....263

Quiz: Too Much of a Good Thing....264

Quiz: Try-Catch in Inheritance....264

Throwing Custom Exceptions....264

Quiz: Throw and Throws....264

Quiz: The Division Fails....265

Writing Your Own Exception Classes....265

Show Impossible Watt with Own Exception....265

Quiz: Potatoes or Other Vegetables....265

Try-with-Resources....266

Write Current Date to File....266

Read Notes and Write Them to a New ABC File....266

Quiz: Excluded....267

Suggested Solutions....268

Get the Longest Line of a File....268

Identify Exceptions, Laughing All the Time....269

Convert String Array to Int Array and Be Lenient on Nonnumbers....271

Quiz: And Finally....272

Quiz: A Lonely Try....272

Quiz: Well Caught....273

Quiz: Too Much of a Good Thing....273

Quiz: Try-Catch in Inheritance....274

Quiz: Throw and Throws....274

Quiz: The Division Fails....274

Show Impossible Watt with Own Exception....275

Quiz: Potatoes or Other Vegetables....277

Write Current Date to File....277

Read Notes and Write Them to a New ABC File....278

Quiz: Excluded....279

10 Lambda Expressions and Functional Programming....280

Lambda Expressions....281

Quiz: Recognize Valid Functional Interfaces....281

Quiz: From Interface Implementation to Lambda Expression....281

Write Lambda Expressions for Functional Interfaces....282

Quiz: Write Lambda Expressions Like This?....283

Developing Lambda Expressions....283

Quiz: Contents of the Package java.util.function....283

Quiz: Know Functional Interfaces for Mappings....283

Method and Constructor References....285

Rewriting Lambda Expressions....285

Selected Functional Interfaces....285

Delete Entries, Remove Comments, Convert to CSV....285

Suggested Solutions....286

Quiz: Recognize Valid Functional Interfaces....286

Quiz: From Interface Implementation to Lambda Expression....287

Write Lambda Expressions for Functional Interfaces....288

Quiz: Write Lambda Expressions Like This?....288

Developing Lambda Expressions....288

Quiz: Contents of the Package java.util.function....288

Quiz: Know Functional Interfaces for Mappings....289

Rewriting Lambda Expressions....290

Delete Entries, Remove Comments, and Convert to CSV....290

Note....291

11 Special Types from the Java Class Library....292

Absolute Superclass java.lang.Object....292

Generate equals(Object) and hashCode()....293

Existing equals(Object) Implementations....293

Interfaces Comparator and Comparable....294

Quiz: Natural Order Or Not?....294

Handle Superheroes....294

Compare Superheroes....296

Concatenate Hero Comparators....297

Using a Key Extractor to Easily Create a Comparator....297

Sort Points by Distance to Center....299

Find Stores Nearby....300

Autoboxing....300

Quiz: Handling Null Reference in Unboxing....300

Quiz: Unboxing Surprise....301

Suggested Solutions....301

Generate equals(Object) and hashCode()....301

Existing equals(Object) Implementations....304

Quiz: Natural Order Or Not?....306

Compare Superheroes....306

Concatenate Hero Comparators....307

Using a Key Extractor to Easily Create a Comparator....308

Sort Points by Distance to Center....308

Find Stores Nearby....309

Quiz: Handling Null Reference in Unboxing....310

Quiz: Unboxing Surprise....311

Notes....311

Appendix A: Most Frequent Types and Methods in the Java Universe....312

A.1 Packages with the Most Common Types....312

A.2 100 Most Common Types....313

A.3 100 Most Common Methods....316

A.4 100 Most Common Methods Including Parameter List....319

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.


Похожее:

Список отзывов:

Нет отзывов к книге.