Win a copy of Rust Web Development this week in the Other Languages forum!

Dhananjay Deshmukh

Greenhorn
+ Follow
since May 22, 2015
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
3
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Dhananjay Deshmukh

Tapas Chand wrote:You should execute the javac command from the parent directory of the package, not from within the package.


Paweł Baczyński wrote:By the convention, package names should begin with lower-case and class names should not contain underscores.


Please follow these instructions.



Yes i will keep that in mind. Thanks for this, It never occurred to me that since this is under the package i should use the command this way. Following is the output i get now :
6 years ago

Paweł Baczyński wrote:Please post your folder structure and a commend you use to compile.

I compiled your code and it works fine.

By the convention, package names should begin with lower-case and class names should not contain underscores.



I have attached the screenshot for the directory structure and following is the command i use:


Sorry i m late to reply, had an interview.
6 years ago
So i m basically using Linux as OS and terminal to compile and run project. I also have eclipse installed just in case to understand. So i was just trying a simple inheritance programs. Below is the code:
Whenever i execute above program through terminal, I get following error:


However, whenever i execute the above programs in eclipse i get the correct output. I m confused as to why am i not getting the output from terminal. All the package and class i have included are correct. Please help me understand why JVM shows error
6 years ago

Marcus Biel wrote:If the book is to though, you are to weak, sorry.

Start reading Head First Java then.

The exam is tough, the book condensed to the maximum. Make notes, read it several times.

Also, just thinking about it, my Free Java Beginner Video Course is based on all my knowledge I gained from Kathy's books and the certificate.
Whenever possible I go deep down into details which are also important for the certification. Might be helpful for you, too.



Nothing was never too tough for me, it was only hard because i didn't even read java from past 4 years, not a single word. That's why i had to brush up my skill with basics from beginners guide. But this was like month back. I have already finished the OCAJP part - 1 of Kathy. But then i do get the message you wanted to give. Right now i m on binge study kinda thing. And thanks for the video tutorials, i will go through it too.
6 years ago

Marcus Biel wrote:


According to the website



I don't know which website you are talking about. I assume you are talking about the Oracle website, in this case, probably yes.
Additionally, you write "I have all the material". Well that might sound stupid, but more often then not people think possessing something is actually doing the trick - including me and myself ;-).
Really, be honest to yourself. Read Kathy's book, read every line of it. I once read the advice that you would be ready if you had a book full of colored highlighting that would fall apart you would be ready.
I did that. I was there. I even bought a new version (updated from Java 5 to 6) and that one in the end was just as colored and falling apart.
I did all mock exams I could get my hands on, and all simulators. I passed all of them above 90% or so as far as I can remember.
I have actually even now recently bought version 7 of the now called OCA/OCP book you probably have, I didn't yet have the time to read it, however mainly I just wanted to own it.
I love Kathy's books. And you can trust her. Everything that is in the book you will need. Everything that is not in the book, you will not need.
At the time in 2008 when I did my SCJP, I didn't even waste any time looking on any Oracle pages. Trust Kathy. That's all you need!

Was that clear enough?

p.s.: Yes, I am in love with her books



I guess saying that i have all the material was stupid. I did studied her material but was hard to understand , so I started with the basic. I guess i will start reading her material
6 years ago

Marcus Biel wrote:I did not understand what exactly your question is, but let me try.

Yes, as of today, you need to do the OCA before the OCP.
What do you need two month for?

Buy your copy of the
OCA/OCP Java SE 7 Programmer I & II Study Guide (Exams 1Z0-803 & 1Z0-804) (Certification Press)

Read it, best read it several times, make notes, and learn everything inside out you don't know.
Do all the mock exams thorughly until you reach close to a 100% in each question.
Then first you do the OCA and second the OCP.
You might also consider buying a Mock exam simulator, e.g. Wizlabs.

I have a link to this and some further information related to oracle Java certification on my blog:
OCA/OCP Certification

Hope this helps.



Let me put it this way. Are the questions that will appear in the OCAJP will be from the above topics And yes i have the material that yu have advised. I got it from the friend of mine, I m also referring to Java in a nutshell as well as the documentation and tutorial material available on java website.
6 years ago

Greg Charles wrote:

Dhananjay Deshmukh wrote:
I just wanted to check one more thing if i m getting the concept right. Lets just say threads one two and three have started and are in line for the resource. At the moment ob1.t.join() executes , ob1.t is calling sleep in run method and releasing the control making way for ob2.t to execute and then ob3.t. And the process goes on in which case ob1.t comes into life again and the same process goes on. Am i getting it right.



Yes, I think you have it right. When the main thread calls ob1.t.join(), that doesn't actually have any effect at all on the ob1.t thread. Whatever it's doing, it's going to keep doing, whether that's executing or sleeping. All the join does is tell the main thread to wait until the ob1.t thread completes it processing and sleeping entirely, before it (the main thread) continues its own processing.

If an analogy helps, let's say the boss needs some information for a call she will make to the board later in the day. She splits the work of obtaining the information into three pieces and gives one piece to each of her three employees, and she tells them to meet her in the conference room when they finish. As soon as all three return to the conference room with the results of their work, she makes her call to the board. That's like the join() method. It doesn't matter if the three employees slept for most of the time they said they were working. She still waits for all three to be done before going on.

On the other hand, she could have also set her three employees to work, and then herself have gone to sleep on the conference room table for an hour. In that case, when she wakes up, she calls the board immediately without waiting for her employees. That's like the sleep() method. If they had all finished their work by that time, then she has all the information she needs for her phone call. It's not ideal though, because the employees might have all finished their work in five minutes, and she made the board wait 55 extra minutes for no good reason. It's worse though if it took one ore more of those employees more than an hour to finish the work. In that case, the boss calls the board and then doesn't have all the information she promised them.



Thanks i guess i have the general idea of how the join works and it will become more clear with time, i just have to practice more examples.

Greg Charles wrote:The join() method called on a thread (ob2.t for example) blocks the thread making the call from going forward (here your main application thread) until the other thread finishes its processing. When you call Thread.sleep(n), you stop your current thread for about n milliseconds, then go on processing. Since your created threads take about six seconds to complete, the only effective difference in this particular example is that the Thread.sleep(10000) is probably slower. In general, you might not know how long a thread will take to finish its work, and so the join() method can be safer ... that is if it is actually important to wait until a thread finishes before doing some other work.



I just wanted to check one more thing if i m getting the concept right. Lets just say threads one two and three have started and are in line for the resource. At the moment ob1.t.join() executes , ob1.t is calling sleep in run method and releasing the control making way for ob2.t to execute and then ob3.t. And the process goes on in which case ob1.t comes into life again and the same process goes on. Am i getting it right.
Yes I did. I guess the concept becomes clear when I see it in a big picture or atleas a scenario big enough, but I have to study many topics before I can understand and I have to try programming few scenarios. Untill then I will have doubts. So let me try programming and debugging for couple of days. But that's for the link
According to the website, Java SE 8 Programmer I certification is a prerequisite. Als there are topics mentioned in exam section. These topics are as follows:



I have a very good knowledge of java and i m pretty sure that i can clear OCJA 8SE certification which is a prerequisite. However i still need 2 months more before i can go for OCJP.
Is it that the question in the OCJA SE8 will be from above topics only or is it otherwise? I just want be sure!!!
6 years ago

Greg Charles wrote:The join() method called on a thread (ob2.t for example) blocks the thread making the call from going forward (here your main application thread) until the other thread finishes its processing. When you call Thread.sleep(n), you stop your current thread for about n milliseconds, then go on processing. Since your created threads take about six seconds to complete, the only effective difference in this particular example is that the Thread.sleep(10000) is probably slower. In general, you might not know how long a thread will take to finish its work, and so the join() method can be safer ... that is if it is actually important to wait until a thread finishes before doing some other work.



All i could muster from your answer is that thread is basically unpredictable. I guess i will have to study more in order to understand the concept. and clear it. Perhaps i will try more programming. May be involving more interfaces will help, i have a plan.
I m getting confused to as what exactly is the function of join. Below is the code that i used in two ways:
1st: Used with Join
2nd: Used with sleep:

Below is the code :


In both the cases I get the same output as follows :


Why is it that both the cases are giving the same output? I feel like there is no purpose to use join here

Paul Clapham wrote:No. Neither of them are ways of creating a thread.

The first one (Thread t = Thread.currentThread) doesn't create a thread. It just gets a reference to a thread which already exists (the thread which is currently running this code) and assigns it to a variable.

And the second one (new NewThread()) creates an object which -- as already mentioned -- isn't a thread. It happens that the constructor of that object creates a new thread, but as I already pointed out it's easy to confuse that thread with the NewThread object when they are actually two different things.

And the fact that a class implements Runnable is nothing to do with the creation of threads, either. All that means is that the class must have a "public void run()" method, and that's all.




Ok now i m clear.

Paul Clapham wrote:It's possible that calling your class "NewThread" has led you into believing that it's some kind of thread. Which it isn't; it only contains a Thread. If you rename your class something else -- like "RanchDemo" -- you'll see that it acts exactly the same way. When you create a RanchDemo object, a Thread is created and started. It makes no difference whether that RanchDemo object is subsequently assigned to a reference variable or not.



One more question that i have for you is that I have observed the statement below



And another statement is used in another class to create object as well as thread that has main and also the fact that NewThread class "implements Runnable" interface. So are these two ways of creating thread?

Paul Clapham wrote:It's possible that calling your class "NewThread" has led you into believing that it's some kind of thread. Which it isn't; it only contains a Thread. If you rename your class something else -- like "RanchDemo" -- you'll see that it acts exactly the same way. When you create a RanchDemo object, a Thread is created and started. It makes no difference whether that RanchDemo object is subsequently assigned to a reference variable or not.



that explains why i was getting confused. Because i tried to create a simple program without either implementing runnable or thread and tried to create an object like "new Classname". And ended up with error i couldn't figure out. Well, so much for trying variation however i think it was worth it. Its like the entire thread chapter just became easy to understand.