Thursday 3 November 2011

Arrays in Java| Core Java tutorials

Arrays in Java:
An array is a group of similar data type items that share common name.
Arrays occupy contiguous memory locations.
Array size is fixed and cannot be altered dynamically.
 A particular value is indicated by writing a number called index number or subscript in square brackets after the array name.
For example we can define an array name employee to represent a set of salaries of  a group of employees. For example
Employee [3]
Represents the fourth employee starting from zero.
Complete set of values is referred to as array, the individual values are called elements.
Arrays can be of any primitive datatypes. It is also possible to create array of objects.
One dimensional arrays:
A list of items can be given one variable name using only one subscript and such a group of variables is called one dimensional array.
Ex:int count[];
double  [] average;
Multidimensional array
It is actually an array of arrays. To declare a multidimensional array variable, each additional index should be specified using another set of square brackets.
Int marks [][];
Declaration of Arrays:
Ex:int count[];
double  [] average;
Creating one dimensional array:
Arrays must be declared and created in the computer memory before they are used. Creation of Array involves
a)      Declare the array.
b)      Create memory location
c)       Assigning the values in memory location

Declaration of Arrays:

Arrays in java may be declared in two forms:
 a)      datatype array- name[];
b)      datatype [] arrayname;

Wednesday 2 November 2011

Super method in Java| Java tutorials

super() method is used to call superclass constructor from subclass constructor. Depending on the parameters we pass, appropriate super() method is called.

Restrictions of using super():

a)If exists, it must be the first statement in the constructor.

b)We cannot use two super() methods within the same constructor as both cannot be the first. We cannot use two super() statements or two this() statements or one super() or one this() within the same constructor.




Super keyword in Java| Java tutorials


Super keyword in Java
Super keyword is mainly used to access superclass variables and methods in subclass.

The variables and method s of a superclass can be overridden by the subclass. In case of overriding , a subclass object calls its own variables or methods. That is,subclass cannot access superclass methods as long as they are overridden. Other way, the overridden variable or method blocks that of super class.

Java still provides a way to access the superclass members,even if they are overridden. It is possible by using super keyword.

Note:The restriction of using super keyword is that we should not use it from a static method.

Method overriding in Java


Method overriding in java

Overriding is a concept where instead of inheriting a method from its superclass,  a subclass can override the method by providing its own functionality to it. That is, subclass and superclass have the same method but outputs are different.  Overriding is useful on occasions when we want an object to respond to the same method but have different behavior when that method is called.  

The overridden method in the subclass has the same name, same arguments and same return type as the method in super class. Then, when that method is called, the method defined in subclass is invoked and executed instead of the one in the superclass.

If the superclass and the subclass have the same method, we say the superclass method is overridden by subclass. It is called method overriding. In case  of method overriding, the subclass prefers to call its own method.

Tuesday 1 November 2011

Difference between c++ and Java?


                             Java
                            C++
1)There are no pointers in java
1)There are pointers
2)There is no  operator overloading in Java
2)There is operator overloading in C++
3)There are no  processor directives
3)There are preprocessor directives
4)There are no Structures and Unions
4)There are Structures and Unions
5)There is no go to statement
5)There is go to statement in C++
6)There are no global variables
6)There are global variables
7)There are no templates
7)There are templates
8)There is garbage collection
8)There is no garbage collection
9)Java does not support multiple inheritance
9)C++ supports multiple inheritance