Win a copy of Getting started with Java on the Raspberry Pi this week in the Raspberry Pi forum!

Venu Chakravorty

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

Recent posts by Venu Chakravorty

A word of advice Bryce:
Braces make code more readable, use them.

Hope this helps.
11 years ago
I want to read from a .htm file (around 800KB, 18000 lines) and store the text in a String object. The code follows:

This works for smaller files, but for this file it is not working.
Please help.

Venu Chakravorty.
12 years ago
consider a case of using <? extends Animal>
here the method can accept anything that is an Animal and you can't use the add() method in this case.

consider a case of using <? super Animal>
here the method can accept anything that is a supertype of Animal. That might include Vertibrates, LivingThings or even Object. So the method can accept all these and you can add elements which are (IS-A) Animal(s).

Please correct me if I am wrong.


Malatesh Karabisti wrote:From K & B Book

public void addAnimal(List<? super Dog> animals)
is essentially, "Hey compiler, please accept any List with a generic type that is of type Dog, or a supertype of Dog.
Nothing lower in the inheritance tree can come in, but anything higher than Dog is OK."

I think my source of confusion is these words still these words are not very clear to me ?

Of course the method can accept any supertype of Dog or Dog itself. We get the error when we are adding elements to the list (List).

What are the things that can be done in C and not in Java. Let's keep aside JNI.

Thanks and regards,
13 years ago
Hi, Sandy
Create a Cookie object and send it (response.addCookie(Cookie)) when the user logs in. Before a secure page loads, check whether this cookie exists.
Upon logout delete this cookie (using 'setMaxAge(0)' and then send it).
13 years ago
Hi David and Janeice,
Is it to be done like this:
Map<String, ArrayList<String>> acc = new Hashtable<String, ArrayList<String>>;
13 years ago
There is a difference between the two programs, the first one uses var-args while the second one doesn't. Have you thought about that?
Hi, Gz Portland
I think that's a case of constructor overloading.
In the first case the thread acquires the lock on the currently executing object i.e. 'this'. BTW it's 'synchronized' not 'Syn...'.
In the second case you can have code that is both thread safe and thread unsafe (if I may call it so) un the same method, moreover you can specify the object whose lock you want to acquire (by replacing the 'this' keyword with it).
To access a protected member of one class say c1 in a package say p1, from another class say c2 in another package (p2) you must make c2 inherit c1 (or another class in p2 that inherits c1).

Please correct me if I am wrong.
A collection must be sorted before it can be searched.
Like this:
System.out.println(Collections.binarySearch(list, "a"));

Correct me if I am wrong.
Taken from K & B (SCJP 1.6) page no.: 748 and 749:

This program contains two objects with threads: ThreadA contains the main
thread and ThreadB has a thread that calculates the sum of all numbers from 0
through 99. As soon as line 4 calls the start() method, ThreadA will continue
with the next line of code in its own class, which means it could get to line 11
before ThreadB has finished the calculation. To prevent this, we use the wait()
method in line 9.

Even it is stated that "As soon as line 4 calls the start() method, ThreadA will continue with the next line of code in its own class...". What I do not understand is, how can we be so sure?