Charandeep Singh

Ranch Hand
+ Follow
since May 06, 2007
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 Charandeep Singh

Hi All

I have a question regarding Java reflection API .
If I wish to call a method of a class which throws an exception via Java reflections how can I make sure the calling method gets the orignal exception thrown by the method and handles it accordingly ?
any suggestions .............

Here is an example

14 years ago
How many objects are created by the following two statements?

int[] a = new int[10];
int[][] b = new int[10][10];
14 years ago
How many objects are created by the following two statements?

int[] a = new int[10];
int[][] b = new int[10][10];
14 years ago
hey congrats
swati great going

16 years ago
Hi Palla

1. How does this serializability will be useful ?? I mean what are the practical aspects of serializability ??

Practical aspect of serializable is when you are using some variable of a class like dog in your case and you want to save the state of all the variables of class dog that so that what ever manipulations are done on dog object you have the original version saved with you. so now what you can do to for that is save that object and how do you do that in java it is done through use of Serializable interface so that when ever later on in the day you want to use that dog object which was initially created you can do that.

2. How do i use the Dog class in another code, so that serializability is applicable??

In some other class you will create an object of type dog and initialise all the other variables of that dog object. now when ever you want to serialize that dog object

to de serialize

3.What does defaultWriteObject() and defaultReadObject do? Please explain in detail!!

these are to make your serialization customizable
like in dog definition might be like this\
class dog implements Serializable

so now there might be a case that some objects defined in class dog are not serilzable (objects of other class are defined in class dog which do not implement serilzable) in that case you would like to customize the serilization the way you want to save the state of objects of a dog class .
for that scenario these two methods are provided which comes into picture in some other class serilize or deserilize objects of dog class these methods are automatically called .

I hope it clears your doubt about serilizable
don't set classpath using windows enironment variables
do it whn you are compiling you can set class path then
do that it will help you get good knowledge of classpath related issues in Java which is one important aspect of SCJP
congrats man great going
that's a really very good score
16 years ago
hey Nicole

If you target is SCJP
then you should be using notepad or something similiar like edit plus as your editor rather than Eclipse.
It will help you get good knowledge of stuff and also provide a good basis for the java development .
You will understand what I am trying to say when you use notepad as your IDE for writing code it will help you a lot in achieving your SCJP goal.
congrats chandra
you have always been a source of inspiration
great going dude
all the best

16 years ago
list < ? super String> list = new ArrayList <String>> ();

The above syntax says that the list is declared of type list and can take only objects of type String or super class of String.
and it has been initialized as an ArrayList which will accept only Strings in the list.
What is the problem in it ???

howcome a protected is less restrictive than default.

Protected is less restrictive than defualt cause the visibility of the object or method marked protected is visible outside the package to all the classes who extend that class . Where as default is limited to visibility just with in that package irrespective of whether the class is being extended by some other class out side package it won't b visible.
Hi Pankaj

In the above code
as we know that String is immutable
so what ever manipulations done in method

public static void method(String s){

will not effect what ever is done on the object passed .
and when you say
s = "New Instance";

you are actually changing the value of static variable of class Test14
String s = "Local";
the concept is called shadowing.

and when either of the value is passed thru your "method" method won't affect cause of String immutability.
and after that

s will print it's value which is Local
and t.s will print it's value which is New Instance.

so the output is Local New Instance

I hope I cleared your doubt

Dolly is correct

Answer is

D: End of method
java.lang.RuntimeException: problem

E: run:
java.lang.RuntimeException: problem
End of method

You cannot predict whether execution of main thread will occur first or the other thread .

Hi Dhwani

An Advice
If you are really looking forward to SCJP certification then use more of command line for compiling your java progs and notepad as your editor.
This will clear a lot of your fundas and help you with some basic issues.

How ever if you still want to compile using Eclipse which I would not recommend Right click on the java file.
Click on Run->Run->Arguments Tab
Over there in VM arguments place -ea and it should work

Hi Madhu repala

Make sure that when you run the program you have your assertions enabled
java -ea Threads

This will work fine then
by default assertions are not enabled you have to enable them

Hi anita dhar

You can always try and compile the prog and see the output
how ever there won't be any output
in fact it won't compile
cause in for loop
for (; i = 0; ++i)

i=0 is not correct it should actually result in a boolean value
which this doesn't
so the prog won't compile