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?

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

Saturday, 22 October 2011

Collection Interfaces tutorial and collection Interface video free download

Collection Interfaces video tutorial

It is the root of collection hierarchy. A Collection includes a group of objects known as elements. Some Collection classes allows duplicate elements, and others do not. Some are ordered and others are unordered. All collection class implement Collection interfaces or subinterfaces.

public interface Collection<E> extends Iterable<E>

Collection Interface extends Iterable interface

int size():Returns the number of elements in collection.

boolean isempty():Returns true only if collection is empty.

boolean Contains(Object o):Returns only if specified element is in the collection.

boolean add(Element e):This is used to add a single element to collection.This method true only when the element is added.

boolean remove(Object o):This element will remove specified element from collection. Returns true if the element is removed from collection.

Hash map tutorial and Hash map video free download

 Video sample screenshot:


Hash Map is like Hashtable which stores key/ value pairs. It implements Map interface and we can use all operations of Map interface. It permits null values and null key. The Hash Map class is almost equivalent to Hashtable, except that its unsynchronized and permits nulls. The order of elements is not guaranteed.

Following is the signature of HashMap class:
Public class HashMap extends AbstractMap implements Map, Cloneable, Serializable

HashMap constructor can be specified with -initial capacity and load factor. The capacity of HashMap gives the storage capacity and size() gives the actual elements present in the HashMap. The intial capacity gives the starting capacity of Hash Map when it is created. The load factor gives at what rate the capacity must be increased when the existing capacity gets exhausted. The default load factor is 0.75

There are four constructors in the class HashMap.

It creates an empty HashMap object with an initial capacity of 10 and default load capacity of 16.

HashMap(int cap):It creates an empty Hash Map object with an intial capacity specified as "cap" and a default load capacity of 16.

HashMap(int cap, float loadfactor): It creates an empty HashMap object with intial capacity specified as "cap" and a load capacity specified as "loadcap".

HashMap(Map m1):It creates a HashMap object with the elements of another Map class specified as "M!"