FAQ Database Discussion Community


Create list of Java metaclasses that have common base class

java,java-7
I have several classes derived from common base class. public class BaseClass ... public class ClassA extends BaseClass ... public class ClassB extends BaseClass ... I need to store those classes in list where I can retrieve them via their index and create specific instances at runtime and I can...

No compiler error about incompatible casts

java,generics,java-7,classcastexception
Sorry if this was already explained, but i didn't find similar threads anywhere in web. Today I opened one project class in IDE and saw an error (red underline), though project was compiled successfully. So, the code is: public interface DatasourceImplementation<T extends Entity> { .... } public interface Datasource<T extends...

Construct FrameNode with ASM api

java-7,bytecode,java-bytecode-asm,bytecode-manipulation,stackframe
I succeeded in implementing bytecode method inline optimization and the generated code seems OK for me. Yet, the verification fails with message: java.lang.VerifyError: Expecting a stackmap frame at branch target 47 Exception Details: Location: code/sxu/asm/example/Caller.test(II)V @44: goto Reason: Expected stackmap frame at this location. And the corresponding bytecode is: public...

Java Generic and inheritage of Generic Class

java,generics,java-7
It seem that a generic container cannot use a more specific class that the one of a function signature with generic container. How can I have a container which use more specific class that the one of the function it is passed to? Is that possible ? Did I misunderstood...

JUnit test method comparing DateTimes fails only when run from suites

java,junit,java-7,junit4
A single JUnit test being run under JUnit 4.11 fail the majority of the time while being run via either to module test suite (40 runs: 2 failures, 38 passes), or the class test suite (40 runs: 6 failures, 34 passes), but running the test method by itself did not...

Should I use Java 7's try-with-resources statement for each line of log

java,java-7,writer,close,try-with-resources
I want to log (append text) into a file every time something happens. I find this might be the correct way to do this with Java 7's try-with-resources statement: public void log(String textLine) { try(PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter("Logfile.txt", true)))) { output.println(textLine); }catch (IOException e) { //exception handling...

Comperator caused “Comparison method violates its general contract!” - 1300 items sort

sorting,java-7
I have data of 1300 items, sorted with my comperator. Sorting is working fine when I'm using JAVA 6. When project is run on JAVA 7 I'm getting this exception: env: JAVA 7, Vaadin 6.8.12, tested with both 32 bit and 64 bit same error occured. ( It is working...

Tomcat failing to startup

java,tomcat,java-8,java-7
A few days ago when I turned the computer on, I tried to start up tomcat and got a surprise for the first time since I deal with software development. The exact error message is: Using CATALINA_BASE: "C:\apache-tomcat-8.0.9" Using CATALINA_HOME: "C:\apache-tomcat-8.0.9" Using CATALINA_TMPDIR: "C:\apache-tomcat-8.0.9\temp" Using JRE_HOME: "C:\Program Files\Java\jdk1.8.0_45" Using CLASSPATH:...

Java erased -> compile time type alignment - or Java Library/Framework code transitioning to application logic

java,generics,java-7,erasure,type-polymorphism
I am Working on a configuration scenario for a complex distributed OSGi system. I need to make the following transition from library code to application code on Java 7 (this code below is incorrect): void someFrameworkMethod(...) { .... // arg 2 is of type Object // service is of type...

HIPI compile fail: class file for com.sun.image.codec.jpeg.JPEGDecodeParam not found

java,apache,hadoop,ant,java-7
I was compiling HIPI framework using ant on Hadoop 2.6.0 on Ubuntu 14.04 and got this error: Buildfile: /home/jinjunho/hipi/src/build.xml setup: test_settings: all: [javac] Compiling 23 source files to /home/jinjunho/hipi/lib [javac] /home/jinjunho/hipi/src/hipi/image/io/MetadataReader.java:34: error: cannot access JPEGDecodeParam [javac] return JpegMetadataReader.readMetadata(_ubis); [javac] ^ [javac] class file for com.sun.image.codec.jpeg.JPEGDecodeParam not found [javac] Note: Some...

Switch statement with string

java,switch-statement,java-7
I tried the following code: String str = "Str1"; switch(str) { case Constants.First_String : System.out.println("First String"); break; case Constants.Second_String : System.out.println("Second String"); break; default : System.out.println("Default String"); } And my Constants class is, public class Constants { public static String First_String = "Str1"; public static String Second_String = "Str2"; public...

JavaFx Webview goes to mobile site -(using jdk 7)

java,webview,javafx,java-7,javafx-webengine
I am trying to create a JavaFX desktop application which consists of an embedded browser. webEngine.load("http://sampleurl"); This statment loads the mobile website for some sites and for some others it loads the desktop site. Is this because of JavaFX or the implementation of the respective websites? Morever the view is...

Stanford CorpNLP returning wrong results

java-7,stanford-nlp,eclipse-3.4,lemmatization
I am trying lemmatization with stanford corenlp following this question. My environment is:- Java 1.7 Eclipse 3.4.0 StandfordCoreNLP version 3.4.1 (downloaded from here). my code snippet is:- //...........lemmatization starts........................ Properties props = new Properties(); props.put("annotators", "tokenize, ssplit, pos, lemma"); StanfordCoreNLP pipeline = new StanfordCoreNLP(props, false); String text = "painting"; Annotation...

Java 7: IF condition triggered when false

java,if-statement,java-7
I have this piece of code: void timerCountDown(){ while(RaftNode.getTimeoutVar()){ long x = System.currentTimeMillis(); if(x >= RaftNode.limit){ System.out.println(x); System.out.println(RaftNode.limit + " THIS SHOULD BE LESS THAN"); System.out.println(System.currentTimeMillis() + " THIS"); System.out.println("TIMED OUT"); raft.RaftNode.setTimeoutVar(false); nextRandomTimeOut(); raft.RaftNode.onTimeOut(); } } } So basically, this is a time-out function and the time-out is refreshed by...

adding dragged component to JPanel on java8

java,swing,java-8,java-7,mousemotionlistener
I have (JScrollPane) scroll which contains: (JPanel) mainPanel (scroll size) (JPanel) boxPanel (boxPanel is added to mainPanel) (ArrayList < JPanel >) rowPanel (all components in List are added to boxPanel) I want rowPanel components to be draggable and update their position in boxPanel depending on place they are dragged onto....

Getting UnsupportedClassVersionError in Eclipse JPA project which does not make sense

java,eclipse,jpa,java-7,jdk1.6
I have a weird situation here. I am getting an error about Java 1.7 when I am using Java 1.6 everywhere. I am using Eclipse Kepler 32-bit. The JPA implementation I am using is EclipseLink 2.6.0. In Window --> Preferences --> Java --> Installed JREs, I have jdk1.6.0_34 (default) checked...

Java7 multiple exception handling

java,exception-handling,java-7
I have been trying to find out answer to this question but did not get any satisfactory explanation. Here is some background: Java 7 allows us to catch multiple exceptions in a single catch block provided those exceptions are from diffrent hierarchy. Eg: try { // some code } catch(SQLException...

Performance hit with binary literals in Java 6 as compared to Java 7

java,binary,java-7,java-6
I am reading a book , it says Before Java 7 , if you want to convert a binary literal in Integer. you need to write int x = Integer.parseInt("1100110", 2); but after Java 7 int x = 0b1100110; Java6 practise gives 1) There is a performance hit for that...

JDK 7: Existing file gets empty on new File(“path/to/file.html”);

java,file-io,java-7
I'm using JDK 7. I've got a class with a method that creates a html-file using PrintStream. Another method in the same class is supposed to use the created file and do stuff with it. The problem is that once i use new File("path/to/file.html), the file lenght is reduced to...

Hadoop 2.6.0 build on Windows 8.1 fails - Ant BuildException

maven,hadoop,build,windows-8.1,java-7
Hello I'm trying to build hadoop 2.6.0 on Windows 8.1. Unfortunately without luck so far. I have installed: jdk1.7.0_71 (added Variable JAVA_HOME with value C:\Program Files\Java\jdk1.7.0_71 to the User Variables) cygwin64 (added its installation-directory as value D:\cygwin64\bin to the PATH Variable under System Variables) Maven 3.2.5 (added its installation-directory as...

How Is the Default Max Permgen Size Defined:

java,java-7,windows-7-x64,eclipse-kepler,permgen
My understanding from what documentation I can find and StackOverflow questions I can find is that the default max permgen size is 64MB. I am running an application out of Eclipse Kepler x86, Windows 7 x64, Java 7 with no -XX:MaxPermSize flags set. The application maxes out at ~82 MB...

How to use Java 7+ Objects.hash with arrays?

java,arrays,java-7,hashcode
I really like Java 7+ style of writing hashCode() method: @Override public int hashCode() { Objects.hash(field1, field2); } It doesn't work correctly with arrays though. The following code: @Override public int hashCode() { Objects.hash(field1, field2, array1, array2); } will not work, as for array1 and array2 regular hashCode() instead of...

Java: must cast to short, cannot use shorthand 'S'

java,casting,java-7,short
I am trying to call a function that requires a short value. The following works: i.setDamage((short) 10); However, this does not: i.setDamage(10S); According to the IDE I am using, this should work. Why does it not? I am using Maven and Java 7....

How to use Try-with-resources with if statement?

java,resources,java-7,try-with-resources
I have the simple code: try (FileReader file = new FileReader(messageFilePath); BufferedReader reader = new BufferedReader(file)) { String line; while ((line = reader.readLine()) != null) { //// } } I want to write something like that: FileReader file = null; ///..... try(file = (file == null ? new FileReader(messageFilePath) :...

How to generate date with milliseconds [duplicate]

java,java-7,java.util.date
This question already has an answer here: How to get the current time in YYYY-MM-DD HH:MI:Sec.Millisecond format in Java? 5 answers I tested this code: java.util.Date d=new java.util.Date(); System.out.println("date="+d); The output is: Sat May 09 02:48:42 CDT 2015 It has no milliseconds... p.s lets say if to use Date...

What is the code convention for formatting try-with-resources? [closed]

java,java-7,indentation,readability,try-with-resources
I'd like to know what the code convention is for formatting try blocks with resources, in particular with more than one resource. Currently I put each resource on its own line, terminated by a semicolon, and use vim's indentation level (2 tab characters), like the following: try ( InputStream in1...

Play! framework Java Promise example

java,playframework-2.0,promise,java-7
I'm reading up on Java's Play framework but don't have much experience in Java. Can someone please explain this Promise<Double> promiseOfPIValue = computePIAsynchronously(); Promise<Result> promiseOfResult = promiseOfPIValue.map( new Function<Double,Result>() { public Result apply(Double pi) { return ok("PI value computed: " + pi); } } ); I get that they're creating...

Lock+HasMap or ConcurrentHashMap in my case?

java,concurrency,thread-safety,java-7,concurrenthashmap
I have a Map<String, Queue<?>> and each time I have to put a couple (key, value) I need to get the not thread-safe Queue associated with that key and add a value to it (if key exist). Because I need to update an existing value (queue) I think that the...

Weblogic domain is not getting created because of jrockit error

java-7,weblogic11g
I am creating a Basic Weblogic server domain(11g, version 10.3.5.0 ). And in the JDK selection Window, in Available JDKs , ' JRockit SDK 1.7.0_55 @ C:\Program Files\Java\jdk1.7.0_55' is selected.. The domain gets created, now i check the 'Start Admin Server' checkbox and click 'Done' . The process of starting...

Joining (union) of Sets inside a Set in Java

iterator,set,java-7,java-api,set-union
I have a map where the values are sets of integers. What i'd want to do is to get in the best way possible (using only the Java API would be great) the union of all the sets of Integers. Map<Long, Set<Integer>> map; What I thought so far is to...

Java JDK 8 IndexedPropertyDescriptor has changed since JDK 7 with List object

java,java-8,java-7,introspection
I have a simple issue. I have a program working in Java JDK7 but it doesn't work in JDK8 because of some introspection changes. Here is a test program to reproduce the issue: import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.util.ArrayList; import java.util.List; public class Main { public...

JRuby Java Version Compatibility

java,version,jruby,java-7,java-5
we want to upgrade our JRuby application from 1.6 (with Java5) to 1.7 (with Java7). I haven't found anywhere a support matrix or compatibility list. Does JRuby support any Java version out of the box? bye, selcuk....

Shortest way to extract Map from List in Java

java,collections,java-7,guava
I have a List List<FeatureHolder> featureHolderList; consisting of FeatureHolder objects public class FeatureHolder { private String flag; private String value; } Now I need to extract Map from the featureSetList. The solution is, of course, trivial: Map<String, String> map = new HashMap<>(); for(FeatureHolder fh: featureHolderList){ map.put(fh.getFlag(), fh.getValue()); } The question...

How to display the time of a Date object based on DateFormat.SHORT and locale?

java,date,java-7
I am using Java 7 and I need to display the time part of a Java Date object. I notice that DateFormat has the SHORT constant according to the page and the page has the following description: SHORT is completely numeric, such as 12.13.52 or 3:30pm My question is how...

Concatenate variable argument list

java,concatenation,java-7,varargs,variableargumentlists
I want to prepend a String to a variable list of String arguments. public String myMethod(String... args) { return myOtherMethod("some string" + args); } Now, this of course will not work, because you cannot add these two types as such. How can I insert this string at the beginning of...

J2SE interfaces specifications and implementations of those interfaces

java,interface,java-7
I was looking at rt.jar for some reasons and there i saw some packages like java.sql.* among others. In a typical jdbc program we write (for Connection class, for example): import java.sql.Connection; As per the docs, java.sql.Connection is interface, not concrete implementation, and java.sql.Connection is in rt.jar. When we write...

try-with-resource close sequence : FileInputStream close executed three times

java,debugging,java-7,close,try-with-resources
I was trying a simple try-with-resource example using Java 8 on OS X. I see some strange behavior. First, following is the code I am running: public void test() { try( FileInputStream fin = new FileInputStream("/tmp/test"); FileOutputStream fout = new FileOutputStream("/tmp/test1") ){ System.out.println("Nothing here"); System.out.println("Nothing here"); }catch (Exception e) {...

Use of Matchers.isNull() for generic classes

java,generics,mockito,java-7
Im using Mockito to test a method like this: myMethod(String s, List<Integer> i); I use this call: doReturn(foo).when(bar).myMethod(anyString(), isNull(List.class)) The use of the isNull(Class<?> class) method is my problem here. Because I use anyString(), which is a Matcher, I can't just pass null. Now I get a type safety warning,...

How can you manually find the Java Development Kit when setting up Android Studio on a PC running Windows 8.1?

java,android,java-7
I visited the link that is shown by Android Studio. But they did not have that exact version of the JDK. I installed what I could find for Windows. I thought I picked the correct file but still getting an error. What am I missing here? This is a screenshot...