My Cart (0)

Customer Service 1-800-221-5528

Murach’s Java Programming

by Joel Murach
23 chapters, 802 pages, 340 illustrations
Published November 2011
ISBN 978-1-890774-65-3
eBook: $52.50

Now available: NEW 5th edition covering through Java 9

This is the 4th Edition of our best-selling core Java book. Since 2001, it has been used by thousands of beginning and experienced programmers to master the core language skills that are needed to create console, web, and mobile applications. Now, to make training even easier, this book shows you how to develop Java programs using NetBeans, a popular IDE that will boost your productivity at every step.

College Instructors

Go to our instructor’s site to learn more about this book and its instructor’s materials.

 

I love your Java book. It cuts right to the essential information, providing the perfect balance between too many details and too little information. I bought another well-known Java book, but I spent several hours trying to learn what I learned from your book in about 45 minutes."

Posted at an online bookseller

  • About this Book
  • Table of Contents
  • FREE Downloads
  • Book FAQs
  • Corrections
  • Reviews

What to expect from this book

Get a quick start

You’ll be writing your first complete Java applications at the end of chapter 2!

Build realistic applications

By the end of chapter 5, you’ll know how to use Java classes, objects, and methods to write bulletproof applications that use custom methods to validate user input. That gets you off to a fast start in Java whether you’re a beginner or have years of programming experience.

Work more efficiently by using NetBeans

Starting from chapter 1, you’ll take advantage of the time-saving features that an IDE provides as you use NetBeans to create, compile, run, test, and debug Java applications.

Object-oriented programming made clear

Section 2, on object-oriented programming, cuts through the mystery of inheritance, polymorphism, and the factory pattern so you can learn how to create and use sophisticated business and data access classes. At that point, you’ll know how to develop real-world, object-oriented, business applications.

Expand your core Java skills

In section 3, you’ll learn more of the core Java features that you’ll use all the time, like how to work with arrays, dates, strings, exceptions, enhanced for loops, try-with-resources, and more! Because each chapter in this section is independent of the others, you can add these skills to your resume whenever you need them.

Create user-friendly GUIs

Section 4 shows you how to use the popular Swing GUI Builder that comes with NetBeans to develop GUI applications. Here, you’ll learn how to handle events, validate data, and populate objects to create applications that aren’t just useful, but easy-to-use as well.

Work with files and databases like a pro

To complete your OOP training, section 5 shows you how to write data access classes that store the data for objects in a file or database. Here, then, you’ll learn how to: work with text, binary, and XML files; embed an Apache Derby database in an application; and use JDBC to work with any database.

Take your skills to a new level

Section 6 shows you how to work with threads and how to deploy your finished applications using executable JAR files or Java Web Start.

Who this book is for

This book is for anyone who wants to learn the core features of the Java language. It works:

  • if you have an aptitude for problem-solving but no programming experience at all
  • if you have programming experience with another language
  • if you already know an older version of Java and you want to update your skills
  • if you’ve already read 3 or 4 other Java books and still don’t know how to develop a real-world application

What’s new in this edition

The big news in this edition is that it now teaches Java programming using the NetBeans IDE. Today, no professional programmer should miss out on the time-saving features of an IDE, and NetBeans is a popular choice that's free, easy-to-use, and powerful. And because NetBeans works on the Windows, Mac, and Unix/Linux operating systems, this book is less Windows-centric than previous editions have been.

There are also new chapters on debugging and deployment, and the GUI section now features the use of the NetBeans Swing GUI Builder. In terms of the Java language itself, there aren't a lot of significant changes in Java SE 7, but new features have been added whenever they’re useful, and of course, the technical content has been updated throughout.

What software you need

This book teaches you how to develop Java applications using:

  • the Java Platform Standard Edition (Java SE)
  • NetBeans, a popular, easy-to-use IDE

Although this book specifically covers Java SE 7, almost all of the core features will work with all previous releases of Java...and will continue to work with future releases as well.

You can download Java and its documentation for free from the Oracle website. Likewise, you can download NetBeans for free from the NetBeans website. To make this easier for you, Appendix A (for Windows) and Appendix B (for the Mac) explain the procedures you will use to download and install both pieces of software.

Companion books for web and Android developers

Since web programming is one of the primary uses of Java, we also offer a book on web programming called Murach’s Java Servlets and JSP (3rd Edition). It shows you how to use Java servlets and JavaServer Pages as you develop professional web applications. As you read that book, you’ll discover that Java web programming requires most of the skills that are presented in chapters 1-14 (sections 1-3) of our Java Programming book.

Another primary use of Java today is developing Android apps for tablets and smart phones. So we also offer a great first book for on that subject, Murach’s Android Programming. Again, like our Servlets and JSP book, this book assumes that you have the skills that are presented in chapters 1-14 of our Java Programming book.

What people say about this book

“Finally there is a Java book for serious programmers doing real life business applications.”
- Donna Dean, IS Trainer, Chicago, Illinois

“I bought your Java book a week ago and I am already writing useful programs, not ‘toys!’”
- Richard Cooper, Programmer

“If I’d seen this book first, I would not have wasted money (and time) on 6 other books! This one is highly organized, clear, and very effective as a learning tool.”
- Posted at Amazon.com

"I bought this book to brush up on my Java programming skills in preparation for doing some Android programming. This book brought me up to speed really fast, and it even has a chapter on XML, which is used in Android."
- Posted at an online bookseller

"I’m reading the part of the book that discusses the nio package. The information is so clear, it beats what I read in the Java tutorials on the Oracle web site. Once again, a Murach book adds clarity that’s hard to find elsewhere."
- Steve, Programmer, Denver, Colorado

"Ever have someone come in your office with a Java question, and you reach for a certain book that you know has the answer in it? When needing assistance with the core features of Java, Murach’s Java Programming is the resource that supplies these answers, both quickly and completely. If this book isn’t on your bookshelf, you should get it there."
- Robert Liguori, Tech Center Java User Group

“Terrific - Fantastic - Superlative! WELL worth several times the purchase price.”
- Posted at an online website

Murach's Java is now my go-to source for reference and learning and brushing up, well above and beyond the other books in my collection.”
- Jeff Salter, Sacramento Java Users Group (SacJUG)

 “The style is clean, very user friendly, and simple. The narrative is totally accurate and focuses on important issues; it is not dumbed down. This book is a winner!”
- Dr. Richard Wiener, Editor-in-Chief, Journal of Object Technology

View the table of contents for this book in a PDF: Table of Contents (PDF)

Click on any chapter title to display or hide its content.

Section 1 Essential Java skills

Chapter 1 How to get started with Java and NetBeans

Introduction to Java

Toolkits and platforms

How Java compares to C++ and C#

Applications, applets, and servlets

The code for the console version of the Future Value application

How Java compiles and interprets code

Introduction to Java IDEs

How to use NetBeans to work with existing projects

Introduction to Java projects and the NetBeans IDE

How to open, close, and delete a project

How to compile and run a project

How to use the Output window with a console application

How to work with two or more projects

How to use NetBeans to develop new projects

How to create a new project

How to set the Java version for a project

How to work with Java source code and files

How to use the code completion feature

How to detect and correct syntax errors

Chapter 2 Introduction to Java programming

Basic coding skills

How to code statements

How to code comments

How to create identifiers

How to declare a class and a main method

How to work with numeric variables

How to declare and initialize variables

How to code assignment statements

How to code arithmetic expressions

How to work with string variables

How to create a String object

How to join and append strings

How to include special characters in strings

How to use Java classes, objects, and methods

How to create objects and call methods

How to import Java classes

How to use the API documentation to research Java classes

How to use the console for input and output

How to use the System.out object to print output to the console

How to use the Scanner class to read input from the console

Examples that get input from the console

How to code simple control statements

How to compare numeric variables

How to compare string variables

How to code if/else statements

How to code while statements

Two illustrative applications

The Invoice application

The Test Score application

How to test and debug an application

How to test an application

How to debug an application

Chapter 3 How to work with data

Basic skills for working with data

The eight primitive data types

How to declare and initialize variables

How to declare and initialize constants

How to code assignment statements and arithmetic expressions

How to use the shortcut assignment operators

How to work with the order of precedence

How to work with casting

How to use Java classes for working with data types

How to use the NumberFormat class

How to use the Math class

How to use the Integer and Double classes

The formatted Invoice application

The code for the application

A bug in the arithmetic

How to debug the application

How to use the BigDecimal class

The constructors and methods

How to use BigDecimal arithmetic

Chapter 4 How to code control statements

How to code Boolean expressions

How to compare primitive data types

How to compare strings

How to use the logical operators

How to code if/else and switch statements

How to code if/else statements

How to code switch statements

An enhanced version of the Invoice application

How to code loops

How to code while and do-while loops

How to code for loops

The Future Value application

How to code nested loops

How to code break and continue statements

How to code break statements

How to code continue statements

How to code and call static methods

How to code static methods

How to call static methods

The Future Value application with a static method

Chapter 5 How to validate input data

How to handle exceptions

How exceptions work

How to catch exceptions

The Future Value application with exception handling

How to validate data

How to prevent exceptions from being thrown

How to validate a single entry

How to use generic methods to validate an entry

The Future Value application with data validation

The console

The code

Chapter 6 How to test and debug an application

Basic skills for testing and debugging

Typical test phases

The three types of errors

Common Java errors

A simple way to trace code execution

How to use NetBeans to debug an application

How to set and remove breakpoints

How to step through code

How to inspect variables

How to inspect the stack trace

Section 2 Object-oriented programming with Java

Chapter 7 How to define and use classes

An introduction to classes

How classes can be used to structure an application

How encapsulation works

The relationship between a class and its objects

How to code a class that defines an object

How to use NetBeans to create a new class

The code for the Product class

How to code instance variables

How to code constructors

How to code methods

How to overload methods

How to use the this keyword

How to use NetBeans to work with classes

How to create and use an object

How to create an object

How to call the methods of an object

How primitive types and reference types are passed to a method

A ProductDB class that creates a Product object

A ProductApp class that uses a Product object

How to code and use static fields and methods

How to code static fields and methods

How to call static fields and methods

How to code a static initialization block

When to use static fields and methods

The Line Item application

The console

The class diagrams

The code for the classes

Chapter 8 How to work with inheritance

An introduction to inheritance

How inheritance works

How the Java API uses inheritance

How the Object class works

How to use inheritance in your applications

Basic skills for working with inheritance

How to create a superclass

How to create a subclass

How polymorphism works

The Product application

The console

The ProductApp class

The Product, Book, and Software classes

The ProductDB class

More skills for working with inheritance

How to get information about an object’s type

How to cast objects

How to compare objects

How to work with the  abstract and final keywords

How to work with the abstract keyword

How to work with the final keyword

Chapter 9 How to work with interfaces

An introduction to interfaces

A simple interface

Interfaces compared to abstract classes

Some interfaces of the Java API

How to work with interfaces

How to code an interface

How to implement an interface

How to inherit a class and implement an interface

How to use an interface as a parameter

How to use inheritance with interfaces

How to use NetBeans to work with interfaces

A Product Maintenance application that uses interfaces

The class diagram

The console

The DAOFactory class

The ProductTextFile class

The ProductMaintApp class

How to implement the Cloneable interface

A Product class that implements the Cloneable interface

A LineItem class that implements the Cloneable interface

Chapter 10 Other object-oriented programming skills

How to work with packages

An introduction to packages

How to use NetBeans to work with packages

How to use NetBeans to work with libraries

How to use javadoc to document a package

How to add javadoc comments to a class

How to use HTML and javadoc tags in javadoc comments

How to use NetBeans to generate documentation

How to view the documentation for a package

How to code classes that are closely related

How to code more than one class per file

An introduction to nested classes

How to work with enumerations

How to declare an enumeration

How to use an enumeration

How to enhance an enumeration

How to work with static imports

Section 3 More Java skills

Chapter 11 How to work with arrays

Basic skills for working with arrays

How to create an array

How to assign values to the elements of an array

How to use for loops with arrays

How to use enhanced for loops with arrays

More skills for working with arrays

The methods of the Arrays class

Code examples that work with the Arrays class

How to implement the Comparable interface

How to create a reference to an array

How to copy an array

How to work with two-dimensional arrays

How to work with rectangular arrays

How to work with jagged arrays

Chapter 12 How to work with collections and generics

An introduction to Java collections

A comparison of arrays and collections

An overview of the Java collection framework

An introduction to generics

How to use the ArrayList class

The ArrayList class

Code examples that work with array lists

An Invoice application that uses an array list

An overview of the Invoice application

The code for the Invoice class

The code for the InvoiceApp class

How to use the LinkedList class

The LinkedList class

Code examples that work with linked lists

A class that uses a linked list to implement a generic queue

An enhanced version of the Invoice application

An overview of the enhanced Invoice application

The code for the InvoiceApp class

How to work with maps

The HashMap and TreeMap classes

Code examples that work with hash maps and tree maps

How to work with legacy collections

An introduction to legacy collection classes

How to use an untyped collection

How to use wrapper classes with untyped collections

Chapter 13 How to work with dates and strings

How to work with dates and times

How to use the GregorianCalendar class to set dates and times

How to use the Calendar and GregorianCalendar fields and methods

How to use the Date class

How to use the DateFormat class to format dates and times

A DateUtils class that provides methods for handling dates

An Invoice class that includes an invoice date

How to work with the String class

Constructors of the String class

Code examples that create strings

Methods of the String class

Code examples that work with strings

How to work with the StringBuilder class

Constructors and methods of the StringBuilder class

Code examples that work with the StringBuilder class

Chapter 14 How to handle exceptions

An introduction to exceptions

The exception hierarchy

How exceptions are propagated

How to work with exceptions

How to use the try statement

How to use the try-with-resources statement

How to use the methods of an exception

How to use a multi-catch block

How to use the throws clause

How to use the throw statement

How to work with custom exception classes

How to create your own exception class

How to use exception chaining

How to work with assertions

How to code assert statements

How to enable and disable assertions

Section 4 GUI programming with Swing

Chapter 15 How to develop a form

An introduction to Swing

The user interface for the Future Value Calculator application

The inheritance hierarchy for Swing components

How to design a form

How to create a project for a GUI application

How to add a form to a project

How to add controls to a form

How to set properties

Common properties for forms and controls

How to add code to a form

How to set the variable name for a control

How to create an event handler for a control

How to rename or remove an event handler

How to enter the code for a form

Common methods for controls

How to display and center a form

The code for the FutureValueFrame class

How to validate Swing input data

How to display error messages

How to validate the data entered into a text field

The SwingValidator class

How to validate multiple entries

The Future Value application

The user interface

The code

Chapter 16 How to work with controls and handle events

How to work with components

How to work with text areas

How to work with check boxes

How to work with radio buttons

How to work with combo boxes

How to work with lists

The Payment application

The user interface

The code

How to code low-level events

A summary of low-level events

How to work with focus events

How to work with keyboard events

The Product Maintenance application

The user interface

The code

Chapter 17 How to develop and deploy applets

An introduction to applets

The Future Value Calculator applet

A brief history of applets

Applet security issues

The inheritance hierarchy for applets

Four methods of an applet

How to develop applets

How to develop a panel for an applet

How to code an applet

How to test an applet with the Applet Viewer

How to deploy applets

A procedure for deploying an applet

How to create an HTML document for an applet

How to run an applet within a web browser

Section 5 Data access programming with Java

Chapter 18 How to work with text and binary files

Introduction to directories and files

A package for working with directories and files

Code examples that work with directories and files

Introduction to file input and output

How files and streams work

A file I/O example

How to work with I/O exceptions

How to work with text files

How to connect a character output stream to a file

How to write to a text file

How to connect a character input stream to a file

How to read from a text file

An interface for working with file I/O

A class that works with a text file

How to work with binary files

How to connect a binary output stream to a file

How to write to a binary file

How to connect a binary input stream to a file

How to read from a binary file

Two ways to work with binary strings

How to work with random-access files

How to connect to a random-access file

How to read to and write from a random-access file

How to read and write fixed-length strings

A class that works with a random-access file

Chapter 19 How to work with XML

Introduction to XML

An XML document

XML tags, declarations, and comments

XML elements

XML attributes

An introduction to DTDs

How to view and edit an XML file

How to view an XML file

How to edit an XML file

An introduction to three XML APIs

DOM

SAX

StAX

How to use StAX to work with XML

How to create an XMLStreamWriter object

How to write XML

How to create an XMLStreamReader object

How to read XML

A class that works with an XML file

Chapter 20 How to work with a Derby database

How a relational database is organized

How a table is organized

How the tables in a database are related

How the columns in a database are defined

How to use SQL to work with the data in a database

How to query a single table

How to join data from two or more tables

How to add, update, and delete data in a table

An introduction to Derby

An overview of Derby

How to configure your system to work with a Derby database

How to use the ij tool to work with a Derby database

How to start and stop the ij tool

How to connect to and disconnect from a database

How to create a database and connect to it

How to run SQL statements

How to run SQL scripts from the ij prompt

How to run SQL scripts from the command prompt

How to start and stop the Derby database server

How to start the server

How to stop the server

How to learn more about Derby

How to view the Derby documentation

How to navigate through the documentation

Chapter 21 How to use JDBC to work with databases

An introduction to Java database drivers

The four driver types

How to add a database driver to a project

How to use Java to connect to a database

How to load a database driver

How to connect to an embedded database

How to disconnect from an embedded database

How to connect to a networked database

How to use Java to work with a database

How to return a result set

How to move the cursor through a result set

How to return data from a result set

How to modify data in a database

How to work with prepared statements

Two classes for working with databases

A utility class for working with strings

A class that works with a database

An introduction to working with metadata

How to work with metadata

How SQL data types map to Java data types

Section 6 Advanced Java skills

Chapter 22 How to work with threads

An introduction to threads

How threads work

Typical uses for threads

Classes and interfaces for working with threads

The life cycle of a thread

How to create threads

Constructors and methods of the Thread class

How to create a thread by extending the Thread class

How to create a thread by implementing the Runnable interface

How to manipulate threads

How to set a thread’s priority

How to interrupt a thread

How to synchronize threads

How to create synchronized threads

How to communicate among threads

The Order Queue application

The operation

The classes

The OrderQueueApp class

The Order class

The OrderTaker class

The OrderHandler class

The OrderQueue class

Chapter 23 How to deploy an application

An introduction to deployment

How executable JAR files work

How Java Web Start works

How an installer program works

How to use an executable JAR file

How to create an executable JAR file

How to deploy a GUI application

How to deploy a console application

How to use Java Web Start

A procedure for using Java Web Start

How to create a JNLP file

How to create an HTML document that launches an application

How to deploy an application to a remote web server

How to launch an application

How to fix a common problem

Appendixes

Appendix A How to set up your PC for this book

How to install the JDK

How to install NetBeans

How to install the source code for this book

Appendix B How to set up your Mac for this book

How to install the JDK

How to install NetBeans

How to install Derby

How to install the source code for this book

Sample chapters

Chapter 1: How to get started with Java and NetBeans

If you’re completely new to Java or the NetBeans IDE, chapter 1 gets you started right by giving you some background on Java and showing you how to use NetBeans to create, work with, compile, and run Java projects. By the end, you’ll be ready to start writing your own Java programs.

Chapter 2: Introduction to Java programming

To find out how quickly and easily you can learn Java from this book, download and read chapter 2. Whether you’re a programming novice or have years of programming experience, you’ll be writing complete Java programs by the end of this chapter.

Chapter 1 PDF (940Kb) Download Now

Chapter 2 PDF (640Kb) Download Now

The book applications and exercises

This download includes:

  • The Java source code and data for the applications that are presented in the book
  • The starting source code and data for the exercises in the book

All of the code is stored in NetBeans projects that are ready to be used with the NetBeans IDE. Appendix A in the book describes how to install these files on a Windows system, and Appendix B describes the installation process on a Mac.

Exe file for Windows (6.3Mb) Download Now

Zip file for Windows (6.2Mb) Download Now

Zip file for Mac (6.2Mb) Download Now

On this page, we’ll be posting answers to the questions that come up most often about this book. So if you have any questions that you haven’t found answered here at our site, please email us. Thanks!

To view the corrections for this book in a PDF, just click on this link: View the corrections

Then, if you find any other errors, please email us so we can correct them in the next printing of the book. Thank you!

Jorge Mongelos

Tuesday, 17 November 2015

I'm a student of Web and Software development, and let me say; books like this are hard to find. Simple and straightforward explanations in plain English. Good book really. I'm just not giving 5 stars because of the eBooks. You can't Highlight nor bookmark with due to the software that they chose to protect their copyright.
I'm all in favor to protect intellectual rights, but at the customer's expense? really? Besides that, it is an excellent book. Like I said: a book like this is hard to find.

To leave a review, please log in to your account.     Log In Here

Our Ironclad Guarantee

You must be satisfied. Try our print books for 30 days or our eBooks for 14 days. If they aren't the best you've ever used, you can return the books or cancel the eBooks for a prompt refund. No questions asked!

Contact Murach Books

For orders and customer service:

1-800-221-5528

Weekdays, 8 to 4 Pacific Time

College Instructors

If you're a college instructor who would like to consider a book for a course, please visit our website for instructors to learn how to get a complimentary review copy and the full set of instructional materials.