handling Exception using try and catch

Although the default exception handler provided by the Java run-time system is useful for debugging, you will usually want to handle an exception yourself. Doing so provides two benefits. First, it allows you to fix the error. Second, it prevents the program from automatically terminating. Most users would be confused (to say the least) if your program stopped running…

Tagged

Exception-Handling Fundamentals

A Java exception is an object that describes an exceptional (that is, error) condition that has occurred in a piece of code. When an exceptional condition arises, an object representing that exception is created and thrown in the method that caused the error. That method may choose to handle the exception itself, or pass it on. Either way,…

Tagged

Static Imports in Java

Static Imports The only value import statements have is that they save typing and they can make your code easier to read. In Java 5, the import statement was enhanced to provide even greater keystroke-reduction capabilities although some would argue that this comes at the expense of readability. This new feature is known as static…

Tagged

Declaring Enums

As of 5.0, Java lets you restrict a variable to having one of only a few pre-defined values—in other words, one value from an enumerated list. (The items in the enumerated list are called enums). Using enums can help reduce the bugs in your code. For instance, in your coffee shop application you might want…

Tagged

Class and Super-Class

Any class class should o er its users a well-speci fied interface, which adhere to a published contract. We have studied so far the question of how these contracts can be maintained in the presence of inheritance. A second, complementary view on inheritance considers the derived class itself as a user of its super-class. After all, the derived class re-uses…

Tagged

Inheritance In Java

Inheritance is usually considered the feature most typical of object-oriented programming. If contracts are to be used successfully to reason about object-oriented programs, they must be applicable to the inheritance construct. Basic Concepts of Inheritance in Java Inheritance in mainstream object-oriented programming languages has two dimensions: types and implementation. Concerning the types, an object of any class B…

Tagged

Overview of Threads

Process A process is an instance of a computer program that is executed sequentially. It is a collection of instructions which are executed simultaneously at the rum time. Thus several processes may be associated with the same program. For example, to check the spelling is a single process in the Word Processor program and you…

Tagged

Java Compiler and Java Virtual Machine (JVM)

To commence with Java programming, we must know the significance of Java Compiler. When we write any program in a text editor like Notepad, we use Java compiler to compile it. A Java Compiler javac is a computer program or set of programs which translates java source code into java byte code.  The output from…

Tagged

Objects and Classes

Object – Objects have states and behaviors. Example: A dog has states-color, name, breed as well as behaviors -wagging, barking, eating. Identifying the state and behavior for real-world objects is a great way to begin thinking in terms of object-oriented programming. An object is an instance of a class. Class – A class can be defined as a…

Tagged

What is Java technology and why do we need it?

Java is a programming language and computing platform first released by Sun Microsystems in 1995. There are lots of applications and websites that will not work unless you have Java installed, and more are created every day. Java is fast, secure, and reliable. From laptops to datacenters, game consoles to scientific supercomputers, cell phones to…

Tagged