Wednesday, October 9, 2013

DOM in Javascript

  • DOM Abbreviated as Document Object Model.
  • It’s a Platform and Language API(Application Programming Interface) which allows programs to access andupdate the content, Structure, and Style of a document.
  • We can Say JVM(Java virtual Machine) for Java. DOM is for UI(HTML, CSS, Javascript etc).
  • DOM represents a document as a tree structure. The tree made up of parent-child relationship.
  • parent-child relationship means a parent can have one or more children nodes.

  • Example:

    DOM Structure:
    • DOM Structure
    • In the above picture we have two child node’s for HTML. 1. Title and 2. Body.
    • For head we have one child which is title. For title we have child “title text” which we say text node.
    • For body we have one child which is ”content text” it’s a text node.
    HTML tags are Element node in DOM tree, Pieces of text become text nodes. Both of them are nodes Just the type is different.

Friday, August 3, 2012

I/O Streams in Java – with simple example

       Streams are used to transfer data from one location to location, just like a water pipe which carrires water from one place to other.

Different sizes of waters pipes are used to carry water from different sources (Ex: Ground water, from water tank, from reservoir, etc.).  The size and type of the pipe depend upon the quantity of water that to be transferred.  Similarly in java different streams are used to transfer data to/from different source (Ex: input device, output device and files)
In java, basically there are two types of streams available
1.      Input Stream – A stream is used to read data from an input source is called Input Stream.
2.      Output Stream – A stream is used to read data to an output stream is called output stream.
All streams in java are represented by classes in “” package. The package contains serialization classes and the file system classes along with these stream classes. In java all Input and output operations are performed through these data streams.
Let us now consider, a simple example “reading a character from keyboard” to better understand the streams.

Class KeyboardChar
            Public static void main (String arg[])
 // CreateInputStreamReader and BufferedReaders object to accept data from keyboard
                        InputStreamReader  Istream  =  InputStreamReader(;
                        BufferedReader br = new BufferedReader(Istream);
                        System.out.println(“Enter a character”);
                        Char ch = (char); // read a single character
                        System.out.println(“You Entered : ” + ch);


In the above program, is representing a standard input device i.e, keyboard. Now this “” is a source of data like Reservoir of water as shown in figure 1.1. Here the keyboard is a Input Stream object.
Figure 1.1 shows the data flow in Streams similar to water flow in a pipe 

The “InputReaderClass” is like a water pipe to carry data. Till now it is good, now what about the “Buffered Stream Reader” class? BufferedStreamReader class is like a water tap at end of the pipe which is used to control the water flow.
Therefore, Buffered Stream Reader is an efficient way to bring the data outside of the pipe by using different controls like
1.; à slow
2.      br.readLine(); -- > fast is used bring the data slowly like character by character (open the water tap slightly).
br.readLine() is used to bring the more data like entire line of data can be read (open the water tape completly).

Thursday, August 2, 2012

Diamond Inheritance problem in C++ and How it is solved in Java

In this tutorial, we can examine the problem with multiple inheritance in C++ language and how it is avoided in java using Interface concepts. Before going to the actual discussion, let us check out some basics about the multiple Inheritance concept.
What is multiple Inheritance?
Deriving a sub-class from two or more super classes is called multiple Inheritance. From the figure 1.1 , the sub classes ‘C’ is derived from two super classes (A and B). In multiple Inheritance there can be one or more super classes.

Figure 1.1 Deriving sub class C from two super classes (A and B)

Problem with multiple Inheritance
Consider a super class A from which two sub classes (B and C) are derived as shown in figure 1.2. The class A has a variable ‘x’  and its values is ‘5’ (x = 5). All the properties (data and methods) of super class A are derived into its subclasses B and C. Therefore the sub classes B and C have the variable ‘x’. Let us suppose, the x value in class B is changed to ‘10’ (k = 10) and in class C the variable x value is left unchanged. This is single Inheritance (one Boss many Employees). Till now there is no problem.
Problem is here:
If another sub class (D) is derived from two super classes (B and C) then all the properties if B and C are derived into the class D. The variable ‘x’ also derived into the class D. Now the problem is which value of ‘x’ should be taken into class D. This type of Inheritance is called Diamond Inheritance and leads to confusion regarding which copy of ‘x’ is available in C.
This can better explained by using Boss Employee example. Consider there are two bosses with same level priority in an organization giving orders to single employee. The employee may get confused which orders has to follow first. This sort of confusion may lead to chaos in the organization.

Figure 1.2 Diamond Inheritance
Multiple Inheritance is available in C++, but it is not available in java due to diamond Inheritance problem.
Multiple Inheritance is a powerful concept, it helps a lot while developing an application. For example, in a car manufacture company all individual parts are designed separately in different sections. But finally all these individual parts are assembled together and send it to market.
Similarly, while developing a software application, difference parts of the applications are developed separately and finally assembled together. In such cases multiple inheritance concept is very useful.

Solution to Diamond Inheritance:
Consider another example, if two teachers teaching same subject to students in a class. Then student may get confused to which type of syntax is used to define a formula or which procedure to be used to solve a problem in a particular subject. But sometimes students will get clear idea about the concept of the subject.
From the above example, two teachers for same subject will be advantage to students with respect to improve their knowledge about the subject. But it will be a problem to them regarding rules of each teacher.
To solve this situation, the management of the school or college keeps two teachers for same subject by labeling main and dummy. One teacher (main) for regular class work and other one (dummy) for doubts clarifications during tuition hours in the school/college. With this idea, student need not follow second teacher rules (dummy) in a subject, but they can clarify their doubts.
In the same way, the diamond Inheritance problem was solved in java by defining a concept of Interface (dummy class). Interface concept will keep the advantage of multiple Inheritance and at the same time it will solve the diamond Inheritance.
An Interface is a dummy class, which contains constants and function prototypes (in complete methods). An Interface is purely in-complete class, nothing is implemented. Therefore we are unable to create an object to an Interface.

Figure 1.3 Diamond Inheritance with Interface

Consider Diamond Inheritance using Interface concept as shown in figure 1.3, in which x is a final constant not a variable like in class. Constant is always constant, even though it is derived into any classes. Therefore confusion with variable in diamond inheritance is avoided by making it as a constant in java using Interface concept and also allows the advantage of multiple inheritance.

Monday, July 30, 2012

Difference Between Window and Frame in Java

What is the Difference between a window and a Frame?
A window is an undecorated Frame. That is it doesn’t have title bar, border and any close button. It is just a container, which holds children components on it like button, label, text field, etc. Simple we can say it is an imaginary rectangle. The default layout to place these children is Border Layout.
A Frame is derived from window but it has title bar, border, close button, minimize button, resizable and movable options. By default it also has Border Layout.
Note: A frame is a part of a window, but a window is not a part of window.

Thursday, April 5, 2012

Om ganeshaya namaha, Om sai baba, Om venkateswara, Om durgamma

Om ganeshaya namaha, Om sai baba, Om venkateswara, Om durgamma

Twitter Delicious Facebook Digg Stumbleupon Favorites More

Powered by Blogger