Skip to content

Tag: java

How to change the Java JDK version in an Ant task?

I need to compile my source code to be compatible with JRE 1.6. However, when I attempt to set the compiler attribute of the javac task to be javac1.6, Ant will still compile my code with javac1.7. I have also tried setting the compiler version to be “modern” and that did not work. My JAVA_HOME is…

Fastest way to scan ports with Java

I made a very simple port scanner, but it runs too slow, so I’m looking for a way to make it scan faster. Here is my code: This code tests if a specific port is open on a specific ip. For timeout I used a minimum value of 200 because when I go lower it doesn’t have enough time to

Spring AOP Advice Called Twice

For some reason, my Spring AOP advices are being called twice. I checked: Spring AOP advice is called twice but I am not using the Component annotation, and am declaring the aspect bean once and annotating it with @Aspect and that’s it. Somewhat belatedly I realized that one of my classes was not implem…

Java applets – is it a wrong choice today?

I have some non-trivial computational code that need to be applied on data already downloaded into the browser DOM and captured from user interactions. I do not wish to expose this code. I am wondering if: Write a webservice and communicate with the browser over websocket or HTTP. The trade-off is speed of in…

Assigning values of an array in a for loop java

Im still starting out in java – and any guidance would be great on this. I’m basically hoping to create an array, then assign values to that array in a for loop. The code I have at the moment is: All i wanna do is make an array with each entry the number of the iteration (using this method) I

How to implement enum with generics?

I have a generic interface like this: This interface has limited instances, hence it would be best to implement them as enum values. The problem is those instances have different type of values, so I tried the following approach but it does not compile: Any idea about this? Answer You can’t. Java doesn&…

How to use for checking multiple Roles?

I want to display some content conditionally based on Roles using Spring Security JSP taglibs. But in Spring Security 3.1.x is checking for only one role. I can use but ifAllGranted is deprecated. Any help? Answer There is a special security expression in spring security: hasAnyRole(list of roles) – tru…