This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!

Paweł Baczyński

+ Follow
since Apr 18, 2013
Paweł likes ...
Firefox Browser IntelliJ IDE Java Linux Spring
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 Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Paweł Baczyński

Wecome to the Ranch!

What security exception are there with == operator?

You shouldn't use == to compare strings.

You coud use a 'reversed' notation to avoid NPE, like: if(!"".equals(message)). I'll let you decide if it looks readable enough.

Writing err.equals("") || err.equals(null) won't guard you against a NPE.
First, you should always check for null first. If err is null then err.equals("") will throw a NPE.
Second, err.equals(null) is an incorrect way to do a null check. It will throw NPE if err is null. Also, a properly designed equals method (String class has one) will never return true for null argument. For a null check you have to use the == operator.
1 week ago
There is no difference. Both lines do the same thing.
1 week ago
You said: "There is already a map class, user-defined for that reason, which includes the method."

You need to create an instance of this class. Look at the code of the class. Does it have public constructors? Static factory methods?
Is it the BST class? Does it implement Map interface?
1 month ago

Does it even compile? You are using a variable that is not initialized.
1 month ago
There is java.exe in the path \Oracle\JavaPath.
Windows chooses this executable when you invoke java in the console.
Move your jdk11 path to the top.
2 months ago
Welcome to the Ranch!

First, please use meaningful title for your posts.
Second, [color] tags don't work inside [code] tags.

And finally, your code looks fine. I suspect you are trying to run it incorrectly. Can you post the command you use to run the code?

Edit: oh I missed that your main method returns boolean...
2 months ago

Dave Tolls wrote:That check is correct as far as I can see.

It looks like it is. My bad.
2 months ago
Welcome to the Ranch!

Jay Rex wrote:1. Why is it that if I enter 99.99, it enters the if loop and prints "Please enter a valid number". 99.99 is not greater than 99.99.

Read carefully what condition you have in line 25. Write on pensil your calculation for input 99.99.

Jay Rex wrote:2. I am new to try catch blocks. I see that they have block scope. Lines 18 and 24 are duplicated, as it appears I have to check the code inside the try block and then duplicate the code outside the try catch block because that is what I want to do. Is this the correct way to do it?

It is not the correct way. If no exception is thrown then the value of result will aleady br set to desired value. No need to duplicate this. In this case the computation will be quick so no harm done, but if it were an expensive operation you might have a problem.

Also, I noticed that you use BigDecimal(double) constructor. Read the warning in corresponding javadoc so you are not surprised in the future.
2 months ago

Stephan van Hulst wrote:To further clarify what Paweł wrote, the value you are using to create the BigDecimal instance with is not actually -0.206, but the closest value that can be represented by the double datatype.

And this value is exactly -0.2059999999999999886757251488234032876789569854736328125.
3 months ago
You can find the answer is in the javadoc of the constructor.
It is not a problem with the abs() method. It is a problem with the instance of BigDecimal that you are creating.
3 months ago
It prints 55 because this is the number assigned to character '7' (DIGIT SEVEN).
4 months ago

Tim Holloway wrote:An ArrayList (as far as I know) encapsulates an array (although it could just as easily employ an internal linked list)

So it would become a LinkedList.
4 months ago
Also, there is no sense in using the String constructor. If you want to assign a String to a variable just write:
4 months ago
Make first() return the string.
5 months ago