Kapil Sakhuja

Ranch Hand
+ Follow
since May 09, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
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 Kapil Sakhuja

Thanks Astha!

I tried to look at the JLS and this is what i could follow from the same: The compiler follows a process called as 'static analysis' and so it knows that 'only' in the case of break, continue, return or throw statement, the code cannot complete 'normally' and so any statement after one of these statements becomes not reachable. A function call is treated like other expressions, and so the compiler is not able to make out whether this call will complete normally or not.


In the code above, at line marked 'LINE 2' the compiler rightly says that the code is not reachable, but it doesn't report the same problem with line marked as 'LINE 1'. Why can't the compiler see that the function fun() has only one line of code and that code is just throwing an exception, which means that the line 'LINE 1' will never execute in this code.
I have used mock exam softwares of both Enthuware and Whizlabs for OCJP 6 very recently and the following has been my personal experience:

Enthuware:
1) High on quality and quantity, value for money.
2) Even after one if finished with the objective wise Qs, very few Qs repeat (if any) in the complete mock Tests.
3) Very few Qs on "out of syllabus" APIs.
4) Software can be installed on any of your systems and you do not need to be online.

Whizlabs:
1) Low on quantity. Not value for money if you compare with Enthuware. See next point for more.
2) I started with the objective wise Qs and then moved to the complete tests. There were hardly any new Qs. Most of the Qs were repeating.
3) Quite a few Qs on "out of syllabus" APIs.
4) You need to be online and login to their website in order to use the software.

Summary: As per my personal experience, Enthuware is and Whizlabs is
Please see Enthuware.com and Whizlabs.com for info on pricing.
12 years ago
I have used mock exam softwares of both Enthuware and Whizlabs for OCJP 6 very recently and the following has been my personal experience:

Enthuware:
1) High on quality and quantity, value for money.
2) Even after one is finished with the objective wise Qs, very few Qs repeat (if any) in the complete mock Tests.
3) Very few Qs on "out of syllabus" APIs.
4) Software can be installed on any of your systems and you do not need to be online.

Whizlabs:
1) Low on quantity. Not value for money if you compare with Enthuware. See next point for more.
2) I started with the objective wise Qs and then moved to the complete tests. There were hardly any new Qs. Most of the Qs were repeating. Their customer care executive (Raj) acknowledged this fact!
3) Quite a few Qs on "out of syllabus" APIs.
4) You need to be online and login to their website in order to use the software.

Summary: As per my personal experience, Enthuware is and Whizlabs is
12 years ago
This is the standard behaviour. The 'sometimes' in the statement refers to the -d option.

When you used the command javac MyClass.java , the MyClass.class file is generated, but in order to use it you need to place it in a folder structure similar to its package name, i.e. my\util.

When you use the -d option, the compiler helps you by creating the required folders so that you don't have to do it manually.

Please note, in both the above scenarios, the fully qualified name of the class(file) generated is 'my.util.MyClass'.
Thanks! This really helped! I think i have my answer now. See, my minor test/experiment helped me understand something very basic yet very important.
The sentence

When the classes are loaded, it doesn't matter where the class files come from, if they are declared to be in the same package, they are in the same package.



is not mentioned very clearly in Java books/websites. Thanks again Bear!

In other words, just because you can declare classes in existing javax packages, doesn't mean that it's a good idea to do so.



Bear, i think i did not make myself clear when i posted the question. I would rephrase it again. I am not using the existing 'java.lang' or 'javax.swing' packages. I created folders with the same name on my C drive. i am using Windows XP. Also, the answer to this question is important to me cause i feel the answer would also help me understand the class loader and package concepts more clearly.
Sebastian, my import statement is: . I have a feeling this is something to do with the class loader concept. If you or somebody could shed some light on this problem in the context of class loaders it would really help.

Bear, i don't have a clever phrase/idiom like yours to write here, but are you trying to discourage me from experimenting/testing? I personally don't think just mugging up whats written in a book or a website without testing/experimenting is the best approach to learn, but i also understand everyone has a right to their opinion.
Most of the Java books/websites mention that one should not use the package names starting with java and javax as they are already in use by Java language. I was testing to see what error message would i get if i tried to use the forbidden package names for a 'Hello World' type program. I created the required directories on my C drive root manually. I found that if i try to use the package name "java.lang" for my Test.java class, it compiles but gives a "java.lang.SecurityException: Prohibited package name: java.lang" at run time, whereas if i use the package name "javax.swing" there is no exception/error and the program runs fine! My questions:

1) Why is there a difference in behaviour when using package names starting with java and javax? What i am aware of is that the package names starting with java are the standard packages and those starting with javax are the extension packages.
2) In the case where i tried to use the 'javax.swing' package name for my class, i also tried to 'import' an 'javax.swing.JFrame' class and use it. I did not get any error at compile or run time. Why wasn't there a conflict in this case?
Thanks Ankit! But this isn't mentioned in both Kathy's or Khalid's SCJP6 book. errata?
I still haven't got the answer to my question. Could you please put a link to some resource(book/website) which explicitly says that default constructor is/is not required for a JavaBean?
Thanks for your answers guys, but if one of you or somebody could provide a reference/link to some authentic website or book for the same, i would be grateful!

Ankit, i know that a default constructor is implicitly provided if no other constructor is provided, but if a default constructor is required for a JavaBean, shouldn't it be specified explicitly under JavaBean standards. If your answer is yes, isn't this an errata in both Kathy and Khalid's book?

Yes M M, i know wikipedia is not an authentic source, but i wasn't able to find anything more reliable and so i quoted the same. Also, it took me some time to figure out what 'hth' means, so i would really appreciate if you could please write complete words in your answers. Kindly see Javaranch FAQ for more on the same.
Is default constructor one of the requirements in JavaBean standards/conventions? Wikipedia link for JavaBean does say so clearly but i could not find the same in both SCJP6 Kathy's and Khalid Mughal's book. Was wondering if this is a common errata for both Kathy and Khalid's book OR is there a reason for not explicitly mentioning it with JavaBean naming conventions?
Hi friends, I am using Eclipse 3.2.1 with JDK5.0, to develope a Swing App. which is basically a control GUI to run some commands on the machine which were earlier being run on DOS shell. The app has a play/pause button, which works analogous to a CD player button. The current image on the button reflects whether it is play or pause.
The main logic is, when the button is pressed, if the current image is play, i change the image to pause and run some business logic steps. The image shows pause icon as long as the steps are running. After the steps are finished, the button icon is changed back to play.
The GUI is created in a seperate class by extending JFrame and the listener class is seperate. The actionPerformed() method goes like this:

public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("PLAY / PAUSE BUTTON HAS BEEN CLICKED");
JButton buttonClicked = (JButton)e.getSource();
Icon currentIcon = buttonClicked.getIcon();
if(currentIcon == controlGUIMainFrameObject.getPlayImageIcon()){//begin if
System.out.println("PLAY BUTTON HAS BEEN CLICKED");
buttonClicked.setIcon(controlGUIMainFrameObject.getPauseImageIcon());
//buttonClicked.repaint();
//buttonClicked.repaint(100);
/*
*some logic goes here....
*
*/

runSteps(); // this calls another method which creates a new process using ProcessBuilder and runs it.
}// end of if
// resetting the play/pause button icon back to play
controlGUIMainFrameObject.getPlayButton().setIcon(controlGUIMainFrameObject.getPlayImageIcon());
// disbling the stop button
controlGUIMainFrameObject.getStopButton().setEnabled(false);

The steps in the runSteps() method execute as is visible from the console System.out.println() statements. The steps take some time to finish (probably 20 sec). I can see the output:
PLAY / PAUSE BUTTON HAS BEEN CLICKED
PLAY BUTTON HAS BEEN CLICKED
but the image doesnt change as soon as this is done !! I tried using repaint() and repaint(timeInMillis), but that also didnt work.

Can somebody help me rectify this problem ?
17 years ago