Hennry Smith

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

Recent posts by Hennry Smith



The output here is
Ozymandias
null




can someone explain whats happening in this program .....

Javin Paul wrote:
are you aware of stack trace ?
Whenever a thread calls a method it put it into its stack and when an Exception get thrown it unwind this stack until Exception get caught or until thread dies. this stack trace is useful to find out where exactly problem lies. just run your program with some other String "Symbiosis" and you will know why need to print stack trace.



in the above program we have made a "comparestring" method and passed a string parameter to it and now if the string str matched with "Symbiosis" it prints string are equal otherwise it throws a exception. now in main method we have called "comparestring" with "arg[0]" as argument......how we have used arg[0] to match it with "Symbiosis" and please explain the below code....according to me we have made a "nomatchexception" class and extends exception class....
then we have declared a nomatchexception method and passed strind parameter to it and then why we have super(meaasge) here......i know super is used to call the parent class...but here what message it will print here.....???



also if i am wrong somewhere..please tell....
thank you so much for your previous reply.....

why we have used "printStacktrace()" in this program.....???
Define An Exception Called "NoMatchException" That Is Thrown When A String Is Not Equal To "Symbiosis". Write A Java Program That Uses This Exception?

please someone tell me if the serialization have been removed from the syllabus or not.......one of my friend told me that it has been removed.....

please someone tell me if the serialization have been removed from the syllabus or not...as it is mentioned in the oracle website....but one of my friend told me that it has been removed.....



Develop code that serializes and/or de-serializes objects using the following APIs from java.io: DataInputStream, DataOutputStream, FileInputStream, FileOutputStream, ObjectInputStream, ObjectOutputStream and Serializable.



Meena Ajay wrote:Hi Hennry ,

As given in the answer from K&B,Did you catch the static initializer block given at the end of the code - line 19.?

After the line 4. executes, the value of x is set to 7.Since there is a static initializer block ( given in line number 19.), this would be the next thing to run. So, the value of x would be incremented to 8 after the static initializer block executes.

Now, the code enters the for loop with value of x having 8.After the x++ at line 8. is executed, the value of x becomes 9 and this enters the switch and case 9: would be executed. As per the looping logic, D is the answer"9 10 10 d 13 "

Hope this helps.



Thank you so much....i got your answer...


And given that line 7 will assign the value 0, 1, or 2 to sw, which are true? (Choose all that apply.)
A. Compilation fails
B. A ClassCastException might be thrown
C. A StackOverflowError might be thrown
D. A NullPointerException might be thrown
E. An IllegalStateException might be thrown
F. The program might hang without ever completing
G. The program will always complete without exception



Answer:
D and F are correct. Because i was not initialized, case 1 will throw an NPE. Case 0 will
initiate an endless loop, not a stack overflow. Case 2's downcast will not cause an exception.




Please explain this question ...which exception will b thrown and why....???


What is the result?
A. 9 10 d
B. 8 9 10 d
C. 9 10 10 d
D. 9 10 10 d 13
E. 8 9 10 10 d 13
F. 8 9 10 9 10 10 d 13
G. Compilation fails

Answer:
D is correct. Did you catch the static initializer block? Remember that switches work on
"fall-thru" logic, and that fall-thru logic also applies to the default case, which is used when
no other case matches.
A, B, C, E, F, and G are incorrect based on the above.


Please tell how D is correct...???



According to me in line 3 we have declared a static variable x=7, then we have used a for loop,so according to the for loop it will run thrice,so the value of x will be increased 3 times, as we run the loop first time the value is increased from 7 to 8 and matched with switch (case 8) so first 8 should be printed....but the answer is 9 10 10 d 13....please explain where i am wrong....also tell why 10 is printed twice....???
1.

please explain how we have used index here....like row and column....i know about this we have an array, a, with two rows and four columns.

// Two rows and four columns.

but what about the 1. as in that we don't have actual index provided....what will be the index in that.....


What is true?
A. One of them will compile, only one will be true
B. Two of them will compile, only one will be true
C. Two of them will compile, two will be true
D. Three of them will compile, only one will be true
E. Three of them will compile, exactly two will be true
F. Three of them will compile, exactly three will be true

Actual answer:
Answer:
D is correct. Fragments F2, F3, and F5 will compile, and only F3 is true.

A, B, C, E, and F are incorrect. F1 is incorrect because you can’t compare a primitive to
an array. F4 is incorrect syntax to access an element of a two-dimensional array.

please explain each of this in detail....i am confused in array...

Look carefully! You might be tempted to think the output is b is false
but look at the boolean test in line 12. The boolean variable b is not being compared to
true, it's being set to true, so the println executes and we get b is true . The result
of any assignment expression is the value of the variable following the assignment. This
substitution of = for == works only with boolean variables, since the if test can be done
only on boolean expressions. Thus, this does not compile:

Because x is an integer (and not a boolean), the result of (x = 0) is 0
(the result of the assignment). Primitive ints cannot be used where a boolean value is
expected, so the code in line 8 won't work unless changed from an assignment (=) to an
equality test (==) as follows:



please expalin this line"The result
of any assignment expression is the value of the variable following the assignment"..... i am somehow confused with this line....