Which JDK version (Language Level) is required for Android Studio?

Answer Clarification – Android Studio supports JDK8 The following is an answer to the question “What version of Java does Android support?” which is different from “What version of Java can I use to run Android Studio?” which is I believe what was actually being asked. For those looking to answer the 2nd question, you … Read more

Using File.listFiles with FileNameExtensionFilter

The FileNameExtensionFilter class is intended for Swing to be used in a JFileChooser. Try using a FilenameFilter instead. For example: File dir = new File(“/users/blah/dirname”); File[] files = dir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(“.txt”); } });

Ternary operator in Java only evaluating one expression since Java 7 – was that different in Java 1.6 and lower?

From the Java 6 JLS: At run time, the first operand expression of the conditional expression is evaluated first; if necessary, unboxing conversion is performed on the result; the resulting boolean value is then used to choose either the second or the third operand expression: If the value of the first operand is true, then … Read more

Is it possible to read the value of a annotation in java?

Yes, if your Column annotation has the runtime retention @Retention(RetentionPolicy.RUNTIME) @interface Column { …. } you can do something like this for (Field f: MyClass.class.getFields()) { Column column = f.getAnnotation(Column.class); if (column != null) System.out.println(column.columnName()); } UPDATE : To get private fields use Myclass.class.getDeclaredFields()

java.lang.UnsupportedClassVersionError Unsupported major.minor version 51.0 [duplicate]

These guys gave you the reason why is failing but not how to solve it. This problem may appear even if you have a jdk which matches JVM which you are trying it into. Project -> Properties -> Java Compiler Enable project specific settings. Then select Compiler Compliance Level to 1.6 or 1.5, build and … Read more

Get keys from HashMap in Java

A HashMap contains more than one key. You can use keySet() to get the set of all keys. team1.put(“foo”, 1); team1.put(“bar”, 2); will store 1 with key “foo” and 2 with key “bar”. To iterate over all the keys: for ( String key : team1.keySet() ) { System.out.println( key ); } will print “foo” and … Read more

How to set specific Java version to Maven?

Maven uses the JAVA_HOME parameter to find which Java version it is supposed to run. I see from your comment that you can’t change that in the configuration. You can set the JAVA_HOME parameter just before you start maven (and change it back afterwards if need be). You could also go into your mvn(non-windows)/mvn.bat/mvn.cmd(windows) and … Read more

Dealing with “java.lang.OutOfMemoryError: PermGen space” error

The solution was to add these flags to JVM command line when Tomcat is started: -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled You can do that by shutting down the tomcat service, then going into the Tomcat/bin directory and running tomcat6w.exe. Under the “Java” tab, add the arguments to the “Java Options” box. Click “OK” and then restart the service. … Read more