It took me 3 weeks to prepare for the Java 6 exam, I have 0 professional Java programming experience. For someone who uses the language daily (like a java programmer) it should be even easier. I was very excited to get it over with as soon as possible, so I ordered the Kathy Sierra SCJP Sun Certified Programmer for Java 6 Study Guide at http://www.amazon.com/SCJP-Certified-Programmer-Java-310-065/dp/0071591060 and one day shipped it to me so that I received it on a Saturday. As soon as it came, I started reading. That took about two weeks as the book is an 800 page monster with some self tests in the book that both give you good practice and teach you some specific details that the book did not mention in the actual chapter (a lot you can guess but not all...). For the last week I reviewed all the 2 Minute Drills and re-read the chapters that were API heavy. Also there are a lot of tables (important string methods, thread methods, file API methods, and concurrency). I also took the two master exams included in the book. I took them in study mode and attempted the question, then if it said wrong, I went and tried to figure out why it is wrong, then I went to the reference/hints if I needed. On the day of the exam I reviewed the File/String/Collections API an hour prior to the exam and took it.
I scored 90% so that's GREAT considering I do not have any Java work experience at all and prepared in 3 weeks. It should be much easier for any professional Java developer to prep/take. Although I have known of Java since it came out, and I used it for the occasional graduate and undergraduate program in college so I'm not totally new. Also, I know other C languages so I am used to much of the control structures, etc... However if I can figure out the API/language workings in three weeks enough to get a 90% any experienced java programmer should have no problem figuring out enough to pass. Still that book is giant, the 2 hours of daily train riding to work was a big help in getting the reading done.
Some people say you have to write a hundred small programs to figure things out. But that book is pretty good on details. The most important thing to write programs about (maybe I wrote 10) are the constructors/initializer blocks/static initializer blocks/to find out exactly what is inherited and to cement the order. And when casting a sub class as its parent, it is important to see what happens when you access the variables/overloaded methods. While the overloaded methods are simple and what is expected, accessing variables is not so straight forward. Trust me, write a few programs about it, especially where the super type/sub type have instance variables with the same name.
I think the main thing I got out of SCJP is a broad overview of the language. Java is a beast, the API/language is huge. Typically I just used the parts of the language I needed for each project/activity in Java and looked up the API as I went. Some key words (like transient) I just did not know. Also some interview trivia (like if you override equals what else must you override) I did not know (at least according to what a friend told me). Also I had no idea about things like the internationalization classes Locale, Calendar, DateFormat, NumberFormat, and Date. Really if I was writing serious Java software, I would probably use Calendar for date arithmetic needs. I don't think it will help me land a Java job as everyone seems to want Java experience prior to even giving you an interview. But if I ever do get an interview, the knowledge I gained from preparing the exam would definitely help me to better answer the questions (though I'm sure a lot of the specific API details will fade with time). Also now I feel more confident with Java. Still I can't say that I can just whip up a Java program on the white board that fully works because the API is very complex. A language like C is pretty small, include stdio.h/stdlib.h/string.h and memorize 30 functions and you can do a lot. Java has way more packages/classes to include and way more API. Also with expressions there are a ton of rules, promotions, casting, autoboxing, etc. which would be really easy to mess up. Though C has precedence hell, with the right parenthesis you can get away with a lot. Java is more strict on things (ie if(0) is an error). But the exam is worth it just for some additional trivia, although the exam is a bit frustrating, and if you look at the book it pretty much tells you that the exam deliberately picks tricky questions and edge cases in an attempt to confuse you. It will deliberately give bad indentation and other stuff to try to be tricky. I hate that because rather than focusing on you knowing the material reasonably, it focuses on trying to confuse you.
One thing of note, don't get thrown by the Master exam. I tried to take one in exam mode, and they gave 75 questions in 1.5 hours and I nearly decided to postpone the exam. The real exam is 60 questions and you get 3 hours. Also the questions on the actual exam are MUCH easier than on the master exam. My master exam score was 37%.... My last two times I just did it in study guide mode, attempted each question/if answer was wrong tired again/viewed reference once with the A exam and once with the B exam... I did fine on the exam and I am really really happy that I did not postpone it over the study guide, because now it is over and I can relax....
Hi ankit i assume you are trying to learn some basic concepts of multithreading.
try to get hold of some good online tutorials :http://www.javaworld.com/jw-04-1996/jw-04-threads.html
or try some basic good book. http://www.amazon.com/SCJP-Certified-Programmer-Java-310-065/dp/0071591060/
The program you wrote actually doesn't need synchronization as there is only one thread (main). I know you are just trying your hands, therefore giving some insights. Even if you correctly called wait method on args(args.wait()) or synchronized on Thread.currentThread your thread may goes into indefinite wait (making your program unresponsive) because there is no other thread to notify your main thread.
Yes you can, and as long as you don't extend this class, you don't have to implement any methods.
Abstract class AbstractClass extends ConcreteClass{
public abstract void method();
}
class ConcreteClass {
public void doSomething(){
}
}
in the AbstractClass you don't have to implement the doSomething method, and in the ConcreteClass, you don't have to implement the method().
It would be better if you just try it yourself, and I recommend you to read this book
http://www.amazon.com/SCJP-Certified-Programmer-Java-310-065/dp/0071591060
I have a little book with "Exam Cram" in its title. The emphasis is on "little;" you can read through it in a single evening. It describes in prose all the important features of Java, it contains tables of quick facts that will be essential, and it covers, briefly, all of the SCJP exam.
For the less than eidetic, it gives hints on how to write yourself a crib sheet from memory once the test starts (meaning you can carry a bit of what you need to know in short-term memory). There are also some tips on pitfalls and such. Finally, and perhaps most importantly, there is at least one practice exam in it (haven't looked at it in a while) and a bunch of drill questions.
Some people would (and in fact did) recommend buying a general purpose Java book. Ideally, all you should have to do is learn "all of Java" and then you'd be ready for the exam. But this is not a winning strategy!
related anecdote
The first time I took my driver's test with the DMV, I had a long wait and quickly skimmed through a little info booklet they provided. I easily scored 100.
I later had to take the test again. Knowing the test was laughably easy, I spurned the booklet and failed the theoretical test. The booklet didn't contain anything I didn't already know: But being by the same people who administer the test, it contained the same wording, it had similar situations from the test, it emphasized similar topics and situations. In a few minutes, it could easily make the difference between passing and failing.
Conclusion
Same approach with these "prepare for test XXX" books. It's a racket, but the special-purpose prep books work better at preparing you for the test than general knowledge (or general knowledge books) do.
Sleeping is used to delay execution for a period of time, and no locks are
released when a thread goes to sleep.
A sleeping thread is guaranteed to sleep for at least the time specified in
the argument to the sleep() method (unless it's interrupted), but there is
no guarantee as to when the newly awakened thread will actually return to
running.
The sleep() method is a static method that sleeps the currently executing
thread's state. One thread cannot tell another thread to sleep.
The setPriority() method is used on Thread objects to give threads
a priority of between 1 (low) and 10 (high), although priorities are not
guaranteed, and not all JVMs recognize 10 distinct priority levels—some
levels may be treated as effectively equal.
If not explicitly set, a thread's priority will have the same priority as the
priority of the thread that created it.
The yield() method may cause a running thread to back out if there are
runnable threads of the same priority. There is no guarantee that this will
happen, and there is no guarantee that when the thread backs out there
will be a different thread selected to run. A thread might yield and then
immediately reenter the running state.
The closest thing to a guarantee is that at any given time, when a thread
is running it will usually not have a lower priority than any thread in the
runnable state. If a low-priority thread is running when a high-priority thread
enters runnable, the JVM will usually preempt the running low-priority
thread and put the high-priority thread in.
When one thread calls the join() method of another thread, the currently
running thread will wait until the thread it joins with has completed. Think
of the join() method as saying, "Hey thread, I want to join on to the end
of you. Let me know when you're done, so I can enter the runnable state."
I thought protected fields and methods are
visible to the children even if the latter are in a different package.
That's correct. The class itself has an access to the inherited protected members. But, what you're trying to do it to call the getHeight method on some Control reference. You're allowed to call it only on this instance!
But what does it mean for a subclass-outside-the-package to have
access to a superclass (parent) member? It means the subclass inherits
the member. It does not, however, mean the
subclass-outside-the-package can access the member using a reference
to an instance of the superclass. In other words, protected =
inheritance. The subclass can see the protected member
only through inheritance.
It took me 3 weeks to prepare for the Java 6 exam, I have 0 professional Java programming experience. For someone who uses the language daily (like a java programmer) it should be even easier. I was very excited to get it over with as soon as possible, so I ordered the Kathy Sierra SCJP Sun Certified Programmer for Java 6 Study Guide at http://www.amazon.com/SCJP-Certified-Programmer-Java-310-065/dp/0071591060 and one day shipped it to me so that I received it on a Saturday. As soon as it came, I started reading. That took about two weeks as the book is an 800 page monster with some self tests in the book that both give you good practice and teach you some specific details that the book did not mention in the actual chapter (a lot you can guess but not all...). For the last week I reviewed all the 2 Minute Drills and re-read the chapters that were API heavy. Also there are a lot of tables (important string methods, thread methods, file API methods, and concurrency). I also took the two master exams included in the book. I took them in study mode and attempted the question, then if it said wrong, I went and tried to figure out why it is wrong, then I went to the reference/hints if I needed. On the day of the exam I reviewed the File/String/Collections API an hour prior to the exam and took it.
I scored 90% so that's GREAT considering I do not have any Java work experience at all and prepared in 3 weeks. It should be much easier for any professional Java developer to prep/take. Although I have known of Java since it came out, and I used it for the occasional graduate and undergraduate program in college so I'm not totally new. Also, I know other C languages so I am used to much of the control structures, etc... However if I can figure out the API/language workings in three weeks enough to get a 90% any experienced java programmer should have no problem figuring out enough to pass. Still that book is giant, the 2 hours of daily train riding to work was a big help in getting the reading done.
Some people say you have to write a hundred small programs to figure things out. But that book is pretty good on details. The most important thing to write programs about (maybe I wrote 10) are the constructors/initializer blocks/static initializer blocks/to find out exactly what is inherited and to cement the order. And when casting a sub class as its parent, it is important to see what happens when you access the variables/overloaded methods. While the overloaded methods are simple and what is expected, accessing variables is not so straight forward. Trust me, write a few programs about it, especially where the super type/sub type have instance variables with the same name.
I think the main thing I got out of SCJP is a broad overview of the language. Java is a beast, the API/language is huge. Typically I just used the parts of the language I needed for each project/activity in Java and looked up the API as I went. Some key words (like transient) I just did not know. Also some interview trivia (like if you override equals what else must you override) I did not know (at least according to what a friend told me). Also I had no idea about things like the internationalization classes Locale, Calendar, DateFormat, NumberFormat, and Date. Really if I was writing serious Java software, I would probably use Calendar for date arithmetic needs. I don't think it will help me land a Java job as everyone seems to want Java experience prior to even giving you an interview. But if I ever do get an interview, the knowledge I gained from preparing the exam would definitely help me to better answer the questions (though I'm sure a lot of the specific API details will fade with time). Also now I feel more confident with Java. Still I can't say that I can just whip up a Java program on the white board that fully works because the API is very complex. A language like C is pretty small, include stdio.h/stdlib.h/string.h and memorize 30 functions and you can do a lot. Java has way more packages/classes to include and way more API. Also with expressions there are a ton of rules, promotions, casting, autoboxing, etc. which would be really easy to mess up. Though C has precedence hell, with the right parenthesis you can get away with a lot. Java is more strict on things (ie if(0) is an error). But the exam is worth it just for some additional trivia, although the exam is a bit frustrating, and if you look at the book it pretty much tells you that the exam deliberately picks tricky questions and edge cases in an attempt to confuse you. It will deliberately give bad indentation and other stuff to try to be tricky. I hate that because rather than focusing on you knowing the material reasonably, it focuses on trying to confuse you.
One thing of note, don't get thrown by the Master exam. I tried to take one in exam mode, and they gave 75 questions in 1.5 hours and I nearly decided to postpone the exam. The real exam is 60 questions and you get 3 hours. Also the questions on the actual exam are MUCH easier than on the master exam. My master exam score was 37%.... My last two times I just did it in study guide mode, attempted each question/if answer was wrong tired again/viewed reference once with the A exam and once with the B exam... I did fine on the exam and I am really really happy that I did not postpone it over the study guide, because now it is over and I can relax....
Hi ankit i assume you are trying to learn some basic concepts of multithreading. try to get hold of some good online tutorials :http://www.javaworld.com/jw-04-1996/jw-04-threads.html
or try some basic good book. http://www.amazon.com/SCJP-Certified-Programmer-Java-310-065/dp/0071591060/
The program you wrote actually doesn't need synchronization as there is only one thread (main). I know you are just trying your hands, therefore giving some insights. Even if you correctly called wait method on args(args.wait()) or synchronized on Thread.currentThread your thread may goes into indefinite wait (making your program unresponsive) because there is no other thread to notify your main thread.
Yes you can, and as long as you don't extend this class, you don't have to implement any methods.
in the AbstractClass you don't have to implement the doSomething method, and in the ConcreteClass, you don't have to implement the method(). It would be better if you just try it yourself, and I recommend you to read this book http://www.amazon.com/SCJP-Certified-Programmer-Java-310-065/dp/0071591060
Thanks, Khalil.
I have a little book with "Exam Cram" in its title. The emphasis is on "little;" you can read through it in a single evening. It describes in prose all the important features of Java, it contains tables of quick facts that will be essential, and it covers, briefly, all of the SCJP exam.
For the less than eidetic, it gives hints on how to write yourself a crib sheet from memory once the test starts (meaning you can carry a bit of what you need to know in short-term memory). There are also some tips on pitfalls and such. Finally, and perhaps most importantly, there is at least one practice exam in it (haven't looked at it in a while) and a bunch of drill questions.
Alas, from what I see at Amazon, the book I recommended only covers Java 2: http://www.amazon.com/Java-Exam-Cram-310-025/dp/1576102912 Still, there are bound to be similar, more timely books.
This one: http://www.amazon.com/SCJP-Certified-Programmer-Java-310-065/dp/0071591060/ref=sr_1_1?ie=UTF8&s=books&qid=1261601183&sr=1-1 by Kathy Sierra is similar and about Java 6.
Some people would (and in fact did) recommend buying a general purpose Java book. Ideally, all you should have to do is learn "all of Java" and then you'd be ready for the exam. But this is not a winning strategy!
related anecdote
The first time I took my driver's test with the DMV, I had a long wait and quickly skimmed through a little info booklet they provided. I easily scored 100.
I later had to take the test again. Knowing the test was laughably easy, I spurned the booklet and failed the theoretical test. The booklet didn't contain anything I didn't already know: But being by the same people who administer the test, it contained the same wording, it had similar situations from the test, it emphasized similar topics and situations. In a few minutes, it could easily make the difference between passing and failing.
Conclusion
Same approach with these "prepare for test XXX" books. It's a racket, but the special-purpose prep books work better at preparing you for the test than general knowledge (or general knowledge books) do.
Rules of Sleep, Yield and Join
Sleeping is used to delay execution for a period of time, and no locks are released when a thread goes to sleep.
A sleeping thread is guaranteed to sleep for at least the time specified in the argument to the sleep() method (unless it's interrupted), but there is no guarantee as to when the newly awakened thread will actually return to running.
The sleep() method is a static method that sleeps the currently executing thread's state. One thread cannot tell another thread to sleep.
The setPriority() method is used on Thread objects to give threads a priority of between 1 (low) and 10 (high), although priorities are not guaranteed, and not all JVMs recognize 10 distinct priority levels—some levels may be treated as effectively equal.
If not explicitly set, a thread's priority will have the same priority as the priority of the thread that created it.
The yield() method may cause a running thread to back out if there are runnable threads of the same priority. There is no guarantee that this will happen, and there is no guarantee that when the thread backs out there will be a different thread selected to run. A thread might yield and then immediately reenter the running state.
The closest thing to a guarantee is that at any given time, when a thread is running it will usually not have a lower priority than any thread in the runnable state. If a low-priority thread is running when a high-priority thread enters runnable, the JVM will usually preempt the running low-priority thread and put the high-priority thread in.
When one thread calls the join() method of another thread, the currently running thread will wait until the thread it joins with has completed. Think of the join() method as saying, "Hey thread, I want to join on to the end of you. Let me know when you're done, so I can enter the runnable state."
http://www.amazon.com/SCJP-Certified-Programmer-Java-310-065/dp/0071591060
That's correct. The class itself has an access to the inherited protected members. But, what you're trying to do it to call the
getHeight
method on some Control reference. You're allowed to call it only on this instance!For a better understanding, let me quote Kathy Sierra's SCJP Preparation Guide: