Tags » Java Tutorial

Java Generic

Java Generic :

A parameterized type that operates by a class or an interface is called generic. It is introduced in java-5. It facilitate to write algo which is independent from any specific data type and type safety. 132 more words

Java

vector collection in java


package com.pkjavacode.com;

import java.util.Iterator;
import java.util.List;
import java.util.Vector;

public class VectorExample {
public static void main(String args[]) {
List<String> list = new Vector<String>();
list.add("Pradeep");
list.add("Ajit");
list.add("Vijay");
Iterator<String> itr = list.iterator();
while (itr.hasNext()) {
Object element = (Object) itr.next();
System.out.println("" + element);
}
}
}

… 7 more words
Java

What is IS-A and HAS-A relationship in java

IS-A and HAS-A relationship in java :

IS-A relationship :

IS-A relationship is based on class inheritance or interface implementation. You can say that “this thing is a type of that… 132 more words

Java

Enumeration or enums in java

Enumeration or enums :

Enumeration is just like a list which contains only constant type value. The items in the enumerated list are called enums. 332 more words

Core Java

Advantages of Hibernate Framework

Advantages of  Hibernate Framework :

  • Hibernate has capability to generate primary keys automatically while storing the records into database.
  • Hibernate provide automatic table creation facility.
  • 163 more words
Java

What is Hibernate Framework

Hibernate Framework :

Hibernate framework is an ORM(Object Relational Mapping) tools which is used to map java class with database table name and class variable with database table’s column. 49 more words

Java

Use comparable and sort employee list based on id

Use comparable and sort employee list based on id  :


package com,pkjavacode.com;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
*
* @author pradeep
*/
public class Emp implements Comparable<Emp> {

private int id;
private String name;

public Emp(int id, String name) {
this.id = id;
this.name = name;
}

/**
* @return the id
*/
public int getId() {
return id;
}

/**
* @param id the id to set
*/
public void setId(int id) {
this.id = id;
}

/**
* @return the name
*/
public String getName() {
return name;
}

/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}

public String toString() {
return "Employee details :" + "ID" + id + " Name :" + name;
}

@Override
public int compareTo(Emp e) {
return this.id - e.id;
}

public static void main(String[] args) {
Emp e1 = new Emp(101, "Pradeep");
Emp e2 = new Emp(107, "Ajeet");
Emp e3 = new Emp(103, "Amit");
Emp e4 = new Emp(104, "Rajesh");
Emp e5 = new Emp(105, "Bharat");
List<Emp> employees = Arrays.asList(e1, e2, e3, e4, e5);
System.out.println("Unsorted data :");
for (Emp employee : employees) {
System.out.println("Employee : " + employee.id + " Name: " + employee.name);
}
Collections.sort(employees);
System.out.println("sorted based on id :");
for (Emp employee : employees) {
System.out.println("Employee : " + employee.id + " Name: " + employee.name);
}
}
}

… 37 more words
Java