venu gopal

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

Recent posts by venu gopal

Hi Sagar,
Please write some code and clear your concepts. Try to take as many mock exams as possible.I will suggest you to follow Kathy and Bert certification book. They have described the exam scope very clearly. Learn from Dan's mock exams.(Don't worry about the score). Don't miss Marcus Green's mock exam.
Thanks and Regards,
Venu Gopal.
20 years ago
Hi all,
I have scored 96% in SCJP 1.4 on 08/23/2003. I have been participating in Javaranch discussions. I have been working in java since 5 years. I have decided to go for SCJP. I have followed Sun certified Programmer & Developer for java2 by Kathy Sierra, Bert Bates also. This book is excellent.

Cheers,
Venu Gopal.
20 years ago
Hi Amit,
Answers were wrong, even though explanations were correct.
Here are the correct answers
Which of the following statements are true?

1)You cannot be certain at what point Garbage collection will occur
2) Once an object is unreachable it will be garbage collected

Once an object is unreachable it will be subject to garbage collection but you cannot be certain it ever will actually be garbage collected. The garbage collection mechanism only applies to objects not primitives. You should be able to guess that garbage collection cannot ensure programs do not run ever run out of memory, but it does ensure that memory no longer required is reallocated to be available.
Which of the following statements are true?

1) finalize will always run before an object is garbage collected

Finalize will always be run before an object is garbage collected. It cannot run after it is collected because by then the object will cease to exit. When an object becomes unreachable it will be eligible for garbage collection but there is no guarantee when finalize will run, only that it will run before garbage collection happens. The final option is a passable description of destructors in C++ but not of the finalize method in Java.
Hi Brit,
Watch out this will generate runtime error???
public class Book{
private String title;
public String getTitle() {
return title;
}
public static void main(){ // public static void main(String args[])
Book b = new Book();
System.out.println("The title is " + b.getTitle());
}
}
Thanks,
Venu Gopal.
Hi Harvinder,
I think you can get your answer from this.
3.10.6 Escape Sequences for Character and String Literals
The character and string escape sequences allow for the representation of some nongraphic characters as well as the single quote, double quote, and backslash characters in character literals (�3.10.4) and string literals (�3.10.5).
EscapeSequence:
\ b/* \u0008: backspace BS */
\ t/* \u0009: horizontal tab HT */
\ n/* \u000a: linefeed LF */
\ f/* \u000c: form feed FF */
\ r/* \u000d: carriage return CR */
\ "/* \u0022: double quote " */
\ '/* \u0027: single quote ' */
\ \/* \u005c: backslash \ */
OctalEscape/* \u0000 to \u00ff: from octal value */
OctalEscape:
\ OctalDigit
\ OctalDigit OctalDigit
\ ZeroToThree OctalDigit OctalDigit
OctalDigit: one of
0 1 2 3 4 5 6 7
ZeroToThree: one of
0 1 2 3
It is a compile-time error if the character following a backslash in an escape is not an ASCII b, t, n, f, r, ", ', \, 0, 1, 2, 3, 4, 5, 6, or 7. The Unicode escape \u is processed earlier (�3.3). (Octal escapes are provided for compatibility with C, but can express only Unicode values \u0000 through \u00FF, so Unicode escapes are usually preferred.)


char b = '\61';//1 It's in the limit . It can be upto '\377'.
char c = '\061'; //2 It's in the limit . It can be upto '\377'.

Thanks,
Venu Gopal.
[ August 16, 2003: Message edited by: venu gopal ]
Hi shafkat,
The left most bit is always sign bit. If it is 0 the number is positive and if it is 1 the number is negative.
I will take 8 first
The binary represention is
0000 0000 0000 0000 0000 0000 0000 1000
Here sign bit is 0
I will take 0x80000000 i.e -2147483648
The binary represention is
1000 0000 0000 0000 0000 0000 0000 0000
Here sign bit is 1.
Let us discuss about your doubts.
example 1
--------------------------------------------------------
8 >> 1
binary representation:
---------------------
0000 0000 0000 0000 0000 0000 0000 1000 int is 32 bits long
after bit shift
---------------
0000 0000 0000 0000 0000 0000 0000 0100 Shifted by 1 bit
I know it's clear to you

example 2
----------------------------------------------
0x80000000 >> 4

binary representation
--------------------
1000 0000 0000 0000 0000 0000 0000 0000
1111 1000 0000 0000 0000 0000 0000 0000 <--- what happened here ?
Here we shifted 4 bits to right. The sign bit is 1. In right shifting left bits will be filled by sign bits.( Here 1 ).
If you perform right shift on 4
0000 0000 0000 0000 0000 0000 0000 1000
0000 0000 0000 0000 0000 0000 0000 0000 <--- what happened here ?
Here we shifted 4 bits to right. The sign bit is 0. In right shifting left bits will be filled by sign bits.( Here 0 ).
The result is
0000 0000 0000 0000 0000 0000 0000 0000 ----> Zero

Hope you understand???
Thanks,
Venu Gopal.
Hi Karan,
I think this will clear your doubt
class Test {
public static void main(String args[]) {
test(1<<30,"1<<30"); // Here 1 << 30 will be passed to the function
// 1 << 30 is 1 * 2 Power 30 i.e 0100 0000 0000 0000 0000 0000 0000 0000 i.e 1073741824


}
static void test(int i,String s){
if((i>>30)!=(i>>>1)){
// if((1073741824 >> 30) != ( 1073741824 >>>1)) {
// if( 1 != 1073741824)
System.out.println("(i>>30)--> "+ (i>>30));
System.out.println("(i>>>1)--> "+(i>>>1));
System.out.println("Not Equal");
}
}
}
[ August 13, 2003: Message edited by: venu gopal ]
Hi Marlene this is a great posting, thank you. It covers everything required for inner class instantiation. Could you please add for static and anonymous also?
[ August 13, 2003: Message edited by: venu gopal ]
Thank you Ray and Jim for clarifying my doubts.
Hi tangi I think Ray was trying to explain about abandoned object. If you would like to return the Sring you need to change the return type of go() as
public String go(){
return getDescription();
}


Now wf.go(); is abandoned object
I hope it clarifies your doubts.
Thanks,
venu Gopal.
Hi Rishi,
The method is expecting return statement. Either you must provide else part or include semicolon after if statement, to make compiler happy..

class Test {
public static void main(String[] args) {
Test t=new Test();
System.out.println(t.notReachable());
}
String notReachable() {
int i;
if(false)
return "String";

/*else
return "Str";
*/

}
}
String notReachable() {
int i;
if(false)
/*
; */

return "String";
}
Thanks,
Venu Gopal.
[ August 13, 2003: Message edited by: venu gopal ]
Hi all,
I have problem understanding the following. This is from Marcus Green Test
Given the following code, which of the options if inserted after the comment //here will allow the code to compile without error?

1. super().output(100);
2 new Wfowl().output(i);
3 class test implements Liz{}
4 System.out.println(sDescription);
5 new Wfowl();
6 getDescription();
Correct answers are 2,3,4,5,6.
Option 6 is an instance method. How could I call without instance? In addition to that It's a void method.
Thanks,
Venu Gopal.
[ August 13, 2003: Message edited by: Thomas Paul ]
Hi Cyril,
It's interesting. The result is
false
true
true
true
As long as the method didn't change the contents of a String it returns the same String without changing it's reference. Here s1 and s2 are pointing to different address and there is no change in the remaining strings.
public class EssaiString{public static void main (String args[]){ String s1 = "ABC";
String s2 = new String(s1);
String s3 = new String(s1);

System.out.println(s1==s2);
/* Referring to different strings */

System.out.println(s2.trim() == s2.toUpperCase());
/* s2.trim() doesn't change the string and s2.toUpperCase() doesn't change the string. It returns true. */

System.out.println(s3.concat("") == s3.replace('D','E'));
/* s3.concat("") doesn't change the string and s3.replace('D','E') doesn't change the string.(there is no D to replace). It returns true. */

String s4 = s1.toString();
/*s1.toString returns same string */

System.out.println(s4==s1);
/* s4 is refering s1 ("ABC"). it returns true. */
}
}
Cheers,
Venu.
Hi majohnad,
The answer is A and B