Java Reference
In-Depth Information
machines connected through a network. Java has features that make it easy to develop concurrent applications.
A concurrent application has multiple interacting threads of execution running in parallel. I will discuss these features
of the Java platform in detail in subsequent chapters in this topic.
Robustness of a program refers to its ability to handle unexpected situations reasonably. The unexpected
situation in a program is also known as an error. Java provides robustness by providing many features for error
checking at different points during a program's lifetime. The following are three different types of errors that may
occur in a Java program:
Compile-time error
Runtime error
Logic error
Compile-time errors are also known as syntax errors. They are caused by incorrect use of the Java language
syntax. Compile-time errors are detected by the Java compiler. A program with a compile-time error does not compile
into bytecode until the errors are corrected. Missing a semicolon at the end of a statement, assigning a decimal value
such as 10.23 to a variable of integer type, etc. are examples of compile-time errors.
Runtime errors occur when a Java program is run. This kind of error is not detected by the compiler because
a compiler does not have all of the runtime information available to it. Java is a strongly typed languages and it has
a robust type checking at compile-time as well as runtime. Java provides a neat exception handling mechanism to
handle runtime errors. When a runtime error occurs in a Java program, the JVM throws an exception, which the
program may catch and deal with. For example, dividing an integer by zero (e.g. 17/0 ) generates a runtime error. Java
avoids critical runtime errors, such as memory overrun and memory leaks, by providing a built-in mechanism for
automatic memory allocation and deallocation. The feature of automatic memory deallocation is known as garbage
collection.
Logic errors are the most critical errors in a program, and they are hard to find. They are introduced by the
programmer by implementing the functional requirement incorrectly. This kind of error cannot be detected by a Java
compiler or Java runtime. They are detected by application testers or users when they compare the actual behavior of
a program with its expected behavior. Sometimes a few logic errors can sneak into the production environment and
they go unnoticed even after the application is decommissioned.
An error in a program is known as a bug. The process of finding and fixing bugs in a program is known as
debugging. All modern integrated development environments (IDEs) such as NetBeans, Eclipse, JDeveloper, JBuilder,
etc, provide programmers with a tool called a debugger, which lets them run the program step-by-step and inspect the
program's state at every step to detect the bug. Debugging is a reality of programmer's daily activities. If you want to
be a good programmer, you must learn and be good at using the debuggers that come with the development tools that
you use to develop your Java programs.
The Object-Oriented Paradigm and Java
The object-oriented paradigm supports four major principles: abstraction, encapsulation, inheritance, and
polymorphism. They are also known as four pillars of the object-oriented paradigm. Abstraction is the process of
exposing the essential details of an entity, while ignoring the irrelevant details, to reduce the complexity for the users.
Encapsulation is the process of bundling data and operations on the data together in an entity. Inheritance is used to
derive a new type from an existing type, thereby establishing a parent-child relationship. Polymorphism lets an entity
take on different meanings in different contexts. The four principles are discussed in detail in the sections to follow.
 
Search WWH ::




Custom Search