Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Wednesday, September 9, 2009

People and Java code debugging

Hi friends,

Today I would like to present few concepts in People related to Open Source and Java code debugging which would be helpful for the readers.

Without wasting further time, Here We Go!
Round :People

1.Who created Java?
James Gosling(born May 19, 1955 near Calgary, Alberta, Canada).

2.Who invented C++?
Bjarne Stroutstrup.

3.Who is the well known founder of Oracle?
Lawrence Joseph Larry Ellison.

4.Who is the well known founder of Apple?
Steven Paul Jobs.

5.He is from Moolaipozhi village near Tirunelvelli.Went on to start an IT company which is among top ten Indian IT services firms.
Who is this man and which company he create?

Shiv Nadar - HCL

Round : Java code debugging

1.public class Test {
public static void main(String[] args) throws Exception{
BigInteger fiveThousand = new BigInteger("5000");
BigInteger fiftyThousand = new BigInteger("50000");
BigInteger fiveHundredThousand = new BigInteger("500000");
BigInteger Total =BigInteger.ZERO;
System.out.println(Total);
Total.add(fiveThousand);
Total.add(fiftyThousand);
Total.add(fiveHundredThousand);
System.out.println(Total);
}
}
Output:0


2.package com.planetsoft;
public class Me{
public static void main(String[] args){
System.out.println(Me.class.getName().replaceAll(“.”,”\”)+”.class”);
}
output://///////////////.class


3..public boolean isOdd(int i){
return i%2==1;
}
Output: if we give odd numbers with negative it will return false . For eg: Lets take the value of i=-3 , after computing i%2 the value will be -1 and it will check -1==1 ,hence both not equals it will return false.


4..Write a one line method that takes a list and returns a list , eliminating duplicates and preserving the order of the original list?
Let duplicatedList be a Array list variable with duplicate values.whereas
LinkedHashSet list = new inkedHashSet(duplicatedList);



5. Write a one line method that takes comma a demilited strings and return a string[],each comma may be followed by zero or more spaces which must be ignored by the method.
It can be achieved using the regular expression.Here is the example using String,Similar way we can do that for string array.
String s = ", There , , a , is a , , , null , object ,";
s=s.replaceAll("%*, *","" );
System.out.println(s);



1.public class TestList {
public static void main(String[] args) throws Exception{
final long micros_perDay = 24*60*60*1000*1000;
final long macros_perDay = 24*60*60*1000;
System.out.println(micros_perDay/macros_perDay);
}
} output:5


2.public class AnimalFarm {
public static void main(String[] args) throws IOException{
final String pig = "length: 10";
final String pig1 = "length :"+pig.length();
System.out.println("animals are equal"+pig==pig1);

}
}
output:false


3.public class SetMagic {
public static void main(String[] args) throws IOException{
int[] vals = {10,012,14,016};
Set magic = new HashSet();
for(int i=0;i magic.add(vals[i]);
}System.out.println(magic.size());
}
}

output:2

4.public class Increment {
public static void main(String[] args){
int j=0;
for(int i=0;i<100;i++){
j=j++;
}
System.out.println(j);
}
}

output:0

5.Provide a definition for i so that the loop turns into a infinite loop.
while(i!=i){
system.out.println(“please stop”);
}
output: we can declare i
double i=Double.Nan;

Hope this topic was useful to you, Please Post your comments!

2 comments:

Sismadi said...

i'm very interesting with java...please teach me. i want to learn java struts for after it

Chandrasekar said...

Sure! Java is very easy! Sorry for the delay! Cheers! :)