Installed Java 7 on Mac OS X but Terminal is still using version 6

Oracle’s installer puts java inside the /Library/Internet Plug-Ins/JavaAppletPlugin.plugin. And it doesn’t overwrite /usr/bin/java. So, if you issue a whereis java in the terminal, it’ll return /usr/bin/java. (which in turn points to /System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/java, which is Apple’s 1.6 version). So, if you want to use the new java version, replace the /usr/bin/java symlink so that it points … Read more

How to set -source 1.7 in Android Studio and Gradle

Java 7 support was added at build tools 19. You can now use features like the diamond operator, multi-catch, try-with-resources, strings in switches, etc. Add the following to your build.gradle. android { compileSdkVersion 19 buildToolsVersion “19.0.0” defaultConfig { minSdkVersion 7 targetSdkVersion 19 } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } } Gradle 1.7+, Android gradle … Read more

Java 7 underscore in numeric literals

You don’t have to use “_”, you can. And examples given in the proposal are credit card numbers, phone numbers, or simply numbers for which it makes sense to have a separator in the code. For the “In positions where a string of digits is expected” it’s simply in places where it’s supposed to start … Read more

Java 7 (JDK 7) garbage collection and documentation on G1

The G1 garbage collector is not the default in my installation of Java, version 1.7.0_01. You can see for yourself by using with some extra command line options: > java -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -version -XX:InitialHeapSize=132304640 -XX:MaxHeapSize=2116874240 -XX:ParallelGCThreads=4 -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -XX:+UseCompressedOops -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC java version “1.7.0_01” Java(TM) SE Runtime Environment (build 1.7.0_01-b08) Java HotSpot(TM) 64-Bit Server VM … Read more

Java 7 language features with Android

If you are using Android Studio, the Java 7 language should be enabled automatically without any patches. Try-with-resource requires API Level 19+, and NIO 2.0 stuff are missing. If you can’t use Java 7 features, see @Nuno‘s answer on how to edit your build.gradle. The following is for historical interest only. A small part of … Read more