java-7

How to check the extension of a Java 7 Path

∥☆過路亽.° 提交于 2019-11-27 05:30:46
问题 I'd like to check if a Path (introduced in Java 7) ends with a certain extension. I tried the endsWith() method like so: Path path = Paths.get("foo/bar.java") if (path.endsWith(".java")){ //Do stuff } However, this doesn't seem to work because path.endsWith(".java") returns false. It seems the endsWith() method only returns true if there is a complete match for everything after the final directory separator (e.g. bar.java ), which isn't practical for me. So how can I check the file extension

In a Java 7 multicatch block what is the type of the caught exception?

大兔子大兔子 提交于 2019-11-27 04:58:18
In a Java 7 multicatch block such as the following: try { // code that throws exception } catch (CharacterCodingException | UnknownServiceException ex) { // handle exception } what is the compile-time type of ex ? Is it the most derived class that both exception types have in common? In this example that would be an IOException . Yes, the type of ex is the most specific supertype of both CharacterCodingException and UnknownServiceException , which would be IOException . Edit: Straight from the horse's mouth on http://cr.openjdk.java.net/~darcy/ProjectCoin/ProjectCoin-Documentation-v0.83.html

Is “Java Concurrency In Practice” still valid? [closed]

帅比萌擦擦* 提交于 2019-11-27 04:56:06
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . Is Java Concurrency in Practice still valid? I am wondering whether the ideas, concepts and implementation described in the book are still compliant with the latest Java versions. I ask because the latest edition was done in 2006. 回答1: Yes, it's still valid in my mind. There isn't big change in this area from 6

best example for programmatically creating SplashScreen with text

好久不见. 提交于 2019-11-27 04:54:10
问题 I need to create a SplashScreen programmatically and add text to it (and change it). Most examples work with thecommand line parameters. Are there solutions working without? 回答1: You can use an undecorated dialog with a background image and a progress bar while loading stuffs in a SwingWorker. When done, hide the dialog and start the UI as usual. Components added to the dialog/splashcreen must be non-opaque in order to "see" the background image. Here is a working example: import java.awt

MethodHandle - What is it all about?

一笑奈何 提交于 2019-11-27 04:17:21
问题 I am studying new features of JDK 1.7 and I just can't get it what MethodHandle is designed for? I understand (direct) invocation of the static method (and use of Core Reflection API that is straightforward in this case). I understand also (direct) invocation of the virtual method (non-static, non-final) (and use of Core Reflection API that requires going through Class's hierarchy obj.getClass().getSuperclass() ). Invocation of non-virtual method can be treated as special case of the former

java.security.cert.CertificateException: Certificates does not conform to algorithm constraints

被刻印的时光 ゝ 提交于 2019-11-27 03:56:39
I have a mapping application that can add ArcGIS 9.3+ base maps given a URL. One of the URLs that I would like to add is from a customer's URL and is secured. My mapping application was using Java 6 before and was able to add the secure URL with no issues. I now upgraded to Java 7 and am getting a "java.security.cert.CertificateException: Certificates does not conform to algorithm constraints" exception. At first, I believe this to be the case because in Java 7, by default, the MD2 algorithm to sign SSL certificates is disabled. You can see this in the java.security file: "jdk.certpath

How to change tomcat compiler

 ̄綄美尐妖づ 提交于 2019-11-27 03:52:43
问题 I'm trying to use the new Java 7 switch on strings feature. But Tomcat is not cooperating. I've made sure that tomcat is running under java 7 but it seems that it's not compiling under it. I've added the following to the web.xml file, under the jsp servlet entry <init-param> <param-name>compiler</param-name> <param-value>C:/Program Files/Java/jdk1.7.0/bin/javac.exe</param-value> </init-param> but it doesn't seem to do the trick. Any tips would be appreciated. 回答1: We are running Tomcat 6 and

Why does this compile in Java7 and does not in Java8?

拈花ヽ惹草 提交于 2019-11-27 03:32:46
问题 Generics are tricky. And looks like they are treated differently in different versions of Java. This code successfully compiles in Java 7 and fails to compile with Java 8. import java.util.EnumSet; public class Main { public static void main(String[] args) { Enum foo = null; tryCompile(EnumSet.of(foo)); } static <C extends Enum<C> & Another> void tryCompile(Iterable<C> i) {} static interface Another {} } Here is an error message from Java 8. I used this one to compile it: http://www

How do I add a new Currency to java.util.Currency for an existing country code in Java 7?

£可爱£侵袭症+ 提交于 2019-11-27 03:24:53
问题 For example, the Chinese currency has the ISO 4217 code CNY . Since free global trading in that currency is restricted though, there's a second 'offshore' currency equivalent, called CNH . Wikipedia has a bit of summary of this all. In Java 7 , there's a method for updating the set of three letter ISO 4217 codes that the JVM ships with. However, it can't be used to add a separate currency code to an existing country code: it would replace CNY with CNH , which is no good for my purposes. How

Get large directory content faster (java.io.File alternatives)

若如初见. 提交于 2019-11-27 03:15:28
问题 I've used the old, obsolete java.io.File.listFiles() for too long. The performance is not so good. It is: Expensive, since it creates a new File object for each entry. Slow, because you have to wait for the array to be completed before starting the processing. Very bad, especially if you need to work only on subset of the content. What are the alternatives? 回答1: The Java 7's java.nio.file package can be used to enhance performance. Iterators The DirectoryStream<T> interface can be used to