天道酬勤,学无止境

java

How to make WindowBuilder create fields that are not nested in Eclipse, Java

I am using WindowBuilder for Eclipse Java. When I make a Button or a Menu (or anything), it creates the fields nested inside of the constructor. Is there any way to make them fields and then initialized in the constructor so I can use them outside of the constructor? Thank you. ie: FROM public GUIFrame() { JMenuBar menuBar = new JMenuBar(); } TO public JMenuBar menubar; public GUIFrame() { menuBar = new JMenuBar(); }

2021-06-15 18:15:27    分类:问答    java   eclipse   user-interface   windowbuilder

How to obtain an HttpSession Object from SessionID?

I want to invalidate sessions of users based on some Event. I store their sessionID, how to get their HttpSession from this ID? The HttpSessionContext class is deprecated with no replacement.

2021-06-15 18:13:26    分类:问答    java   servlets   httpsession

Why does Java 7 fail to Verify after successful JRE installation - Java 7 not running my any browser

This question was dogging me for a few days until I found almost a full answer but I want to share the issue first: ISSUE I have a Windows 7 pro 64 bit laptop that supports both IPv4 and IPv6 (important later) I downloaded and installed the latest Java 7 u 51 jre / browser plugin and would always get a grey applet box before it would eventually redirect and say "failed to verify" if java was installed. I am also a java developer and had a few JDKs installed as well as jres. Thinking it was my environment I did a complete wipe of jave from my system (I ran JavaRa and made sure everything was

2021-06-15 18:13:13    分类:问答    java   applet   jnlp   verification

How to find if a subarray has a specific sum inside a 2D array in Java ?

I am trying to solve a Image matching problem by comparing the average color of pixels present in both the source and pattern image. I have reduced this problem to a sub array sum problem, but cannot figure out a way to solve it. Lets say i have a 2D array ARR with all positive integers. I have a number x( which is the average of the pixel colors present in a small pattern image). I just need to find any subarray in ARR which has the exact sum x. I found a similar problem which could be solved with Dynamic programming here. http://www.geeksforgeeks.org/dynamic-programming-set-27-max-sum

2021-06-15 18:12:33    分类:问答    java   algorithm   multidimensional-array   dynamic-programming

Can Swagger @APIOperation allow to specify a list of list in Java?

I have a method in a Java class with signature like below and I want to add Swagger Rest documentation for it. public List<List<MyCustomClass>> getMyCustomClasses(String id){ // } I want to know if there is a way to have either response or responseContainer to return List of List objects? Something like below? @ApiOperation(value = "find MyCustomClass objects by id", response =MyCustomClass.class , responseContainer = "List<List>") I have no issues in generating swagger docs if the response of the method is just List where I could specify response =MyCustomClass.class , responseContainer =

2021-06-15 18:11:32    分类:问答    java   swagger   swagger-ui

What is the syntax to run a maven plugin from the command line.

I see that this has already been asked over here: How to execute maven plugin from command line? but I don't really understand the answer. It looks like the syntax is of the form: mvn foo:bar But I'm not really sure what foo and bar are supposed to be. Specifically I have configured the maven-resource-plugin like this: <plugin> <artifactId>maven-resources-plugin</artifactId> <version>2.5</version> <executions> <execution> <id>copy-resources</id> <phase>prepare-package</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <!--configuration here--> </configuration> </execution> <

2021-06-15 18:10:29    分类:问答    java   maven   maven-plugin   maven-resources-plugin

Is there a way to know maximally reached JVM call stack depth for a particular program run?

I've been coding one recursive function today and the recursion depth depends on the input length. I was wondering from the pure interest point of view, is there some way to monitor, probably in some JVM logs or elsewhere, what has been the maximal call stack depth during a particular program execution? After some thinking I can imagine an analytical approach to calculate this approximately but that would be very time-intensive and would require quite good knowledge of JVM internals and bytecode. JVM allows to configure the limit of a stack size memory, but I've never seen anything about how

2021-06-15 18:10:09    分类:问答    java   jvm

access exception when invoking method of an anonymous class using java reflection

I'm trying to use an event dispatcher to allow a model to notify subscribed listeners when it changes. the event dispatcher receives a handler class and a method name to call during dispatch. the presenter subscribes to the model changes and provide a Handler implementation to be called on changes. Here's the code (I'm sorry it's a bit long). EventDispacther: package utils; public class EventDispatcher<T> { List<T> listeners; private String methodName; public EventDispatcher(String methodName) { listeners = new ArrayList<T>(); this.methodName = methodName; } public void add(T listener) {

2021-06-15 18:09:28    分类:问答    java   events   reflection   anonymous-class   access-levels

Processing on MySQL query taking too long and throwing “Communications link failure”

I issued a query using a JDBC connection: Connection conn = null Class.forName("com.mysql.jdbc.Driver") conn = DriverManager.getConnection(dbHost, dbUser, dbPass) s = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); s.setFetchSize(Integer.MIN_VALUE); r = s.executeQuery (MY_SELECT_QUERY); while(...) { processResultSet(r); } The while runs for a long time processing the ResultSet. After around 1 hour i got the exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet successfully received from

2021-06-15 18:04:07    分类:问答    java   mysql   jdbc   database-connection

ECDH using Android KeyStore generated private key

I'm trying to implement ECDH in Android using a private generated by Android KeyStore Provider. public byte[] ecdh(PublicKey otherPubKey) throws Exception { try { ECPublicKey ecPubKey = (ECPublicKey) otherPubKey; KeyAgreement keyAgreement = KeyAgreement.getInstance("ECDH"); PrivateKey pk = (PrivateKey) LoadPrivateKey("Backend"); keyAgreement.init(pk); keyAgreement.doPhase(ecPubKey, true); return (keyAgreement.generateSecret()); } catch (Exception e) { Log.e("failure", e.toString()); return null; } } However, this exception is catched in keyAgreement.init(pk) : E/failure: java.security

2021-06-15 18:00:02    分类:问答    java   android   keystore