lalitha kaparapu

Greenhorn
+ Follow
since Nov 05, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by lalitha kaparapu

Hi Nadeem,

Even I am also confused with this.I dont know why the compliler is giving error for this.
Hi,

Thanks for your reply..I have found this material in the cd which came along with K&B book.So if you substitute <List E> instead of <List ? super E> the correct answers will be B and F.
Hi,

I have a doubt in K&B chapter7 16th question .

Given a method declared as:
public static <E extends Number> List<? super E> process(List<E> nums)
A programmer wants to use this method like this:
// INSERT DECLARATIONS HERE
output = process(input);
Which pairs of declarations could be placed at // INSERT DECLARATIONS HERE to allow
the code to compile? (Choose all that apply.)
A. ArrayList<Integer> input = null;
ArrayList<Integer> output = null;
B. ArrayList<Integer> input = null;
List<Integer> output = null;
C. ArrayList<Integer> input = null;
List<Number> output = null;
D. List<Number> input = null;
ArrayList<Integer> output = null;
E. List<Number> input = null;
List<Number> output = null;
F. List<Integer> input = null;
List<Integer> output = null;
G. None of the above.

For the above question B,E,F are given as correct.I tried to compile the code with B as option.But I am getting compiler error as Type mismatch:cannot convert from List<capture-of ? super Integer> to List<Integer>.

Is this question framed wrong??I have another doubt in this question even the option C should also be correct since the return type can be List<Integer> or anthinf which is super of Integer .So Number should also be correct..
I have one more doubt in this question

Do the co-variant returns not applicable to generics??Like can't we return an ArrayList to a method whose return type was declared as List.IF this is not true why we are passing an argument of type ArrayList to a method whose parameter was declared as of type List???


Can anyone please help me in this regard???
Hi,
I have a doubt in K&B Collections chapter.


import java.util.*;
public class LongWordFinder {
public static void main(String[] args) {
String[] array = { "123", "12345678", "1", "12", "1234567890"};
List<String> list = Arrays.asList(array);
Collection<String> resultList = getLongWords(list);
}
public static <E extends CharSequence> Collection<E>
getLongWords(Collection<E> coll)
{
Collection<E> longWords = new ArrayList<E>();
for (E word : coll)
if (word.length() > 6) longWords.add(word);
return longWords;
} }

In the above question in the getLongWords() method List argument was passed but in the method declaration we have parameter of type Collection.
How can this be true??eventhough List extends Collection we should not declare the method like this..But I tried this I didnt get any compiler error.Can anyone help me in this regard??
Yes I tried that code without the catch clause and I got the exception now..Thanks A lot!!!
I am sorry I am taking about "file1.txt"If the catch block is catching that exception Why again the file "file1.txt" is renamed to null.If there is an exception Y should it be renamed??
I am sorry I am taking about "file1.txt"If the catch block is catching that exception Why again the file "file1.txt" is renamed to null.If there is an exception Y should it be renamed??
import java.io.*;
public class Example4 {
public static void main(String args[]){
try{
File f=new File("directory");
f.mkdir();
File f1=new File(f,"file1.txt");
f1.createNewFile();
File f2=new File(f,"file3.txt");
f2.createNewFile();


PrintWriter p=new PrintWriter(f2);
p.println("lalli");
p.println("swar");
p.flush();
p.close();
System.out.println(f2.delete());
File l=null;
f1.renameTo(l);
}catch(Exception e){}
}
}
I compiled and ran this program.It compiled fan and the file "file3.txt" was renamed to null.But I saw in K&B that we must give the existingFile object a valid new File object with the new name you want(If l had been null we would get a NullPointerException).But I dint get any such exception instead that file was renamed to null.
Can anyone help me in this regard??
What is RuntimeException??Can we consider all the exceptions which occur at runtime are RuntimeExceptions like ArrayIndexOutOfBoundsException.What is the difference between JVM thrown exceptions and RuntimeExceptions??JVM thrown Exceptions also occur at runtime.I am confused with these two types of exceptions ..
Can anyone clarify this??
Thanks in advance..
Is IndexOutOfBoundsException a runtime exception or a checked exception???
An exception that's never caught will cause application to stop running.This is the line I found in K & B.But I read in some book that if the exception is never caught in our program that exception is propagated to the JVM.How JVM handles this exception.Will the JVM cause the application to stop running??
Can anyone please clarify this..
Hi Chinna,

Legal identifiers must be composed of only Unicode characters,
numbers, currency symbols, and connecting characters (like underscores).

In int e#;
You are including # which does not come under above characters..So its not legal.
I have one doubt regarding keywords.In one of the mock exam I observed that "true" is not a keyword.I have searched in K & B book also,there it does'nt list true as a keyword.
I have another doubt.Is this acceptible
Boolean flag=true;
Hi,
I tried the below code

Integer iObj1 = new Integer(100);
Integer iObj2 = new Integer(100);
if(iObj1 == iObj2)
System.out.println("Objects are equal!");
else
System.out.println("Objects are not equal!");

Predictably, the output is "Objects are not equal!".

Till jdk1.4, two wrapper objects, though both have same value are not considered as equal (==). We had to use the equals() method.

But from JDK1.5, using AUTOBOXING, we can use wrapper objects just like primitive datatypes.

The same piece of code when compiled in jdk1.5 should produce the output as "Objects are equal!".But when I compiled the abouve code with JDK 1.5,I am getting the output as "Objects are not equal!".

Can anyone help me in this regard??
Hi I tried the code below.Inspite of runtime exception at line 3 ,it is showing the runtime exception at line 4.Why the float value when divided by zero is returning infinity inspite of java.lang.ArithmetiException.
class Test{

public static void main ( String args [ ] ) {
int intX = 10 ; // line 1
float floatX = 10 ; // line 2
double doubleX = floatX / 0 ; // line 3
System.out.println(doubleX);
double doubleY = intX / 0 ; // line 4
System . out . println ( doubleX == doubleY ) ; // line 5
}
};