Skip to main content

Posts

The Switch Vs If-Else

The switch and if-else both are selection statement and they both let you select an alternative out of given many alternative by testing an expression.

Scope : Local And Global

From the computer’s point of view, a C program is nothing more than a collection of functions and declarations. Functions can be thought of as sealed capsules of program code which float on a background of white space,and are connected together by means of function calls. White space is the name given to the white of an imaginary piece of paper upon which a program is written, in other words the spaces and new line characters which are invisible to the eye. The global white space is only the gaps between functions, not the gaps inside functions. Thinking of functions as sealed capsules is a useful way of understanding the difference between local and global objects and the whole idea of scope in a program.

Java Runtime Environment

The Java Runtime Environment (JRE) provides the libraries, the Java Virtual Machine, and other components to run applets and applications written in the Java programming language. In addition, two key deployment technologies are part of the JRE: Java Plug-in, which enables applets to run in popular browsers; and Java Web Start, which deploys standalone applications over a network. (a) Java Plug-in : Java Plug-in technology, included as part of the Java Runtime Environment, Standard Edition (Java SE), establishes a connection between popular browsers and the Java platform. This connection enables applets on Web sites to be run within a browser on the desktop. (b) Java Web Start : Using Java Web Start technology, standalone Java software applications can be deployed with a single click over the network. Java Web Start ensures the most current version of the application will be deployed, as well as the correct version of the Java Runtime Environment (JRE).

Applications and Applets In Java

Java is a general-purpose, object-oriented programming language. We can  develop two types of Java programs : Stand alone Applications : Programs written in Java to carry out certain  tasks on a stand alone local computer.  Executing stand alone java  programs involves two steps : (a) Compiling through javac compiler. (b) Executing the byte code using java interpreter.  Web Applets : Programs that are developed for Internet based   applications. An applet located on a distant computer (Server) can be   downloaded via Internet and executed on a local computer (Client) using   a java capable browser. From the user‟s point of view, Java applications can be compared to   compiled C programs since they are started from a command line just like   any compiled program would be started. However, there is a major  difference: Java applications, as well as applets, are interpreted.  Applications are started on the command-...

Exception Handling in Java

The term exception is shorthand for the phrase "exceptional event." Definition : An exception is an event, which occurs during the execution of a program that disrupts the normal flow of the program's instructions.  When an error occurs within a method, the method creates an object and hands it off to the runtime system. The object, called an exception object, contains information about the error, including its type and the state of the program when the error occurred. Creating an exception object and handing it to the runtime system is called throwing an exception. After a method throws an exception, the runtime system attempts to find something to handle it.  Some of the predefined exception classes are :  ArithmeticException, ArrayIndexOutOfBoundException, IOException etc.

What are Abstract Methods and Classes

Abstract Methods and Classes : An abstract class is a class that is declared abstract—it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed. An abstract method is a method that is declared without an implementation (without braces, and followed by a semicolon), like this : abstract void moveTo(double deltaX, double deltaY); If a class includes abstract methods, the class itself must be declared abstract, as in: public abstract class GraphicObject { // declare fields // declare non-abstract methods abstract void draw(); } When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class. However, if it does not, the subclass must also be declared abstract. When an Abstract Class Implements an Interface : A class that implements an interface must implement all of the interface's methods. It is possible, however, to define a class that does not implement al...

Packages and Interfaces

Packages Many times when we get a chance to work on a small project, one thing we intend to do is to put all java files into one single directory. It is quick, easy and harmless. However if our small project gets bigger, and the number of files is increasing, putting all these files into the same directory would be a problematic for us. In java we can avoid this sort of problem by using Packages. Packages are nothing more than the way we organize files into different directories according to their functionality, usability as well as category they should belong to. Packaging also help us to avoid class name collision when we use the same class name as that of others. For example, if we have a class name called "Vector", its name would crash with the Vector class from JDK. However, this never happens because JDK use java.util as a package name for the Vector class (java.util.Vector). So our Vector class can be named as "Vector" or we can put it into another packa...