
Java 7 is now available - Mitt
http://www.oracle.com/technetwork/java/javase/downloads/java-se-jdk-7-download-432154.html
======
j_col
You can now finally use a string in a switch statement, hurray (it's the
little things that make me happy)!

[http://download.oracle.com/javase/7/docs/technotes/guides/la...](http://download.oracle.com/javase/7/docs/technotes/guides/language/strings-
switch.html)

~~~
dxbydt
God, I seriously hope string-switching doesn't catch on.

In a prev job, I saw this block of code -

\-------

public int getDaysInMonth( String month ) {

    
    
      if( month.equalsIgnoreCase("january")) return 31;
    
      else if( month.equalsIgnoreCase("february")) return 28;
    
      else if( month.equalsIgnoreCase("march")) return 31;
    
      else if( month.equalsIgnoreCase("april")) return 30;
    
     ...
    

}

\-------

My eyes bled. I said folks, just map the month to an int M in range [1..12]
and simply write 1 line of code

return 30+((M+Math.floor(M/8))%2;

( except for 2, which is 28 or 29 depending on a leap year)

I was overruled. "We are programmers, not mathematicians" was the response!!!

Now they'll happily use this string-switch to do

\---------

switch( month.toLowerCase() ) {

    
    
      case "january" return 31;
    
      case "february" return 28;
    
      case "march" return 31;
    
      case "april" return 30;
    

...

    
    
      default : return -1;
    

}

\-------

which is an even nastier abomination :(

~~~
kragen
I have to say, I think it's easier to verify the correctness of

    
    
        [31, isLeapYear(year) ? 29 : 28, 31, 30, 31, 30,  31, 31, 30, 31, 30, 31][M-1]
    

than your formula. Even a dictionary wouldn't be bad. And if it were wrong, it
would be easier to fix it.

~~~
fleitz
Correctness should be verified by tests not 'looking at the code'.

The aforementioned code can never be verified as correct because February
requires a year to be present to know the number of days.

Doesn't java have a massive calendar library to address exactly these sorts of
human questions?

I mean sure you'd still be looking at code like:

    
    
      public int getDaysInMonth(DateTime date) throws
        CalendarFactoryFactorException,
        DateOutOfRangeException,
        ArrayOutOfBoundsException 
      {
        CalendarFactoryFactory factoryMaker = new CalendarFactoryFactory("Western");
        GregorianCalendarFactory gregFactory = factoryMaker.getGregorianFactory();
        Calendar c = gregFactory.createCalendar(new DateTime());
        return c.getDaysInMonth();
      }

~~~
kragen
> Correctness should be verified by tests not 'looking at the code'.

Tests can prove the presence of bugs, but they are (in general) hopelessly
inadequate to prove their absence; and once a test finds a bug, you still have
to be able to understand what the code is doing in order to fix the bug.

In practice, code inspections and tests find quite distinct sets of bugs with
some overlap, so it's valuable to do both of them. That's why all decent
programming processes require both.

(This is probably one of the few cases where you _could_ in fact verify that
the code is correct by exhaustive testing — but only by comparing it against a
known-correct implementation.)

------
spullara
InvokeDynamic is a pretty awesome new feature in JDK7 and will likely be
tranformative for dyanmic languages on the JVM. For my mustache.java
templating solution it increased performance on an integration benchmark by
25%.

[http://groups.google.com/group/mustachejava/browse_thread/th...](http://groups.google.com/group/mustachejava/browse_thread/thread/24b6c59d2ea55f04)

------
coverband
Did they always have this clause in the Java license, or is it new to Oracle's
release?

"These Supplemental License Terms add to or modify the terms of the Binary
Code License Agreement....

A. COMMERCIAL FEATURES. You may not use the Commercial Features for running
Programs, Java applets or applications in your internal business operations or
for any commercial or production purpose, or for any purpose other than as set
forth in Sections B, C, D and E of these Supplemental Terms. If You want to
use the Commercial Features for any purpose other than as permitted in this
Agreement, You must obtain a separate license from Oracle."

Sections mentioned are: B. SOFTWARE INTERNAL USE FOR DEVELOPMENT LICENSE
GRANT. ... Oracle grants you a non-exclusive, non-transferable, limited
license without fees to reproduce internally and use internally the Software
complete and unmodified for the purpose of designing, developing, and testing
your Programs.

C. LICENSE TO DISTRIBUTE SOFTWARE. ... Oracle grants you a non-exclusive, non-
transferable, limited license without fees to reproduce and distribute the
Software, provided that (i) you distribute the Software complete and
unmodified and only bundled as part of, and for the sole purpose of running,
your Programs, (ii) the Programs add significant and primary functionality to
the Software, (iii) you do not distribute additional software intended to
replace any component(s) of the Software, (iv) you do not remove or alter any
proprietary legends or notices contained in the Software, (v) you only
distribute the Software subject to a license agreement that: (a) is a
complete, unmodified reproduction of this Agreement; or (b) protects Oracle's
interests consistent with the terms contained in this Agreement and that
includes the notice ...

D. LICENSE TO DISTRIBUTE REDISTRIBUTABLES. ... Oracle grants you a non-
exclusive, non-transferable, limited license without fees to reproduce and
distribute those files specifically identified as redistributable in the
README File ("Redistributables") ...

E. DISTRIBUTION BY PUBLISHERS. This section pertains to your distribution of
the JavaTM SE Development Kit Software with your printed book or magazine ....

Maybe I'm reading too much into it, because of the Android lawsuit?

~~~
nl
The licence has always had similar terms.

Specific to (A), that is regarding the JDK (as opposed to the JRE). As
mentioned elsewhere, you can't redistribute tools.jar, and I think the
compiler itself is a problem too.

------
famousactress
Meh. The world turns. I spent a decade developing primarily in Java, and the
last few years were really disappointing. The community splintered, the
language and platform really lost any ability to maintain momentum. I might
have been stoked about Java 7 three years ago (when it should have come out).

~~~
speckledjim
> The community splintered, the language and platform really lost any ability
> to maintain momentum.

This is the mindset I've never understood.

Do you stop using a hammer to bang in nails because the hammer "community" has
splintered, or the development of hammers has stagnated? No, you still use it
to fulfill a job it solves.

~~~
famousactress
I don't think this is a valid analogy. The language/tools/support/ability-to-
hire-developers are all a fluid ever-changing thing. Hammers aren't. Take this
post.. people are excited about _updates_. I'm just saying the updates are
kind of too little too late for me.

~~~
speckledjim
Well, people want different things. I just want the hammer.

New language features are all fun, but unless they actually result in faster
execution, or allow you to do things you could not do before, they're only use
is to make some developers happy, which I don't think is particularly
important.

It looks like there's some real solid good APIs here though which is great to
see.

At first thought I imagined it'd just be useless pandering to developers like
"You can now do closures or first class functions" or something equally
useless.

~~~
famousactress
Come on, let's get honest. The ecosystem matters. A lot. The community, and
level of interest and delight in using the language matters.. Yes, even to
you. It determines what third party tools are available, how easy it is to
hire developers, and what machines the platform actually runs on. Your
argument suggests you'd be just as happy and productive developing today in
Pascal.

 _"You can now do closures or first class functions" or something equally
useless._

Flamebait, but I'll take it. I think the dust-up over the possibility of this
being added to Java really seemed to contribute to the decline and apparent
disinterest of a lot of folks (I'd really be interested in Bob Lee's opinions
here, since he was someone who's ideas I was particularly aligned with at the
time and has since gone pretty quiet).. That said, lack of first class
functions in Java isn't a trifle. It's why Java isn't all that much fun to
program in compared to more expressive languages... and a bigger problem is
that more than any other language I'm familiar with Java suffers from the
problem of not being able to see enough ideas in a given amount of source
code. I'm explaining that terribly, but I just mean that Java code is at least
60% scaffolding that isn't material to the author's intent.

Closures, or first class functions done nicely would be a big step in
alleviating that issue, IMHO.

~~~
speckledjim
> and a bigger problem is that more than any other language I'm familiar with
> Java suffers from the problem of not being able to see enough ideas in a
> given amount of source code.

This is not an issue with Java. It's an issue with the programmer. How are you
going to cope with assembly language listings? Blame assembly language?

------
kragen
Looks like this version is not open source. Is there an open-source version of
Java 7? Edit: Yes! <http://openjdk.java.net/> has an announcement at
[http://mail.openjdk.java.net/pipermail/announce/2011-July/00...](http://mail.openjdk.java.net/pipermail/announce/2011-July/000106.html).
So why would anybody "accept the Oracle Binary Code License Agreement for Java
SE"?

~~~
metra
The OpenJDK may have more bugs. Check out
[[http://stackoverflow.com/questions/1977238/why-should-i-
use-...](http://stackoverflow.com/questions/1977238/why-should-i-use-the-sun-
jdk-over-the-openjdk-or-vice-versa)].

~~~
elehack
In my experience, OpenJDK has fewer bugs - at least the ones I care about.
Like Swing making bad assumptions about the WM, including that only a small
fixed number of window managers are tiling (OpenJDK works on XMonad, Java 6u21
does not).

------
rkalla
There is a good amount of _stuff_ to get excited about in this release.

    
    
      - Try-with-resources-Catch-Block [0]
      - Fork/Join libraries from Doug Lea (author of Executor framework) [1]
      - Inferred/Simpler generics in declarations (should have been in Java 5)
      - NIO2, brand new/robust filesystem APIs [2]
      - NIO2, treat ZIP/JAR files like directories of files for R/W [3]
      - SDP support [4]
      - String-in-switch (NOTE: check on performance implications of this for tight loops)
        NOTE: Read through "COMPILATION" section here for details [6]
      - Elliptic curve cryptography (when normal curves just don't cut it)
      - Underscores in numbers (e.g. int million = 1_000_000;)
      - XRender pipeline on Linux (Swing/Java2D rendering get a big boost)
      - New sound synthesizer (replaces a proprietary lib that wasn't OS)
      - XML stack finally got updated across the board.
      - InvokeDynamic (already talked about numerous times below)
      - Other Swing stuff I'm not all that pumped about.
    

I think the most exciting items are:

    
    
      1. Try-with-resources
      2. NIO2 filesystem API
      3. InvokeDynamic
    

Features that got pushed to 8 (next year) that will be really exciting:

    
    
      - Modular programming (super packages? think OSGi-lite)
      - Syntactic Sugar: Collection literals
        List<String> people = {"Frank", "Mary", "Satan"};
      - Closures
      - Modularization of the JDK (JDK gets broken into core modules)
    

And one that I can't get confirmation on if it's in 7 or got pushed, index-
access for List and Maps [5]:

    
    
      - List<String> people = {"Frank", "Mary", "Satan"};
        System.out.println("Hello " + people[0]);
    

I understand that a lot of people don't find Java sexy any more, that is
understandable, it has become a platform for what seems like a lot of next-
series of languages.

That being said, I've been working with Java since 1998 and still love it. I
know people get a big kick out of writing code with no exception handlers and
no curly braces, and programming _is_ a creative/artistic process so you have
to do what feels good... but none of that stuff ever bothered me.

I like being a pedantic programmer.

[0] [http://www.javacodegeeks.com/2011/07/java-7-try-with-
resourc...](http://www.javacodegeeks.com/2011/07/java-7-try-with-resources-
explained.html)

[1] [http://artisans-serverintellect-com.si-
eioswww6.com/default....](http://artisans-serverintellect-com.si-
eioswww6.com/default.asp?W9)

[2] <http://openjdk.java.net/projects/jdk7/features/#f250>

[3] <http://openjdk.java.net/projects/jdk7/features/#fa537814>

[4] <http://openjdk.java.net/projects/jdk7/features/#f639>

[5] [http://mail.openjdk.java.net/pipermail/coin-
dev/2009-March/0...](http://mail.openjdk.java.net/pipermail/coin-
dev/2009-March/001108.html)

[6] [http://mail.openjdk.java.net/pipermail/coin-
dev/2009-Februar...](http://mail.openjdk.java.net/pipermail/coin-
dev/2009-February/000001.html)

~~~
mmahemoff
Syntactic Sugar: Collection literals List<String> people = {"Frank", "Mary",
"Satan"};

I find it breathtaking this isn't core yet. I was writing test fixture support
code for 1.4 to easily and DRYly generate lists of up to 10 items, which
required 10 copy-paste functions each with a different number of arguments.
1.5 came along and made it possible to easily do it with one function thanks
to varargs, but it's 6 years later and still no collection literals!

~~~
rtg
If you use the Google library [1], this becomes a bit more convenient that the
built-in Java way:

    
    
       List<String> people = ImmutableList.of("Frank", "Mary", "Bob");
    

There's also ImmutableSet and many other goodies, to say the least. For
instantiation of these generic types, you can do:

    
    
       List<String> people = Lists.newArrayList(); 
       Map<String,Integer> scores = Maps.newHashMap();
    

and so on.

[1] <http://code.google.com/p/guava-libraries/>

~~~
markelliot
Since 1.5 you can use the `Arrays` built-in [1]:

    
    
        List<String> people = Arrays.asList("Frank", "Mary", "Bob");
    
    

[1]
[http://download.oracle.com/javase/1.5.0/docs/api/java/util/A...](http://download.oracle.com/javase/1.5.0/docs/api/java/util/Arrays.html)

------
nkassis
So for languages like Clojure,Scala does this offer any new feature for them?

~~~
ghotli
Yes [1]. Invokedynamic (JSR-262). Quote from an older article [2]:

"... enable[s] implementers of compilers for dynamically typed languages, that
is, the people who develop compilers for languages such as JRuby and Jython,
to generate bytecode that runs extremely fast in the JVM."

[1] <http://blogs.oracle.com/jrose/entry/jsr_292_launched_in_java>

[2]
[http://java.sun.com/developer/technicalArticles/DynTypeLang/...](http://java.sun.com/developer/technicalArticles/DynTypeLang/index.html)

~~~
peterb
Indeed, As Charles Nutter (JRuby) wrote:

"There’s a very real chance that invokedynamic could improve JRuby performance
many times, putting us on par with our statically-typed brothers like Java and
Scala. And that means you can write Ruby code without fear. Awesome."

[http://www.engineyard.com/blog/2011/jruby-1-6-released-
now-w...](http://www.engineyard.com/blog/2011/jruby-1-6-released-now-what/)

~~~
jamesgeck0
So invokedynamic is already wired into JRuby? I can just install the Java 7
runtime and see significant performance improvements?

~~~
peterb
JRuby 1.7 has the major Invokedynamic changes. You can play with trunk for
now.

------
bromagosa
«JSR TBD: Project Lambda Lambda expressions (informally, "closures") and
defender methods for the Java programming language»

Welcome to the sixties, Java!

Sorry, I couldn't help it >:D

~~~
jyxent
That's a deferred feature. It won't make it into Java until version 8.

~~~
bromagosa
Oh, in that case, welcome to the 50s ;)

------
nextparadigms
Does it come with more patents? Serious question.

I'm thinking Oracle tried to put a lot more locks on this version of Java, to
make it _theirs_ , and not so open source anymore.

~~~
wmf
Wasn't the feature freeze before Oracle bought Sun?

~~~
zmmmmm
Ah, but patents, wonderful things that they are, protect implementations more
than they protect features. It's very easy to implement the same feature in
different ways, ones that are patent protected if you know how.

Having said that, GPL in theory ensures users and even people making
derivatives of Java are protected from patent action by Oracle.

------
macmac
Watch out for the Commercial Features as defined in table 1.1 of this document
[http://www.oracle.com/technetwork/java/javase/documentation/...](http://www.oracle.com/technetwork/java/javase/documentation/java-
se-product-editions-397069.pdf)

Commercial Features appears to be jRockit technology.

------
Emore
Anyone know why an OS X release is not on the list?

~~~
JonnieCache
Apple manage their own java builds, and they usually lag way behind the
sun/oracle releases.

With java "deprecated" in lion, who knows how long it will take this time.

~~~
reverend_gonzo
It's not just Apple anymore.

Apple and Oracle will be working together to create an OpenJDK for Macs.

[http://www.macstories.net/news/apple-and-oracle-announce-
ope...](http://www.macstories.net/news/apple-and-oracle-announce-openjdk-for-
os-x-java-developers-rejoice/)

------
johnnyo
I'm glad to see it's finally available.

I'm especially happy to see some of the language syntax that makes your
standard try/catch/finally blocks a little cleaner and less error prone.

~~~
huherto
I don't see a "What's new in Java 7" in the above link. Where can a read about
it? thanks

~~~
Mitt
[http://www.oracle.com/technetwork/java/javase/jdk7-relnotes-...](http://www.oracle.com/technetwork/java/javase/jdk7-relnotes-418459.html)

------
rubyorchard
Too little to show for 5 years.

~~~
cfontes
yeah but Sun was sold, and other stuff happened. I think it's already great
that there is a release with some syntax features that are useful and other
nice to have things too. I think Java 8 will come fast there are plenty of new
langs now they can't miss the point otherwise companies will continue to
migrate to faster evolving languages with faster developing times.

~~~
felipemnoa
>>faster evolving languages with faster developing times.

Could you provide citations of any studies done please. i.e. How development
times differ for small projects and large projects. For small projects I could
see other languages being faster, what about large project or really large
projects?

~~~
cfontes
I cannot, and I think no one can. There is simply not enough data about it,
this could easly become a Masters thesis and I would love to read it. This is
just my feeling about Java comparing to some of the new and not so new
languages that are evolving in months while java takes years. I am a Java
programmer that likes to experience with other langs so don't get me wrong
java is an awesome tool and I love working with it, but I think there are
other very good tools emerging and getting more and more reliable.

------
sgt
Having created several "enterprise" systems in Java, I'm now looking into
Mono, because there are some aspects of Java that I'm simply tired of having
to deal with again and again. So far it looks very interesting and it works
really well on Linux and OS X. Anyone here got experience with using Mono (and
possibly Fluent NHibernate, WCF, ASP.NET MVC, etc) in the "enterprise"
environment?

------
_mayo
Does anyone have a link to the changelog?

~~~
SlyShy
Here: <http://openjdk.java.net/projects/jdk7/features/>

~~~
EgeBamyasi
That image confuses me..

Edid: You change the link didnt you? Im talking about the image from here:
[http://blogs.oracle.com/theplanetarium/entry/summarizing_jav...](http://blogs.oracle.com/theplanetarium/entry/summarizing_java_language_changes_for)

------
msx
[http://mail-archives.apache.org/mod_mbox/lucene-java-user/20...](http://mail-
archives.apache.org/mod_mbox/lucene-java-
user/201107.mbox/%3C001601cc4d6b$37618880$a6249980$@apache.org%3E)

that worried me little bit. what do you think ?

------
suprgeek
Making sure that the people excited about Java 7 wait until this gets patched
<http://news.ycombinator.com/item?id=2820204>

------
kennystone
Good for Oracle. There are (reasonable) concerns about their ownership of
Java, but at least it's moving forward again.

------
gmosx
A great release (professionally handled by Oracle), but still I am waiting for
Java 8 (esp. closures + modules)

------
dmitrykoval
Have anyone done any performance comparison with the openjdk yet? GC related
tests would be of high interest :)

------
gnoupi
Pity though that Swing didn't get much love in this release. But I guess
that's the course of things.

------
jzoidberg
Awesome IO stuff - finally we have great cross platform file handling.

------
fleitz
Awesome, so java finally has closures & lambdas?

------
dstywho
closures yet?

~~~
jyxent
Not yet. Closures and other features were delayed to get Java 7 out sooner.

<http://openjdk.java.net/projects/jdk7/features/>

------
czDev
oh man, can't wait to use closures in my Java code

~~~
cpeterso
Unfortunately, you'll have to wait (until Java 8).

------
clobber
Excellent. Looking forward to the memory enhancements that should help make
Minecraft servers less of a hog :)

------
zszugyi
Too little, too late.

~~~
jpr
Perfect summation of everything java.

~~~
fleitz
That's quite incorrect, Java is very good about allocating memory, it's often
too much, too early.

