All Types GNIIT/NIIT Solution (Mr Jerry) Follow me on G+ and Twitter for more updates Twitter @mrjerry0001 #Write for us and get paid contact us On hike App:- @mrjerry4968
Pages
- Home
- HTML LAB@HOME
- DSA LAB@HOME
- WCD LAB@HOME
- C# LAB@HOME
- RDBMS LAB@HOME
- IADRT Lab@home
- EBDD LAB@HOME
- ACPC Lab@home
- LBEPS Lab@home
- ICTWC LAB@HOME
- SQL LAB@HOME
- WINDOWS APP LAB@HOME
- JAVA LAB@HOME
- NETWORK ESSENTIALS + LAB@HOME
- ASP.NET LAB@HOME
- LBEPS CYCLE TEST
- ASP.NET CYCLE TEST
- JAVA CYCLE TEST
- RDBMS CYCLE TEST
- DSA CYCLE TEST
- NIIT-HTML CYCLE TEST
- NIIT ASSIGNMENTS
- NIIT PROJECTS
- CORE JAVA NOTES
- NIIT BOOKS
- NIIT MT SOLVED
Sunday, 14 May 2017
Java Applet ~ mkniit
Java Legacy Classes ~ mkniit
Legacy Classes
Early version of java did not include the Collection framework. It only defined several classes and interface that provide method for storing objects. When Collection framework were added in J2SE 1.2, the original classes were reengineered to support the collection interface. These classes are also known as Legacy classes. All legacy claases and interface were redesign by JDK 5 to support Generics.
The following are the legacy classes defined by java.util package
- Dictionary
- HashTable
- Properties
- Stack
- Vector
There is only one legacy interface called Enumeration
NOTE: All the legacy classes are syncronized
Java Comparator Interface ~ mkniit
In Java, Comparator interface is used to order the object in your own way. It gives you ability to decide how element are stored within sorted collection and map.
Comparator Interface defines
compare() method. This method compare two object and return 0 if two object are equal. It returns a positive value if object1 is greater than object2. Otherwise a negative value is return. The method can throw a ClassCastException if the type of object are not compatible for comparison.Example
Student class
class Student
int roll;
String name;
Student(int r,String n)
{
roll = r;
name = n;
}
public String toString()
{
return roll+" "+name;
}Java Map Interface ~ mkniit
A Map stores data in key and value association. Both key and values are objects. The key must be unique but the values can be duplicate. Although Maps are a part of Collection Framework, they can not actually be called as collections because of some properties that they posses. However we can obtain a collection-view of maps.
| Interface | Description |
|---|---|
| Map | Maps unique key to value. |
| Map.Entry | Describe an element in key and value pair in a map. This is an inner class of map. |
| NavigableMap | Extends SortedMap to handle the retrienal of entries based on closest match searches |
| SortedMap | Extends Map so that key are maintained in an ascending order. |
Java Iterator and ListIterator ~ mkniit
Accessing a Collection
To access, modify or remove any element from any collection we need to first find the element, for which we have to cycle throught the elements of the collection. There are three possible ways to cycle through the elements of any collection.
- Using Iterator interface
- Using ListIterator interface
- Using for-each loop
Accessing elements using Iterator
Iterator Interface is used to traverse a list in forward direction, enabling you to remove or modify the elements of the collection. Each collection classes provide iterator() method to return an iterator.
Java Collection Classes ~ mkniit
The Collection classes
Java provides a set of Collection classes that implements Collection interface. Some of these classes provide full implementations that can be used as it is and other abstract classes provides skeletal implementations that can be used as starting points for creating concrete collections.
ArrayList class
- ArrayList class extends AbstractList class and implements the List interface.
- ArrayList supports dynamic array that can grow as needed. ArrayList has three constructors.
ArrayList() ArrayList( Collection C ) ArrayList( int capacity )
- ArrayLists are created with an initial size, when this size is exceeded, it gets enlarged automatically.
- It can contain Duplicate elements and maintains the insertion order.
Java Collection Interfaces ~ mkniit
Interfaces of Collection Framework
The collection framework has a lot of Interfaces, setting the fundamental nature of various collection classes. Lets study the most important Interfaces in the collection framework.
The Collection Interface
- It is at the top of collection heirarchy and must be implemented by any class that defines a collection. Its general declaration is,
interface Collection < E >
- Following are some of the commonly used methods in this interface.
Methods Description add( E obj ) Used to add objects to a collection. Doesn't add duplicate elements to the collection. addAll( Collection C ) Add all elements of collection C to the invoking collection remove( Object obj ) To remove an object from collection removeAll( Collection C ) Removes all element of collection C from the invoking collection contains( Object obj ) To determine whether an object is present in collection or not isEmpty() Returns true if collection is empty, else returns false size() returns number of elements present in collection
Java Introduction to Collection ~ mkniit
Collection Framework
Collection framework was not part of original Java release. Collections was added to J2SE 1.2. Prior to Java 2, Java provided adhoc classes such as Dictionary, Vector, Stack and Properties to store and manipulate groups of objects. Collection framework provides many important classes and interfaces to collect and organize group of alike objects.
Important Interfaces of Collection API
| Interface | Description |
|---|---|
| Collection | Enables you to work with groups of object; it is at the top of collection hierarchy |
| Deque | Extends queue to handle double ended queue. |
| List | Extends collection to handle sequences list of object. |
| Queue | Extends collection to handle special kind of list in which element are removed only from the head. |
| Set | Extends collection to handle sets, which must contain unique element. |
| SortedSet | Extends sets to handle sorted set. |
Java Generics ~ mkniit
A class or interface that operates on parameterized type is called Generic. Generics was first introduced in Java5. Now it is one of the most profound feature of java programming language. It provides facility to write algorithm independent of any specific type of data. Generics also provide type safety.
Using Generics, it becomes possible to create a single class or method that automatically works with all types of data(Integer, String, Float etc). It expanded the ability to reuse code safely and easily.
Example of Generic class
class Gen <T>
{
T ob; //an object of type T is declared
Gen(T o) //constructor
{
ob = o;
}
public T getOb()
{
return ob;
}
}
class Test
{
public static void main (String[] args)
{
Gen < Integer> iob = new Gen(100); //instance of Integer type Gen Class.
int x = iob.getOb();
System.out.print in(x);
Gen < String> sob = new Gen("Hello"); //instance of String type Gen Class.
String str = sob.getOb();
}
} Java Java Networking ~ mkniit
Networking in Java
Java is a premier language for network programming. java.net package encapsulate large number of classes and interface that provides an easy-to use means to access network resources. Here are some important classes and interfaces of java.net package.
Some Important Classes
| CLASSES | |
|---|---|
| CacheRequest | CookieHandler |
| CookieManager | Datagrampacket |
| Inet Address | ServerSocket |
| Socket | DatagramSocket |
| Proxy | URL |
| URLConnection | |
Java Serialization ~ mkniit
Serialization and Deserialization in Java
Serialization is a process of converting an object into a sequence of bytes which can be persisted to a disk or database or can be sent through streams. The reverse process of creating object from sequence of bytes is called deserialization.
A class must implement Serializable interface present in java.io package in order to serialize its object successfully. Serializable is a marker interface that adds serializable behaviour to the class implementing it.
Java provides Serializable API encapsulated under java.io package for serializing and deserializing objects which include,
- java.io.serializable
- java.io.Externalizable
- ObjectInputStream
- and ObjectOutputStream etc.
Subscribe to:
Posts (Atom)