Hacker News new | past | comments | ask | show | jobs | submit login
Hidden Features of Java (stackoverflow.com)
125 points by zengr on Jan 8, 2012 | hide | past | favorite | 23 comments



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.


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.


Java.util.concurrent.ExecutorService is great. Coupling it with Hazelcast is truly great in creating a dynamic cluster that performs parallel distributed work with ease. One of the pains in setting up server cluster in AWS is the cluster discovery and membership maintenance. Hazelcast does all those automatically.


>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?


The intended use case for stackoverflow is that you have a problem, you google for it, you find a stackoverflow question that covers your problem and click it to find out how to solve it because you know that stackoverflow search results are usually useful for that sort of thing.

If they allow other kinds of content, interesting as it may be, it will dilute that and turn stackoverflow into a discussion site or a place where people just post funny anecdotes or assorted programming trivia. That's not inherently bad but it makes it harder to use the site for its intended purpose.

(Disclaimer: I have like five karma on stackoverflow and don't necessarily know what I'm talking about.)


Recently I asked a question on SO that was closed for not being specific enough. I couldn't recreate the problem for others, I think was the issue, and I was hoping to get some general "try this" answers just to steer me in the right direction. But it seems they don't want that, they want specific questions with exactly 1 correct answer.


Maybe you could not have recreated the problem but you could have indeed described the symptoms and the problem statement. It's not written anywhere in the FAQ but SO places the subliminal message to write better, communicate better and research better. The more you do this, the more you understand your own problem and you will be able to reach your solution.

See: http://www.codinghorror.com/blog/2011/02/how-to-write-withou...

Did some digging and found this

http://stackoverflow.com/questions/8449696/project-doesnt-re...

This doesn't look like something to point someone in the right direction. Yes, you are working with proprietary code but you could think of ways to describe what is happening without disclosing information otherwise you are making users play the 20 questions game with your question (as noted by a moderator). A high rep and top contributor to the site (Jon Skeet) was trying to help you but you didn't seem to want to reciprocate with more information. As I said earlier, clear communication is key in SO, don't make users point in the dark. You are wasting their time and yours with the back and forth clarifications.


It becomes unmanageable. It's the bike shed problem. No one seems to want to edit or read the question for an answer that is a duplicate of what the user wants to say but everyone wants to put their fingerprint/mark on the question. Compare Hidden Features of Java with Hidden Features of C# where the community actively maintained the question into something that could be easily traversable (contents). So the harm in leaving the question open tells new users that it's okay to post questions like this since it has a high number of votes. But a high number votes neither proves or disproves the value of a question. At the onset it might but as popularity increases more votes are meaningless and it thusly turns into a popularity contest.

It would interesting to see how many users (who voted) actually paged through all 100 answers.

Take instead the Greatest Hits which do take into account data to determine value http://stackoverflow.com/questions/greatest-hits and you will notice none of these hidden features or list of x questions make the cut.

The argument used to keep them open is that they have value (which is why the notice was added), developers and moderators alike have said that they have gotten valuable information from these questions (Nick Craver, Joel Coehoorn, Bill the Lizard)

> This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here.

As for the single binding vote made by a moderator this could have been a result of many flags made by users that he had to act on. SO moderators and to an extent SE moderators will always be called http://www.google.ca/search?q=%22overzealous+moderators%22+s... and that's something they just have to live with in order to keep StackOverflow a place that is different from a forum. SO emerged because of a need to get Q&A different from a forum. Elections (http://stackoverflow.com/election) are held every year to get moderators knowledgeable of the process and users the community trusts to make decisions the community might not normally. Most SO moderators never see the main site regularly and are stuck in the flag queue answering the community needs.


I'm not sure any more which stackexchange site is a good fit for this sort of questions. It seems that it would be closed on http://programmers.stackexchange.com/ as well, at least from what I can read in the FAQ.


It's been said that the closed SO questions are the best. So I wrote a query to list the best closed questions: http://data.stackexchange.com/stackoverflow/s/2305/top-close...

Here's top 40 most favorited closed questions (closed questions can't be upvoted, but can still be favorited): http://data.stackexchange.com/stackoverflow/q/123697/top-40-...


They strongly dislike poll-like questions.


the mods do but the users don't (290 upvotes and favorited 665 times).


That could indicate that the thread had a medium relevance for a wide range of people, not a high relevance for a specific set of people. SO seems to focus on the second.

I think they fear a slippery slope to becoming /r/programming with everyones favorite cartoons, favorite quotes and "what do you hate about php?"-questions on the front page.


The site fell pretty far down that slope in its first year before turning itself around. Here are some good examples of top-30 questions from the days of softer moderation:

  - What's your favorite "programmer" cartoon?
  - What is your best programmer joke?
  - Great programming quotes
  - Defend PHP; convince me it isn't horrible
  - What is the best comment in source code you have ever encountered?
  - What's your most controversial programming opinion?
  - What are some funny loading statements to keep users amused?
  - Worst UI You've Ever Used


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.


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.


Maybe all the sites without tight enforced rules got their discussions derailed and you never heard about them?

See "Optimizing for Pearls, not Sand": http://blog.stackoverflow.com/2011/06/optimizing-for-pearls-...


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.


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

In getCurrentThreadId it should read

return uniqueNum.get();

not

return uniqueId.get();


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(","));


Why not

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


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...


You save "" for each extra item, which gets annoying on longer lists.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: