Help coderanch get a
new server
by contributing to the fundraiser

K Sujit

Ranch Hand
+ Follow
since Mar 23, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by K Sujit

I am planning to appear for SCJP next week. Can any one sell me the exam voucher at discounted rate at Mumbai?

Please mail me - esujithk @ yahoo.co.in

Thanks,
Sujit
15 years ago
yes, interfaces are public by default, just like top level classes must be either public or default.
Methods in interface are abstract and public by default.
and variabels are public static final, you can't explicitly give them other modifiers.
Thanks Stan James!

Let me ask you - Class.forName("DatabaseDriver"); is used with out assigning to any variable during DB access, I believe it is getting loaded to memory.

So if at compile time I know the driver name, would it be OK to use DatabaseDriver.class; instead of Class.forName

Sujit
18 years ago
That clears the issue fully. Thnx.
18 years ago
Thanks! Your correction to my code is appropriate.

I read the api, but couldn't find anywhere .class constant/method, there is something like object.getClass() that can return the Class, but what is this .class.
In which class is this defined.

Sujit
18 years ago
Thanks! Your correction to my code is appropriate.

I read the api, but couldn't find anywhere .class constant/method, there is something like object.getClass() that can return the Class, but what is this .class.
In which class is this defined.

Sujit
18 years ago
Thanks!
(A)
>>2. By using Class.forName() i.e. Class.forname("Test"). This method call >>returns an Object of type Class.
>>i.e. Class testClass = Class.forName("Test");

(B)
>>HttpServletRequest.class retrieves the Class object of HttpServletRequest.

I can write from B
HttpServletRequest hSR = HttpServletRequest.class
and from A
hSR = Class.forName("HttpServletRequest")
I guess both A) and B) are same because both give a 'Class object'.
Sorry, still I don't understand how they are different.

sujit.
18 years ago
Thanks!
(A)
>>2. By using Class.forName() i.e. Class.forname("Test"). This method call >>returns an Object of type Class.
>>i.e. Class testClass = Class.forName("Test");

(B)
>>HttpServletRequest.class retrieves the Class object of HttpServletRequest.

I can write from B
HttpServletRequest hSR = HttpServletRequest.class
and from A
hSR = Class.forName("HttpServletRequest")
I guess both A) and B) are same because both give a 'Class object'.
Sorry, still I don't understand how they are different.

sujit.
18 years ago
Hi all,
What is the difference between

Class.forName("appname"); and
HttpServletRequest.class;

Sujit
18 years ago
Hi all,
What is the difference between

Class.forName("appname"); and
HttpServletRequest.class;

Sujit
18 years ago
I don't understand how this can throw ClassCastException since the collection contains only instances of Test.


What will happen here? Will it compile?
if you don't want the exception to stop the vm. You can change you main as below

public static void main(String args[]) throws Exception{
Test7 t = new Test7();
try{
t.method();
}catch(Exception e){
System.out.println("Exception thrown at 'method()' caught in main");
}
System.out.println("Print");
}
The code should run properly without throwing any exception.

.equals method takes any object as argument, but if both the argument and the object on which the method was invoked doesn't match, it will return a false.

You can check whether both the objects(argument and the one on which the method was invoked) are same using instanceof operator.
May be because of the return 1; statement, I hope you won't get the compiler error if you remove that.

And then if you run it may return you 2. I don't understand how return 3; is going to behave.

Hope somebody will execute it and tell.