| Mobile | RSS

Java Tutorial : The Nested try catch Block

The nested try-catch block is used to handle exceptions in Java applications. You can enclose a try-catch block in an existing try-catch block. The enclosed try-catch block is called the inner try-catch block, and the enclosing block is called the outer trycatch block. If the inner try block does not contain the catch statement to [...]

[ More ] 23rd Apr, 2010 | No Comment | Posted in Java

Java Tutorial : The super and this Keywords

Java provides the super keyword that enables a subclass to refer to its superclass. The super keyword is used to access: superclass constructors superclass methods and variables Consider a Java application, which consists of multiple classes. The subclass in the application needs to reuse the constructor of the superclass. In this application, super keyword is used as [...]

[ More ] 19th Mar, 2010 | No Comment | Posted in Java
Java Tutorial : Implementing Interfaces – Example

Java Tutorial : Implementing Interfaces – Example

David Johnson is the owner of Safest Software Co. that deals in buying and selling of hardware and software computer products. Don Allen, an employee of the Safest Software Co. is assigned the task to develop a Java application to keep track of the inventory of the computer hardware and software products. The application consists [...]

[ More ] 15th Jan, 2010 | 1 Comment | Posted in Java

Implementing User Defined Exceptions

In addition to the built-in exceptions, you can create customized exception as per the application requirements. Each application that you create might have specific constraints. For example, in case of a train reservation application, a passenger must specify the destination. Also, a ticket has to be bought for a passenger who is above three years [...]

[ More ] 3rd Dec, 2009 | No Comment | Posted in Java

Java Tutorial : Exception-Handling – Summary

Errors can be broadly categorized into two groups on the basis of whether the compiler is able to handle the error or not, such as compile time errors and runtime errors. An exception is a run-time error that can be defined as an abnormal event that occurs during the execution of a program and disrupts [...]

[ More ] 29th Nov, 2009 | No Comment | Posted in Java
Using Assertions

Java Tutorial : Assertion In Java

Assertions are the checks provided by the Java language to ensure that any assumption made at the start of a program is true throughout the program. The assumptions in a program can be simple facts, such as the range of a number is between 10 and 20; or a number cannot be greater than 100. [...]

[ More ] 16th Nov, 2009 | No Comment | Posted in Java
Rethrowing an Exception

Java Tutorial : Throwing An Exception – Part 2

Java Tutorial : Throwing An Exception – Part 1 Printing a Stack Trace When an exception is caught, you can find out the method or the line of the code where the exception is raised by using the printStackTrace() method. You can call the printStackTrace() method for printing the stack trace. The objects of the [...]

[ More ] 30th Oct, 2009 | 1 Comment | Posted in Java
Displaying the Description of an Exception

Java Tutorial : Throwing An Exception – Part 1

You can throw an exception explicitly using the throw statement. For example, you need to throw an exception when a user enters a wrong loginID or password. The throws clause is used to list the types of exceptions that can be thrown during the execution of a method in a program. Using the throw Statement [...]

[ More ] 20th Oct, 2009 | 1 Comment | Posted in Java
Unreachable Code Problem

Java Tutorial : Implementing Exception Handling – Part 2

Handling the Unreachable Code Problem The multiple catch blocks generate unreachable code error. If the first catch block contains the Exception class object then the subsequent catch blocks are never executed. The Exception class being the superclass of all the exception classes catches various types of exceptions. The Java compiler gives an error stating that [...]

[ More ] 18th Oct, 2009 | No Comment | Posted in Java

Java Tutorial : Implementing Exception Handling

When an unexpected error occurs in a method, Java creates an object of the type Exception. After creating the Exception object, Java sends it to the program by throwing the exception. The Exception object contains information about the type of error and the state of the program when the exception occurred. You need to handle [...]

[ More ] 14th Oct, 2009 | 1 Comment | Posted in Java

Java Tutorial : Built-in Exceptions

The built-in exceptions in Java are categorized on the basis of whether the exception is handled by the Java compiler or not. Java consists of the following categories of built-in exceptions: Checked Exceptions Unchecked Exceptions Checked Exceptions Checked exceptions are the objects of the Exception class or any of its subclasses excluding the Runtime Exception [...]

[ More ] 12th Oct, 2009 | No Comment | Posted in Java
Exception Hierarchy

Java Tutorial : Exception Classes

Exception Handling To handle exceptions, the Java run-time system searches for an exception-handler. In Java, a catch statement is an exception-handler that is used to handle an exception. The search for an exception-handler begins with the method in which the exception is raised. If no appropriate exception-handler is found, the Java run-time system searches the [...]

[ More ] 11th Oct, 2009 | No Comment | Posted in Java

Java Tutorial : Exception Handling

The term exception in Java indicates an exceptional event. It can be defined as an abnormal event that occurs during program execution and disrupts the normal flow of instructions. The abnormal event can also be an error in the program. Errors in a Java program are categorized into two groups: compile-time errors and run-time errors. [...]

[ More ] 28th Sep, 2009 | 3 Comments | Posted in Java

Java Tutorial : Inheritance and Interfaces – Summary

Inheritance is the concept of extending data members and methods of a superclass in a subclass. You can derive data members and methods from a single superclass that is a subclass of another superclass. Java does not support multiple inheritance directly. You can use the concept of method overriding to override the superclass method with [...]

[ More ] 24th Sep, 2009 | No Comment | Posted in Java

Java Tutorial : Implementing Interfaces

There might be cases where you might need to inherit the features of more than one class. But Java does not support multiple inheritance. However, you can simulate multiple inheritance in Java by using interfaces. An interface is a collection of methods and data members that can be implemented by any number of classes residing [...]

[ More ] 13th Sep, 2009 | No Comment | Posted in Java
Java Tutorial: Implementing Overriding Methods

Java Tutorial: Implementing Overriding Methods

When you extend the functionality of a class, the subclass inherits the data members and methods from the superclass. For example, if the superclass has a show() method, which displays the value of the superclass, the subclass inherits the show() method from the superclass. When you call this method from an object of the subclass, [...]

[ More ] 11th Sep, 2009 | No Comment | Posted in Java
  • Page 1 of 2
  • 1
  • 2
  • >