Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!

Sachin Tendulkar

+ Follow
since Sep 20, 2003
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 Sachin Tendulkar

Can you send me one invite if you still have it.. my id is
15 years ago
public static void main(String args[]) {
PassS p= new PassS();
void start() {
String s1= "slip";
String s2= fix(s1);
System.out.println(s1 + " " + s2);
String fix(String s1) {
s1= s1 + "stream";
System.out.println(s1 + " ");
return "stream";
Strings are IMMUTABLE
In the function fix(String s1) the parameter s1 is a reference to a new string. The s1 in the start and s1 in fix are different string objects. the s1 in fix is changed to
s1 = s1 + "stream"
so s1 in fix is now slipstream. and this is printed out first
fix returns a string "stream".
The function start assigns this to the reference s2.
All this while the s1 in start has not changed since strings are immutable. It still holds a reference to the value "slip"
So the println in start prints s1 + " " + s2 which gives the output
slip stream
Hence the output you see is
slipstream slip stream.
I think that all those who are postponing their exams because they are not getting a good score is a good thing. Doesnt it make more sense to really get a good score. That way you are really sure that you have the concepts and the basics right.
Only when you are consistently getting a good score in the mocks (and I truly believe that getting a score of over 90% in this exam is really easy) should one attempt the real exam.
I think everyone should be aiming to score well rather than just pass. My two cents
int a =-8;
int b=~-33;
above code prints -8 ,how?Can anybody please explain?
Is expression like 8>>-4 valid?how to solve questions that involve shifting with negative numbers?

Step 1) a>>=b is expanded to
a = (int) (a >> b)
Step 2) b = ~-33
= -(-33) - 1
= 33 - 1
b = 32
(remember ~x = -(x) - 1)
Step 3) a = (int) (a >> 32)
32 in binary is represented as
00000000 00000000 00000000 00100000
When shifting numbers if the type is int then the number of places to shift is denoted by the top 5 bits of the number to shift by
in this case the top 5 bits of 32 are 00000 which is 0
so in short the expression is reduced to
Step 4) a = (int) (a >> 0)
a = (int) a
a = -8
Yes the first bit of the number does denote the sign for all signed integral primitives. However it does not just denote the - or +. It does play a role in the magnitude or the value of a negative number. To get the actual value of a negative number you need to use the two's complement. this is done by reversing all the bits of that number and adding 1 to the result.
So if we have a number say -5. How would you denote the same in binary?
Assuming we want it to represent a byte
5 in binary is 0000 0101
Invert all the bits 1111 1010
Add 1 to the result 1111 1011 --> Thats negative 5.
As you can see that the first bit is 1. So we know its a negative number and its magnitude or value is known only after using two's complement.
So working backwards given a binary representation for a number we can get the decimal number as shown below.
Again we assume we have a byte.
Number given 1111 0011 --> Highest bit is 1, so negative
Invert all bits 0000 1100
Add 1 0000 1101 --> Thats 13
So the number given was -13.
Hope that helps.
Marker interfaces are like directives to the compiler. They do not have any methods. For example Serializable is a marker interface. If you wish to denote that your class is serializable then it should implement the Serializable interface. But there are no methods in this interface.
Similarly the interface Cloneable does not have any methods but if you want your class to be Cloneable it must declare so by implementing the Clonable interface.
Remeber the clone method is inherited from the Object class. So even though all classes have this method it can be used only if your class implements the Cloneable interface. Not doing so will result in CloneNotSupportedException being thrown.
I took the 1.4 exam. This exam does not cover I/O or AWT or event handlging.
For collections Kathy and Berts books is more than enough.
Threads can get tricky at times.
I would suggest Solve all the tests there.
16 years ago
HI Guys,
Just came back from the testing center. I missed out on one question in the threads section. The overall exam was easy.
I started studying for Java just a month back. I have no prior Java exeprience. I studied from Java Programming language by Arnold Gosling and Holmes. Referred to the JLS time to time. I used to hang out at the forum quite frequently and all the questions posed by the ranchers and their answers really did help me a lot.
I would also like to thank Dan Chisholm for his excellent site. I would recommend solving all his exams to get a good grasp of the fundamentals. The SCJP is not as tough so if you get a good score on Dans tests you can rest assured that you will score real big.
Marcus Greens exams are also very close to the level of the real eam
I used K&B's book for the Collection interfaces and wrapper classes. (read those two chapters when I was looking for your book in Borders ).
Next step SCWCD.
16 years ago
There is only one instance of the StrinfBuffer and its contents are the letter "A".
Three instances of the class InSync are created and each is passed a reference to this single StringBuffer.
The run method is synchronized on this StringBuffer object which is shared by all the three instances of InSync.
Only one thread can therefore execute the run method.
The run method prints the StringBuffer 100 times and then sets the first character of the StringBuffer to the next value ie. B in this case.
The next thread then does the same thing.
Hence the output.
In the example given the run method is being over-ridden. The original run method in Thread calls the run method of the Runnable interface if the thread is passed a Runnable object.
In this case the over-riding method changes the behaviour of the run method. It simply prints "A" and never calls the run method of the Runnable interface.
As a result at run time the over-ridden run method is called and prints A.
Sorry I just read the answer properly. It says that the valueOf menthod for Boolean class was introduced in ver 1.4. I was compiling my code with 1.3.
I would like to know if there are any other methods that were added to the Wrapper classes in 1.4
This question appears in one of Dans Tests
Question 9
class C {
public static void main(String[] args) {
Boolean b1 = Boolean.valueOf(true);
Boolean b2 = Boolean.valueOf(true);
Boolean b3 = Boolean.valueOf("TrUe");
Boolean b4 = Boolean.valueOf("tRuE");
System.out.print((b1==b2) + ",");
System.out.print((b1.booleanValue()==b2.booleanValue()) + ",");
What is the result of attempting to compile and run the program?
a. Prints: false,false,false
b. Prints: false,false,true
c. Prints: false,true,false
d. Prints: false,true,true
e. Prints: true,false,false
f. Prints: true,false,true
g. Prints: true,true,false
h. Prints: true,true,true
i. Compile-time error
j. Run-time error
k. None of the above
The answer provided is h. Prints: true,true,true
But there is no Boolean.valueOf(boolean) method. I think the answer should be compile-time error. I tried compiling and I get the same error. I have an exam tomorrow. Can anyone verify the same?
according to JPL
The tokenizer is greedy. It grabs as manu characters as it can to build up the next token, not caring if this creates an invalid sequence of tokens. So becase ++ is longer than +
j = i+++++i;
is interpreted as j++ ++ +i; //INVALID
so in your case
a=b*c+++++d-----4*20; is this possible ?
this is treated as
a=b*c++ ++ + d-- -- -4*20 .. invalid
I am confused here. I always believed that a subclass cannot access the protected variable of its superclass. Can anyone please explain how this works here.