Rashmi Jaik

Ranch Hand
+ Follow
since Oct 04, 2008
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 Rashmi Jaik

Since SCJP is a pre-requisite for other Sun certification exams, and hopefully it would be possible for some of us to take them as time and money permits, I'd go ahead with SCJP 6 and try to study for another exam.

I think SCJP6 certification would still be valid for the higher exams even when newer versions of Java are released (but you may want to verify this)

If you are not planning to take other Sun exams, then it might just be better to invest in reading material for SCJP 7 and then take it. Sometimes exam objectives change significantly or not much at all - some things may be dropped from older versions and some new things may be added.

Also, during job interviews, they usually tend to ask question from older SCJPs even dating back to 1.4 or 1.3 - so it wouldn't hurt to study the older versions too.

I find that it is helpful to go through a small set of exercises after reading about a concept, and in the sample chapter on Threads, they do have a set of challenging questions/exercises that really make us think - and this makes the concepts much clearer.

So far I've reviewed the first few pages of a sample chapter on Threads from this book:



Edit: removed things that were already mentioned
javac -source 1.4 -target 1.4 Test.java

Compiled this to pre-boxing version of Java

From #1 above , it looks like Short.valueOf() can take both short and byte primitive arguments, byte is widened to short primitive and then the valueOf , converts the short to Short.

But at #2 above, it fails to compile - because as you mentioned Byte and Short don't have any inheritance relationship between them.

This deduction is based on logic, and looking at the bytecode - not from the JLS
Yup, there doesn't seem to be a mention of the boxing conversion in 2 levels as discussed above

All I see is this:

byte to short, int, long, float, or double , so I guess byte primitive is directly converted to short primitive and then
public static Short valueOf(short s) , is called to convert the short primitive to Short object

this is what armando explained above

I'll try to see how this could be manually done prior to Boxing and Unboxing by compiling it with a previous version of Java

I don't know if looking at the bytecode helps

here's your code:

Compiled to create .class file

javac Test.java

The output of this gives
javap -classpath . -c Test

On both 1: and 6: above the bytecode looks identical

but I wish we could see more details in the bytecode, like primitive type conversions
Even after having years of experience with Java, doesn't give a satisfaction of being well-rounded in it because most usually at work - we focus only on certain parts of Java.

Studying for the SCJP certification makes us well-rounded in core Java.

SCJP is also a pre-requisite for taking additional Sun certification exams http://www.sun.com/training/certification/java/index.xml .

By reading SCJP books, I learned many things about Java that I wouldn't have known from just programming experience like:

- One interface can extend another interface. An interface can extend multiple interfaces.

- Polymorphism applies only to instance methods ( not static method and not instance or static variables)

and so many other things are in the books

Some of these may be covered in regular non-SCJP books , but an SCJP book is focused on the objectives of the exam which includes everything in core Java to make a well-rounded programmer.

I think for just passing the exam or even for getting a good score one book may be sufficient.

But really, you should look for books that are well suited for your understanding of Java - if you are a beginner then go for a book that covers the whys and the hows - if you already know a lot of basics and have years of experience then a book that may not cover the basics will be more understandable to read.

In college most students read only text books and that is sufficient to pass college tests and exams. but students are encouraged to read books other than text books - by doing this it is possible to get a deeper and better understanding of the subject from different perspectives.

One book cannot cover everything - there are also many online tutorials you can read to understand many basic things.

By reading more than one book or articles, and well-written online tutorials you'll be a much better programmer.

Just my 2 cents.

I have a lot of books so far, not much space to keep them - from now on I'm considering buying only electronic books to save storage space.
Thank you Ruben, for the clear answer it makes a lot of sense now.

From exercise 13.6 and also 13.8 from the book, and your explanation it is clear that just calling the run() method does not actually start the thread.

The thread will only be started asynchronously after calling start() on the thread, otherwise just calling the run() method is like invoking any other method.

For reference please see the sample chapter on Threads here: http://www.ii.uib.no/~khalid/pgjc3e/

I'm trying to understand the outcome of Exercise 13.6 posted in the sample chapter on Threads in the A Programmer's Guide to Java SCJP Certification - 3rd Edition

The output I get is that R2 is printed twice and R1b is printed once. I don't understand why R2 is being printed twice (instead of just once).

From logically thinking about the outcome, it appears that R2 is printed once (when the thread starts the first time, which invokes R2's run() asynchronously at some point)

then what causes R2 to be printed again?
Is it because of this line? :

because the code in the sample never called new Thread(new R1(),"|R1a|").start() , so the R1 thread will never start running.
so calling the run() method manually in R1 , is just that (it is not a thread execution) , so the current thread it prints is R2 ?

There's a good detailed explanation for this in the K&B SCJP6 book on page 671, in the section Method-Local Inner Classes

From reading the above section:

Method-Local inner classes are declared inside a method.

Variables declared inside a method reside on the stack ( not on the heap) and so, they are temporary.

But the object created from the Method-Local inner class can exist on the heap long after the method completes, so it needs to guarantee that whatever variables it is accessing still exist on the heap ( I think final variables declared inside a method exist permanently and that's why it can access only final variables and not regular variables declared inside the method.)

If the variable accessed inside the method-local inner class is a variable from the outer class (not a method variable) , it need not be declared final. The outer object's variables exist on the heap.

Only if the variable accessed in the method-local inner class is a variable declared inside the method, then that variable can be accessed only if it is final , otherwise the code throws a compiler error.

There may be a lot more differences in Java5 and Java6.

But as far as SCJP is concerned, the difference between SCJP 5 and 6 objectives, there's a few additions in SCJP 6 detailed here: http://faq.javaranch.com/java/ScjpFaq#16diff15 .

That's why everyone is recommending SCJP 6 over 5.
It would be really hard to compare two books, because the knowledge covered is different.

One of the replies I found useful while choosing which books to read is covered here:

excerpts from the section under: Contributed by Mike Van...
1. Go through one book at a time, don't skip around between books because it will confuse you.

7. Knowing why something works, makes it easier for us to remember the concepts, and an SCJP book written for beginners would cover this.

I was just reading the sample chapter on Threads from A Programmer's Guide to Java Certification, Third Edition - it is written in a clear manner and is easy to follow - I know a little bit about threads, but the fact that they book explains certain things like what causes IllegalThreadStateException , what exactly are daemon threads and what is the difference between user threads and daemon threads is explained well in a non-confusing manner.

Sample chapters : https://coderanch.com/t/432566/Programmer-Certification-SCJP/certification/FYI-Website-Programmer-s-Guide

While reading the above book a beginner to Threads has to read along, a few more pages to learn how to create Threads , and how a thread changes its state and then try out what is mentioned in the first few pages.

I'm also reading the K&B book, which covers so many things even an experienced programmer wouldn't know
- just based on programming experience. Like overriding hashCode and equals ( how they are related ) , and many tricky things that an experienced programmer wouldn't know.

I have a few older versions of a few SCJP books ( got to go and find them ).

This is from the sample chapter on Threads ( for SCJP ) from A Programmer's Guide to Java SCJP Certification - 3rd Ed book.

Threads have been explained very well in this chapter.

In section 13.3 The Main Thread there's a mention of what causes IllegalThreadStateException, most of the text is very easy to follow and try out with code

Based on what is mentioned in the sample chapter, I tried

See https://coderanch.com/t/432566/Programmer-Certification-SCJP/certification/FYI-Website-Programmer-s-Guide
for sample chapter on Threads (for SCJP)

Himalay Majumdar wrote:

I dont think rehashing is part of the exam, just knowing hashcode searches for a bucket and equals searches for the object inside the bucket will do the trick.

It is not part of the exam.
edit: Pages 585 and 586 do talk about this, but what they talk about is slightly different because they use a new Dog object ( and not the reference to the existing Dog object on the heap)

d.name = "magnolia";
that is System.out.println(m.get(new Dog("clover")));

as opposed to
d.name = "magnolia";

which have different meanings


I was reading this http://mindprod.com/jgloss/hashtable.html to understand more about HashMaps and Hashtables in java.

It appears that internally the Maps are rehashed when the load/capacity increases.

I guess at some unpredictable point (only when and if the load on the HashMap increases), the hash bucket for the key with d.name="magnolia" may change to correspond to 8, at that time the map would be able to return the value for this key.

But all this rehashing is unpredictable and only depends on the Map's load/capacity, it can't be relied upon, so it is not a good idea to change anything in the Map's key (object) after it has been inserted into the HashMap or Hashtable, because the value can't be retrieved in a predictable manner.