Archive for category Java7

Map and its Implemented Class

╔══════════════╦═════════════════════╦═══════════════════╦══════════════════════╗
║   Property   ║       HashMap       ║      TreeMap      ║     LinkedHashMap    ║
╠══════════════╬═════════════════════╬═══════════════════╬══════════════════════╣
║              ║  no guarantee order ║ sorted according  ║                      ║
║   Order      ║ will remain constant║ to the natural    ║    insertion-order   ║
║              ║      over time      ║    ordering       ║                      ║
╠══════════════╬═════════════════════╬═══════════════════╬══════════════════════╣
║  Get/put     ║                     ║                   ║                      ║
║   remove     ║         O(1)        ║      O(log(n))    ║         O(1)         ║
║ containsKey  ║                     ║                   ║                      ║
╠══════════════╬═════════════════════╬═══════════════════╬══════════════════════╣
║              ║                     ║   NavigableMap    ║                      ║
║  Interfaces  ║         Map         ║       Map         ║         Map          ║
║              ║                     ║    SortedMap      ║                      ║
╠══════════════╬═════════════════════╬═══════════════════╬══════════════════════╣
║              ║                     ║                   ║                      ║
║     Null     ║       allowed       ║    only values    ║       allowed        ║
║ values/keys  ║                     ║                   ║                      ║
╠══════════════╬═════════════════════╩═══════════════════╩══════════════════════╣
║              ║   Fail-fast behavior of an iterator cannot be guaranteed       ║
║   Fail-fast  ║ impossible to make any hard guarantees in the presence of      ║
║   behavior   ║           unsynchronized concurrent modification               ║
╠══════════════╬═════════════════════╦═══════════════════╦══════════════════════╣
║              ║                     ║                   ║                      ║
║Implementation║      buckets        ║   Red-Black Tree  ║    double-linked     ║
║              ║                     ║                   ║       buckets        ║
╠══════════════╬═════════════════════╩═══════════════════╩══════════════════════╣
║      Is      ║                                                                ║
║ synchronized ║              implementation is not synchronized                ║
╚══════════════╩════════════════════════════════════════════════════════════════╝
Advertisements

, , ,

Leave a comment

Marshalling & UnMarshalling

Marshalling:

To convert the Java Object  to XML

UnMarshalling:

convert XML to Java Object

, , , , ,

Leave a comment

Junit

Junit:

It is used to test the individual function of the class (Unit testing)

 

Annotation and its use :-

@BeforeClass
It executes begining every  class added in the  testsuite

@AfterClass
It executes end of the  every  class added in the testsuite

@Test
By using this  @Test, Junit pick up the test method and execute and return the result

@Test (expected = Exception.class)
Exception like IllegalArgumentException, RunTimeException, etc..
We can expect the exception which will  occur while execute the test case

@Test(timeout=100)
Fail the testcase if the execution  takes after the particular time, which is  mentioned in timout parameter

@Ignore
Ignore the method  which have @Ignore

@Before
Execute before every method

@After
Execute before every method

@Parameters
Use to execute the testcase for multiple times based on the input

 

@RunWith(value = Parameterized.class)

Notes:

  • Method should be public
  • Method should not have parameter

By using Junit 4:
We can’t add dynamic suite class

By using JUnit 3:

We can add the classes dynamic

Here I attached a sample program :

—————————

package com.junit.packA;

import org.junit.Assert;
import org.junit.Test;

public class Addition {
@Test
public void CaseOne(){
Assert.assertTrue(add(15, 10));

}

private boolean add(int i, int j) {
if(i > j){

return true;
}
return false;
}

}

—————————-

package com.junit.packA;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(Suite.class)
@SuiteClasses({Addition.class})
public class MainSuite {

}

Run procedure in Eclipse:

Right click the MainSuite class in eclipse and select  RunAs –> Junit Test

, , ,

Leave a comment

Collection RealTimeExample

Hi Guys,

Here I specified a  collection and its subclasses

For  easy understanding I specify feautures and its relevant  example for each Subclasses:

HashTable:

Feature:

  • Key-Value pair
  • Does not allow null for both key & value
  • Synchronized ie ) Concurrent modification not allowed

, , , , ,

Leave a comment

Java Naming convention

Best Explanation :Java Naming Convention

http://www.appperfect.com/support/java-coding-rules/namingconvention.html

Leave a comment

Java -15 Years

Hi,

Today May- 23- 2012  is the 15th anniversary for the JAVA  Programming language,Lets cheers and proud to be a Java Guy..

 

Leave a comment

Difference between HashMap and Hash Table

Hash Table HashMap
It is one of the original collection classes in Java

Hashtable is synchronized

HashMap is fail-safe

HashMap permits null values

ie)one null key and any number of null values

It is part of the new Collections Framework, added in Java 2,v 1.2

HashMap isn’t

HashMap isn’t

Hashtable doesn’t permit null key or value

,

Leave a comment