Piotr Kaluski

Greenhorn
+ Follow
since Jan 31, 2003
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 Piotr Kaluski

Hi,
The compiler allows you to assign values to variables without casting, providing that the assigned value is known at the compile time and the value is in the range of the variable type.
Examples:
The code:
int i = 1;
byte b = i;
will not compile. Explicit cast needed.
The code:
byte b = 125;
will compile. Assigned value is known at compile time.
The code
b = 200;
should not compile. Range for byte is -128..127.
Hope that helps
Were can I find the source code for JDK?
Yes, it does.
There is a constructor for Boolean which takes a literal. If the literal is "True" (case does not matter), the object wraps true. If it is something else (like "abcd") the object will wrap "false".
Hi,
The time you are going to need for preparation depends on your background. I have a strong C++ background (which works for my advantage). Apart from that I have 2 children (2.5 and 0.25 year old) which does not work for my advantage .
I have written a small application in java. That was my experience before I started learning. It took 2 months to prepare. In most weeks I had only weekends available. So in average I spent something like 5 hours a week. And I passed with 93%.
If you don't have C, C++ or java experience, then it will probably take you much more time than that.
Hi Frank,
First of all - guys, please do indent your code. It will make understanding your questions much simpler.
As for the questions. Yes, the code presented is a classical example of the code which may cause deadlocks. Let's call threads thr1 and thr2. Imagine the following scenario. Thr1 starts and gets the exclusive lock on s1 (this is what synchronized(s1) means). It is just about executing the line "synchronized(s2)" but then JVM decides that the next thread (thr2) should have a chance to run. So it takes cpu away from thr1 and starts thr2. Thr2 gets exclusive lock on s2 and then tries to get an exclusive lock on s1. But s1 is already owned by thr1. So thr2 waits on attempt of getting the lock on s1. When CPU is given to thr1 again it tries to get a lock on s2. But it is locked by thr2. So thr1 waits. And this is the deadlock. Thr1 is locking s1 and is waiting for thr2 to release the lock on s2 and thr2 is locking s2 and is waiting for thr1 to release the lock on s1. Both threads are blocked so none of them can actually release the locked resource.
The behaviour depends on implementation of threads on a particular platform. There are 2 ways of scheduling threads (deciding which thread to run) - time sliced and preemptive. Preemptive means each thread, while given CPU, runs to its end. Other threads have to white for this thread to finish. Time sliced means each thread will get CPU for a certain amount of time. When the time is over, CPU is given to another thread. As you see, the deadlock is more likely to happen in the time sliced case. For preemptive scheduling, each thread will do its stuff to the end and they will not interfere with each other.
Hope that helps.
Hi,
Sybex mock tests are less difficult than the real test. The toughness of the real test comes from subtle differences between some possible answers. In Sybex tests, in most cases the right answer is so "right" and false answers are so "false" that you don't have doubts. This is not the case on the real exam. I highly recommend mocks below:
http://www.danchisholm.net/dec04/index.html. See my "Thank you Dan" post for more details.
Good luck.
Hi,
I passed java 1.4 programmer with 93%.
I placed my thanks to Dan Chisholm in the subject because his mock tests helped me so much.
I highly recommend those mocks tests to anyone preparing to pass the test.
The area of strength of those tests are:
* It offers topic exams - series of exams related to the particular topic. Answers to each set of questions are very helpfull, and they can be a learning resource by itself.
* Questions on the topic are build in a way, that you can focus on the topic and can easily identify what is you don't know
* The code is carefully indented (which is not the case for some mock tests)
* The level of difficulty is equal or even higher then that of the real exam.
* You can easily print it (both questions and answers are grouped together)
Some additional comments about other mocks. If you want to learn quickly don't take Parikosh mock test www.parikosh.com. It is nothing personal. No doubt this guy knows java very well. But there are some points, which make his test not worth time when time is a constraint:
* Casual indentation - The code is difficult to read
* Some complexity of questions does not come from the complexity of the topic but from using misleading naming conventions (for example object and its member have the same name).
If are good at java and need another proof that you are an expert - take it.
If we want to prepare efficiently to the java test - don't

As for another resources - Sybex book for Java Certificate is good. Read first 8 chapters (240 pages). Note - difficulty of sample questions in this book is lower than those in the real test.
If in doubts about some subtleties, use Eckel's "Thinking in Java"
Do some programming yourself - for Threads, Collections, Inner Classes
Good luck.
21 years ago
In addition to an answer given by R Manivannan, it is worth noting than you can access i in Child class using explicit cast:
System.out.println(((Child)p).i);