How to use TLS 1.2 in Java 6

After a few hours of playing with the Oracle JDK 1.6, I was able to make it work without any code change. The magic is done by Bouncy Castle to handle SSL and allow JDK 1.6 to run with TLSv1.2 by default. In theory, it could also be applied to older Java versions with eventual … Read more

Simple Java HTTPS server

What I eventually used was this: try { // Set up the socket address InetSocketAddress address = new InetSocketAddress(InetAddress.getLocalHost(), config.getHttpsPort()); // Initialise the HTTPS server HttpsServer httpsServer = HttpsServer.create(address, 0); SSLContext sslContext = SSLContext.getInstance(“TLS”); // Initialise the keystore char[] password = “simulator”.toCharArray(); KeyStore ks = KeyStore.getInstance(“JKS”); FileInputStream fis = new FileInputStream(“lig.keystore”); ks.load(fis, password); // Set … Read more

How to define a relative path in java

Try something like this String filePath = new File(“”).getAbsolutePath(); filePath.concat(“path to the property file”); So your new file points to the path where it is created, usually your project home folder. As @cmc said, String basePath = new File(“”).getAbsolutePath(); System.out.println(basePath); String path = new File(“src/main/resources/conf.properties”).getAbsolutePath(); System.out.println(path); Both give the same value.

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)