Skip to main content

Java SE 7 Programming Essentials

Java SE 7 Programming Essentials

Michael Ernest

ISBN: 978-1-118-35910-5

Nov 2012

336 pages

Select type: Paperback

Product not available for purchase


Learn core programming concepts and technologies on the leading software development language

This full-color book covers fundamental Java programming concepts and skills for those new to software development and programming. Taking a straightforward and direct approach,Java SE 7 Programming Essentials provides a solid foundational knowledge of programming topics. Each chapter begins with a list of topic areas, and author Michael Ernest provides clear and concise discussion of these core areas. The chapters contain review questions and suggested labs, so the reader can measure their understanding of the chapter topics.

  • Covers topics such as working with Java data types, using operators and decision constructs, creating and using arrays, and much more
  • Includes additional learning tutorials and tools
  • Puts the focus on Oracle's new Oracle Certified Associate (OCA): Java SE 7 Programmer (1Z0-803) exam

This must-have resource offers new programmers a solid understanding of the Java SE 7 programming language.

Related Resources

Introduction xvii

Chapter 1 Introducing the Basics of Java 1

Understanding Java Class Structure 1

Distinguishing between Classes and Objects 5

Understanding Other Elements of Java Class Structure 6

Writing a main() Method 7

Importing Other Java Classes 10

Understanding Package Declarations 13

Understanding Variable Scope in Java Code 14

Understanding Program State 15

The Essentials and Beyond 16

Chapter 2 Applying Data Types in Java Programming 19

Creating, Using, and Destroying Objects 19

Distinguishing between Object References and Primitives 23

Declaring and Initializing Variables 26

Default Initialization of Variables 30

Reading and Writing Object Fields 32

Using the StringBuilder Class and Its Methods 34

Creating and Manipulating Strings 39

The Essentials and Beyond 42

Chapter 3 Using Java Operators and Conditional Logic 45

Using Java Operators 45

Understanding Operator Types and Properties 48

Precedence and Associativity 50

Using Separators 52

Using Postfix/Prefix Operators 52

Using Unary Operators 53

Using Multiplicative and Additive Operators 55

Using Shift Operators 56

Using Relational Operators 56

Using Equality Operators 57

Using Bitwise and Logical Operators 58

Using Conditional Operators 59

Using Assignment Operators 61

Using Parentheses to Control Operators 62

Understanding Object Equality 64

Using if and if/else Statements 67

Using a switch Statement 69

The Essentials and Beyond 71

Chapter 4 Using Java Arrays 75

Understanding Java Arrays 75

Using a One-Dimensional Array 78

Declaring an Array 78

Instantiating an Array 79

Populating an Array with a Loop 80

Populating an Array without a Loop 81

Using an Array 82

Using a String Object as a Character Array 84

Using System.arraycopy() 85

Using Arrays of Other Types 86

Understanding the Arrays Class 87

Using a Multi-Dimensional Array 87

Declaring a Multi-Dimensional Array 88

Instantiating and Using a Multi-Dimensional Array 88

Using an ArrayList Object 90

Understanding ArrayList Support for Array Features 90

Instantiating an ArrayList Class 92

Consuming the ArrayList API 93

The Essentials and Beyond 94

Chapter 5 Using Loops in Java Code 97

Applying while Loops 97

Choosing a Useful while Test 98

Watching Out for Infinite Loops 100

Applying do/while Loops 102

Applying for and For-Each Loops 103

Using for Loops 104

Nesting Loops 106

Avoiding Useless and Infinite Loops 108

Using For-Each Loops 109

Using the For-Each Loop with a Collections Type 110

Comparing Loop Constructs 112

Using continue and break Statements 112

Using the continue Statement 113

Using the break Statement 114

Using Labeled Statements 115

The Essentials and Beyond 116

Chapter 6 Encapsulating Data and Exposing Methods in Java 119

Encapsulating Data 119

Understanding Data Hiding 120

Hiding the Data 124

Understanding Encapsulation 125

Understanding Mutability 127

Using Final Classes 128

Exposing Data through Methods 129

Understanding the Bean Model 129

Distinguishing Methods from Data in a Class 131

Validating Incoming Parameters 131

Restricting Range 132

Inducing Side Effects 133

Choosing Methods to Make Public 134

Applying Access Modifiers 135

Working with Packaged Classes 137

Using Access Modifiers with Package‑Aware Classes 139

Using Default Access with Class Members 140

Understanding the protected Access Modifier 142

Abstracting Data 143

The Essentials and Beyond 144

Chapter 7 Using Java Methods to Communicate 147

Designing Methods 147

Understanding Method Modifiers 148

Choosing Modifiers 149

Choosing Return Types 151

Choosing Parameters 154

Naming Methods 156

Overloading Methods 158

Understanding Method Signatures 159

Supporting Multiple Parameter Lists 160

Allowing for a Variable Number of Parameters 161

Chaining Overloaded Methods 163

Declaring Methods and Fields static 164

Passing Data among Methods 167

Understanding Primitive Parameters 167

Understanding Reference Parameters 168

Returning Object References 169

Understanding Pass-by-Value 170

The Essentials and Beyond 170

Chapter 8 Using Java Constructors 173

Using the Default Constructor 173

Defining Alternate Constructors 176

Hiding (Replacing) the Default Constructor 177

Limiting Constructor Access 178

Using Packages to Encapsulate Constructors 180

Writing a Proxy Construction Class 185

Requiring Parameters 188

Adding Parameters to Constructors 188

Overriding Default Initialization 188

Disallowing Default Construction 189

Using Other Objects for Initialization 191

Overloading Constructors 192

Chaining Overloaded Constructors 193

Coupling Objects with Constructors 196

Creating a Singleton Object 198

The Essentials and Beyond 199

Chapter 9 Inheriting Code and Data in Java 203

Extending a Class 203

Understanding What Inheritance Provides 204

Extending the Parent Class 206

Removing the final Keyword 206

Observing the Equality Contract 207

Observing Java's Single Inheritance Rule 208

Understanding How Inheritance Works 209

Using the super Keyword 212

Passing Parameters to a Parent Constructor 212

Choosing a Parent Constructor 213

Overriding a Method 214

Using the @Override Annotation 216

Modifying or Replacing an Inherited Method 217

Prohibiting Method Overrides 219

Casting Objects 220

Implementing Polymorphic Behavior 223

Organizing Objects by Type 223

Using Method Names to Effect Polymorphism 224

The Essentials and Beyond 227

Chapter 10 Understanding Java Interfaces and Abstract Classes 231

Understanding Abstract Types 231

Using Abstract Classes 235

Understanding the Template Method Pattern 239

Applying the Template Method Pattern 240

Enforcing a Pattern 241

Using Interfaces 242

Planning for Variation 247

Reviewing Polymorphism 248

Using the enum Type 249

Distinguishing between Abstract and Concrete References 254

The Essentials and Beyond 255

Chapter 11 Throwing and Catching Exceptions in Java 259

Understanding the Role Exceptions Play 259

Understanding Exceptions 260

Handling Exceptions 263

Using a try-catch Block 264

Catching an Exception 265

Throwing an Exception 266

Using Multiple Catch Blocks 267

Using a finally Block 269

Handling Unchecked Exceptions 274

Understanding Exception Types 276

Understanding Errors 276

Understanding Unchecked Exceptions 277

Understanding Checked Exceptions 279

Calling Methods That Throw Exceptions 282

Catching a Checked Exception 282

Declaring a Checked Exception 284

Recognizing Common Exception Types 285

The Essentials and Beyond 286

Appendix A Answers to Review Questions 289

Appendix B OCA Certif ication Program 301

Certification-Objectives Map 302

Index 305

Appendix C: Answers to Additional Exercises