
Hidden Features of Java - zengr
http://stackoverflow.com/questions/15496/hidden-features-of-java
======
ntkachov
Java.util.concurrent is one of the most attractive features of java for server
programming. ConcurrentHashMap is faster, cleaner and much easier to use than
locking every time you need a access a shared HashMap. Not only that but it
doesn't lock the entire hash, just a partition of what ever you will be
accessing.

Also AtomicInt,Float,Long make life easier when dealing with threaded
programs.

~~~
jbooth
Don't forget ExecutorService and the whole concept of sending chunks of work
back and forth across synchronizing queues. Best way to write concurrent code
in any language IMO, analogous to go's channels/goroutines and erlang's
whatever they're called.

------
theon144
>closed as not constructive by Robert Harvey♦ Oct 5 '11 at 5:49

>This question is not a good fit to our Q&A format. We expect answers to
generally involve facts, references, or specific expertise; this question will
likely solicit opinion, debate, arguments, polling, or extended discussion.

I appreciate StackOverflow's active moderators, but this question was actually
pretty interesting. What harm would it do to let the question open?

~~~
philwelch
As a pure matter of observation, StackOverflow seems just as deletionist as
Wikipedia, except they actually keep stuff up sometimes. It's interesting to
ponder why these sites develop deletionist culture.

~~~
gojomo
I suspect it has to do with the kinds of status competition/display that are
possible in the online area, the personality types that thrive under such a
constrained domain, and the side-effects of necessary policing/self-defense.

There are some similarities to the observations about leadership in realspace
organizations made by (sci-fi author Jerry) Pournelle's 'Iron Law of
Bureaucracy' and (sociologist Robert) Michels' 'Iron Law of Oligarchy'.

One of the clearest ways to demonstrate 'authority' in an online site is to
say and enforce a 'No', so No's may be oversupplied.

At some point it starts to resemble an auto-immune disorder, a mis-calibrated
system attacking itself.

------
Ubersoldat
<http://monocaffe.blogspot.com/2011/10/javas-ghost-jvms.html>

"how does tools like JPS, JConsole or VisualVM know the JVMs running in a
system? They simply look in the folder /tmp/hsperfdata_foo where a 32KB data
file with the PID as name is created for each JVM."

Not a hidden feature of Java, but of Sun's (Oracle) JVM which I'm not sure if
happens in other JVMs but it's kind of useful for doing different stuff.

------
jahnu
The example in the linked ThreadLocal documentation appears to have a mistake.

In getCurrentThreadId it should read

return uniqueNum.get();

not

return uniqueId.get();

------
6ren
My preferred initialization for lists of strings (shorter than the anon class
+ instance init e.g.)

    
    
      List<String> fruits = Arrays.asList("apple,orange,pear".split(","));

~~~
chrisbroadfoot
Why not

    
    
      Arrays.asList("apple", "orange", "pear")

~~~
eneveu
I personally prefer Guava's immutable collections:

    
    
        List<String> fruits = ImmutableList.of("apple", "orange", "pear");
    

It also works for sets and maps:

    
    
        Set<String> fruits = ImmutableSet.of("apple", "orange", "pear");
        Map<String, Integer> fruitCounts = ImmutableMap.of("apple", 3, "orange", 2, "pear", 6);
    
    

[http://code.google.com/p/guava-
libraries/wiki/ImmutableColle...](http://code.google.com/p/guava-
libraries/wiki/ImmutableCollectionsExplained)

