Monday, May 10, 2010

public class DacQuestion{
public static void main(String args[]){

int decrement = 12;
while(decrement<10)
decrement--;
System.out.println(decrement);

int increment = 0;
while (increment < 5)
increment++;
System.out.println(increment);
}
}

a. What will be the output for above question.
b, Explain why the answer.. is like that.

Thursday, April 22, 2010

Question of Day (QOD series)

I thought of this idea to start QOD series.. This will ask a question for the day..

So QOD is How to make a list as unmodifiable in Java. ? Infact Collections class has method to ensure to create unmodifiable list. Note that unmodifiable ! = immutable.

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

// How to make the arraylist unmodifiable.

public class Ques1 {

public static void main(String args[]){

List arrList = new ArrayList();
arrList.add(new String("SK"));
arrList.add(new String("PK"));
List unmodifiableList = Collections.unmodifiableList(arrList);

try{
unmodifiableList.add("NK");
}catch(Exception e){
e.printStackTrace();
}

// Making it unmodified again.
List newList = new ArrayList(unmodifiableList);
newList.add("NK");
System.out.println("Added NK");

for( String element : arrList){
System.out.println(element);
}

for( String element : newList){
System.out.println(element);
}
}

}


Now how to check if the unmodifiable list is not immutable?

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

// How to make the arraylist unmodifiable.

public class Ques1 {

public static void main(String args[]){

List arrList = new ArrayList();
arrList.add(new StringBuffer("SK"));
arrList.add(new StringBuffer("PK"));
List unmodifiableList = Collections.unmodifiableList(arrList);

try{
StringBuffer str = unmodifiableList.get(0);
str.append("New");
unmodifiableList.add(new StringBuffer("NK"));

}catch(Exception e){
e.printStackTrace();
}

// Making it unmodified again.
List newList = new ArrayList(unmodifiableList);
newList.add(new StringBuffer("NK"));
System.out.println("Added NK");

for( StringBuffer element : arrList){
System.out.println(element);
}

for( StringBuffer element : newList){
System.out.println(element);
}
}

Tuesday, March 9, 2010

Question asked in Cdac interview

1.

final int a = 1;
final int b;
b = 2;
int x = 0;
switch (x) {
case a:
System.out.println("Hello");
break;
case b:
System.out.println("World");
break;

}

what will be the output of this program.

Wednesday, February 10, 2010

Are you a software architect

http://www.infoq.com/articles/brown-are-you-a-software-architect;jsessionid=5B6661EBB8FA161D1119221BB7D8F784

Wednesday, December 2, 2009

What is System class in Java

Class System provides a standard place for programs to find system related information.

Friday, November 27, 2009

Nice Java puzzle..

Nice Java puzzle..
Came across the following puzzle.
http://whyjava.wordpress.com/2009/09/24/java-puzzlers-are-asked-in-interviews/

Thursday, June 25, 2009

coep wins Microsoft imagine cup

Great job done by 3 coepians:

http://www.sakaaltimes.com/2009/06/25125227/COEP-wins-Microsoft-Imagine-Cu.html

Hats off to them!!