Posts Tagged ‘Beginning Java’

Beginning Java Programming: The Object-Oriented Approach Chapter 7 Compilation Error

This is the live code sandbox for Beginning Java Programming: The Object-Oriented Approach Chapter 7. This example demonstrates how you cannot access a private member of a class from another class. In the program, the class ProductProgram tries to access myWidget.productPrice on line 4. This leads to a compilation error because the string productPrice is […]

Tags:

Beginning Java Programming: The Object-Oriented Approach Chapter 7 OOP, Inheritance, and Multiple Classes

This is the live code sandbox for Beginning Java Programming: The Object-Oriented Approach Chapter 7. This example demonstrates a complete object-oriented program that implements withdrawal and deposits from/to savings and checking bank accounts. Notice how the SavingsAccount class and CheckingAccount class are derived from the abstract class Account. This inheritance helps other classes like the […]

Tags:

Beginning Java Programming: The Object-Oriented Approach Chapter 6 Graceful Exception Catching and Friendly Error Messages

This is the live code sandbox for Beginning Java Programming: The Object-Oriented Approach Chapter 6. This example demonstrates how to gracefully throw and catch a variety of exceptions and print corresponding user-friendly error messages back to the user. Click “Run” to run the example in your browser or edit the code and then click “Run” […]

Tags:

Beginning Java Programming: The Object-Oriented Approach Chapter 6 Finally Block

This is the live code sandbox for Beginning Java Programming: The Object-Oriented Approach Chapter 6. This example demonstrates a good use of the finally block. Note how the scanner object is being released in the finally block of the program. Since the finally block is always executed when the try block exits, it is the […]

Tags:

Beginning Java Programming: The Object-Oriented Approach Chapter 6 Logger Class

This is the live code sandbox for Beginning Java Programming: The Object-Oriented Approach Chapter 6. This example demonstrates how to use Java’s Logger class to log messages to the screen or file. Run the program and then open the files loggerExample_config.log (see the tree of project files to the left of the code window) to […]

Tags:

Beginning Java Programming: The Object-Oriented Approach Chapter 6 Different Assert Functions in JUnit

This is the live code sandbox for Beginning Java Programming: The Object-Oriented Approach Chapter 6. This example demonstrates how to use different assert functions in your JUnit code. Click “Run” to run the example in your browser or edit the code and then click “Run” to run it with your changes. You can download the […]

Tags:

Beginning Java Programming: The Object-Oriented Approach Chapter 6 Empty JUnit Testcase

This is the live code sandbox for Beginning Java Programming: The Object-Oriented Approach Chapter 6. This program demonstrates an empty JUnit testcase. Notice the fail() function called on line 29. That is the function that throws the AssertionError that is printed on the screen when the program is run. Click “Run” to run the example […]

Tags:

Beginning Java Programming: The Object-Oriented Approach Chapter 6 ArrayIndexOutOfBoundsException

This is the live code sandbox for Beginning Java Programming: The Object-Oriented Approach Chapter 6. This program throws an ArrayIndexOutOfBoundsException because the for loop is trying to access more elements than are actually present in the array. To get it working properly, change the comparison operator “<=" to "<" on line 7. Now the program […]

Tags:

Beginning Java Programming: The Object-Oriented Approach Chapter 6 Displaying an Unintialized Object Member

This is the live code sandbox for Beginning Java Programming: The Object-Oriented Approach Chapter 6. This example demonstrates what happens when an object member is displayed without being initialized. The program displays “null” for the value of myPerson.name. Click “Run” to run the example in your browser or edit the code and then click “Run” […]

Tags:

Beginning Java Programming: The Object-Oriented Approach Chapter 6 Using a Custom Object Prior to Initialization

This is the live code sandbox for Beginning Java Programming: The Object-Oriented Approach Chapter 6. This example demonstrates what happens when you try to use a custom object without initializing it first. You will get a compiler error when you run this program, informing you that the variable employee has not been initialized before it […]

Tags: