sandeep atluri

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

Recent posts by sandeep atluri

Hello all,

i have compiled a .java file and its compiled but when i run it, it says that "noclassdefinitionfounderror"
why do i keep getting this message.. please advice . urgent
17 years ago
hey guys...

there are 72 questions for the exam only....
but there will be some pre-assessment questions asking you to grade yourself for proficiency on the various topics involved in this exam... the time taken for this shall not be taken into account.
the real exam starts after the assessment you provide. the time for the exam is 2hrs 55 mins. i.e., nearly three hours....

but what told on to you people must be that the whole procedure of examination can go to a maximum of "3hrs something".....

thats it... real exam is only 2:55 mins...got it...
remaining time is given for reading the rules, assessment of your proficiency etc.,,,... the time taken for studying rules and regulations and assessment will not be counted in the 3:hrs slot....

got it

[ September 13, 2007: Message edited by: Burkhard Hassel ]

From Andrew:
Please quote your sources.

We have reason to believe this was from an illegal source. Since we do not have any information to the contrary, we have deleted this question. Further questions posted without source details may be deleted without any investigation.

Thanks, Andrew


[ September 13, 2007: Message edited by: Andrew Monkhouse ]
please don't post posts that are related to IDE'S...

post them in the respective section,....

thanks
hi there...

ArrayList implements List Interface, which extends the Collection Interface...

ArrayList has the add()method to add objects,primitives etc., to them...

so, there is nothing wrong with the code of your's... that's why its compiling..

understood...
hi As Angel...

lets first see your code...

in the first class your declared a method, which throws an Exception.
then you created a class that IS-A sub-class of the first class.
then in the sub-class, you declared an overloaded version of the method
declared in the first class.
this overloaded version does not throw any exception(As per your Calculation)

and you declared the main method as throwing an Exception
...
Now what happens ...?

At compile time, the compiler sees that an object is being referenced using a super type reference variable... and a method is being invoked on it.

so it checks if the method is present in both the classes. which is true.
and it comes to the conclusion that there is an overloaded version in the subclass.
now according to Inheritance, every class that extends from another class, inherits every variable,property that is supposed to be possessed by the super class... so the subclass unknowingly inherits the Exceptions declared by the superclass.
so.when a class inherits exceptions,it is supposed to throw them...so
we have to

1) either declare that the method (method of subclass)throws Exception.
OR
2) Enclose the invocation of the method in try/catch block.
OR
3) declare that the method throws an Exception

... Now did you understand why we declared that main throws an Exception.

Originally posted by Gaurav Bhatia:
Please check the sample code written below :

public class ReturnExample
{
private String normalExecution()
{
String result = "";
try
{
result = "Entered try block.";
return result;
}
catch(Exception e)
{
result = result + "Entered Catch block.";
return result;
}
finally
{
result = result + "Entered finally block.";
}
}

public static void main(String[] args)
{
ReturnExample example = new ReturnExample();

String result = example.normalExecution();
System.out.println(result);

}
}

Why is the result of the program being printed as �Entered try block�.
Although finally block gets executed but the returned value from the function call only contains the string value set in the try block and doesn�t includes the changes done in finally block.

Thanks!!



let's analyze this code of yours....

you created a String type reference variable named "result".... then you are assigning the value returned by the method "normalExecution()" to this reference variable "result".

now lets see..the method starts executing and we.... go into the try block......
now there's a Private Variable(local to the method)declared in the method...
this gets the value...."Entered try Block"....

now as soon as this step is reached... in the next step we are returning the
value stored in the result(local variable ) to the main method... and then the we enter the finally block...
the value of the String result(local variable) is again updated....
now... as per our calculations.... the result should be...

"Entering try Block"
"Entering finally Block.."

but we have got
"Entering try block" as the answer....

why....??


reason:

because we have returned the value of the local variable, result, as soon as it is modified to "Entering try Block", to the main... and this value will be assigned to the variable "result" in the main method...
in the next step...we asked the compiler to print the result variable(main method)...so we get the result as "Entering the try Block"


if we had placed the return statement in the try block, instead in the finally block.. we would have got the result...
"Entering try Block"
"Entering Finally Block."

understand....
hi there...

you asked... why mark the method as synchronized when we can use stringBuffer to make thread safe code.....???

Answer:

When we mark the method as synchronized, what happens is,the method is called atmost by one Object/thread at a time and until this thread is done using this particular method, no other thread can enter and use this method... kind of a queue....

in StringBuffer class all the methods are individually marked as synchronized....
now lets imagine a scenario when there are two threads executing simultaneously... each on different methods, but come to a point where they need a method to complete their execution.. creating a deadlock.....

"thread-safe" class will fail....

NOTE:
just because a class is described as "thread-safe, doesn't meant that it is always thread-safe"

.

besides why rely on classes when you can get away by just marking a single method as Synchronized....

if you want more ...read chapter 9: page 714 K&B..carefully...

good luck,.........
hey...

did you remember the first thing about class declarations....

a top level class can only be marked as public or default.
since.. in your question...

the second class is not a nested class....
so it cannot be marked anything except public or default....

if you declare the class as coderanch.. the compiler will say that the second class should be kept in a file named after its name(2nd class), not in the first class source file...

so the only choice you are left with is to keep the default modifier...

the 2nd question asked by you is..

whether it can be marked final or not...

now..let's see..if you had marked the NewTreeSet class as final....

then....

you cannot subclass it...
i.e., you cannot make the NewTreeSet2 class, a subclass of NewTreeSet class.
so as per your code... you cannot declare NewTreeSet as Final...

besides.... whats the use of keeping a class when you cannot use it???)


got it....
hi...

i haven't seen the scjp exam in the list of cert exams... this pearson vue provides...

anyway... find yourself a thomson prometric testing center and you can also write at NIIT centers(Prometric only.. not all NIIT centers have the Propetric privileges.) ..stop wasting time by seraching for alternatives

ok...
hi As Angel....

a class is an abstract model of a set or a group of things, having a basic set of qualities or properties....

you create instances of objects using the constructors provided by the class.

now...
any such class, if it has another class declared inside its signature... then the class declared inside is called the Inside class or the Inner class.
i.e., any class that is declared inside the curly braces of a previously declared class, is called the inner class to the outer class...

if you declare any new class outside the curly braces of an old class, then the class is not an inner class to the old class...
but if you declare this new class as...



then the newClass is a subclass of the oldClass... not an inner class of the
oldClass....

now ....

about instance variable's........

instance variable's belong to the Object created using the operator....

Instance variables are given default values..... irrespective of where its parent class has been declared....

the point is that they will always be auto initialized....

but local variables are not auto initialized....



understand....
Hai Anuj....

Don't get tense...
it happened with me also... once you solve quizes.. you feel confident
But when you take the MockExams.. you find it difficult...

Do this way... first go throw all the questions in the mock exam once(answer the easy question you encounter in your path). and then start solving the rest...
you should remember that the questions are actually not tough but they are very...very.... tricky and cunning...
run through the code twice andsee if the signatures are correct. i.e., syntaxes of methods.... declarations, assignments, logic, etc....
then you will find the trick in between them...

them main aim of giving lengthy code is to trick to....

remember...
the large the question...

the smaller will bw the trick and that will be recognized only when you carefully examine the code...

so before going to exams... pefect yourself in basics and anlyzation of the code... write as much code as you can and...take the mock exam(same case with final exam)...

you will see the results...immediately....
remember...analyze and understand....
hi samura...

you asked where did this line come from



you have mentioned as follows in your code line 8:



now lets see....

o1 is a reference of type Object and is referring to an Object of type
array(2D).
at Compile time the compiler sees the referencing variable type only... not the object type...
so it doesn't find anything wrong in converting an Object type into an array(which is also an Object)....
but at runtime... the compiler realizes that its going to cast a 2D array into a 1D.. which cannot be done... since objects are immutable...

thats why there is a runtime error....

but remember one thing ... Object's members are not immutable... i.e.,they can be changed...
so what we have to do is use the members to create a new array object of 1D and assign this object to be referenced by the 1D variable b2.....

so... that is why sreenivasan used a 2D casting...

see here....
he is saying...



instead of



Did you see the difference...

sreenivasan has used the members in the 1 slot of the two dimensional array...

but you are directly casting the Object itself.....which creates a Runtime exception i.e., an Unchecked Exception

One more difference:.....

in your code even if you use as follows...



you will get a Compile time error saying that an int is submitted when an int[] should have been submitted...

Explanation:

here you are casting an object type into a 1D object when a 2d object is expected...

you are creating a new object that will have the values of a specific column or row of a 2D array.... so for that purpose you have to access these values... retrieve them and then assign this values into a new Object that is of 1D type array and then make it referred to by .


understood...

i know it's a little complicated.... read it twice and compare it to the question and the errors you get and you will understand ...

ok...
any more queries and you can ask me by mail...ok... bye

understand...
[ August 19, 2007: Message edited by: sandeep atluri ]
hi...

You had it completely wrong....

the statement as in the book is as follows:

[B] relates to Wrapper Classes which, as we know, are marked final [/B]

.

let's see, what this sentence says:....

it says that toString() is a method that relates to wrapper classes...

and that these Wrapper classes are marked final.. i.e., you cannot subclass
them in anyway... which is true....

isn't it..>???

besides you should remember that we override the toString() method to tell the user of what the object does......
so in order to do such thing we have to override that particular method... which as per your Question states that's declared final.....
now we know that we cannot override a final method butwe have to use it .. as it was declared.... right..???...
so your assumption that toString() is marked final is wrong...

its the Wrapper classes that are marked final....

understood....
ok.