Paweł Baczyński

Saloon Keeper
+ Follow
since Apr 18, 2013
Paweł likes ...
Firefox Browser IntelliJ IDE Java Linux Spring
Forum Moderator
Paweł Baczyński currently moderates these forums:
Kraków
Cows and Likes
Cows
Total received
44
In last 30 days
0
Total given
55
Likes
Total received
474
Received in last 30 days
5
Total given
586
Given in last 30 days
18
Forums and Threads
Scavenger Hunt
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Paweł Baczyński

Piet Souris wrote:Edit: my 'indeed' was in reaction to Pawels reply, that seems to have gone!?


I deleted my own post immediately after posting it as I noticed Campbell was faster than me and my post didn't add anything new to Campbell's.
The post was online for less than a minute. You were lucky to see it.
It is now restored.

This post will disappear in 3 days.
5 hours ago
The method is defined as asList(T... a). It is not defined for primitive types.

If you pass int[] into it, the whole array would be treated as the sole element of the created list.
7 hours ago

Andy Frels wrote:When importing you import classes and Java.io is not a class.

Now it is.

ras oscar wrote:java.lang.Object
java.io.InputStream
   java.io.FilterInputStream
     java.io.BufferedInputStream


I know from process of elimination that the correct import statement is
import java.io.BufferedInputStream

What do the 3 lines above that refer to? If I instead entered

import java.lang.Object

would I get the desired class?



This is the inheritance tree of java.io.BufferedInputStream class.

It means that:
java.io.BufferedInputStream extends java.io.FilterInputStream.
java.io.FilterInputStream extends java.io.InputStream.
java.io.InputStream extends java.lang.Object.

You need to import only these classes that you want to refer to by name.
You don't need to import classes from java.lang package.
19 hours ago

Kelly Lykins wrote:I'm pretty sure isn't a real thing. You gotta specify what you are trying to import.



But it is a real thing. It would import a class io from package Java. You would need to make sure such class is available at compile time. And if it doesn't exist you can create it.

Note that Java identifiers are case sensitive. Names Java.io and java.io are not the same thing.

As you probably had java.io in mind, writing import java.io; is perfectly legal as far as the language syntax is concerned. The only problem is that the class named java.io doesn't exist.
1 day ago

saurabhmehta mehta wrote:I guess since the other thread has not yet released the lock due to sleep() method.



You guessed correctly. The thread you want to notify needs to own the lock to be notified.

saurabhmehta mehta wrote:So is the notify() call being made only after the entire loop is over?


The call on notifiy() is made several times in the DemoThread. But the call only has an effect on the notified thread when it gets the lock.
Welcome to the Ranch!

You can iterate over map.entrySet() and append key+value to a String (possibly StringBuilder).

Do you care about the order of characters in the output?
If you do, would it be the order of first appearance or alphabetical order? Or any other?

For xxxaddb, do you want to get x3a1d2b1 or a1b1d2x3?
1 week ago
Welcome to the Ranch!

java.lang.StringIndexOutOfBoundsException: String index out of range: 0
This means you are trying to get a character from a String atindex 0 but this index is "out of bounds".
An index is out of bounds if it is negative (not the case here) or >= length of the String.
The only way index 0 can be out of bounds is when a String is empty.

One of the Strings in your example is empty. It is numbers (if you modified it somewhere) or passwordCreated.
2 weeks ago

Paul Clapham wrote:Since you're doing the same thing in both catch blocks you can simplify that some more:


Nitpick alert!

Actually this code won't compile as FileNotFoundException is a subclass of IOException.
So this can and should be shortened to:
2 weeks ago
We can't sort a HashMap because HashMaps aren't meant to be sorted.
Complaining about it is kind of like complaining that cars can't fly.
3 weeks ago

S Fox wrote:It should be implied that we want a new object and that we want the same type we already specified, why write it twice.


JEP 286 to the rescue!
3 weeks ago
import aquarium.* imports all classes from aquarium package.
It does not import anything from aquarium.jellies package.

You need to understand that aquarium and aquarium.jellies are completely different packages.
The class aquarium.jellies.Water doesn't belong to the aquarium package.
3 weeks ago

Dave Tolls wrote:Then if the code referred to Eager.SOME_STATIC_THING the INSTANCE would be created


Well, no.
A public static final String would be inlined.

This prints:
thing

This prints:
Instance created
thing

This is mandated by JLS:

JLS SE 9 in 13.1 wrote:A reference to a field that is a constant variable (§4.12.4) must be resolved at compile time to the value V denoted by the constant variable's initializer.

If such a field is static, then no reference to the field should be present in the code in a binary file, including the class or interface which declared the field.



But this is only the case with primitives and Strings.
The equals() methods in arrays is inherited from Object class.
That means it checks objects identity (like using == operator).

If you want to compare contents of arrays use Arrays.equals method.
1 month ago
You need to provide fully qualified names of classes.
1 month ago