I’m trying to use a timer to schedule a recurring event in an application. However, I want to be able to adjust the period at which the event fires in real time (according to the users input). For example: I then start a new instance of this class and call its set period function. However, when I do tha…
Tag: java
.class vs .java
What’s the difference between a .class file and a .java file? I am trying to get my applet to work but currently I can only run it in Eclipse, I can’t yet embed in HTML. Thanks **Edit: How to compile with JVM then? Answer A .class file is a compiled .java file. .java is all text and is human reada…
Initialization of an ArrayList in one line
I wanted to create a list of options for testing purposes. At first, I did this: Then, I refactored the code as follows: Is there a better way to do this? Answer Actually, probably the “best” way to initialize the ArrayList is the method you wrote, as it does not need to create a new List in any w…
“Invalid signature file” when attempting to run a .jar
My java program is packaged in a jar file and makes use of an external jar library, bouncy castle. My code compiles fine, but running the jar leads to the following error: Exception in thread “main” java.lang.SecurityException: Invalid signature file digest for Manifest main attributes I’ve …
How to change command prompt (console) window title from command line Java app?
How to change and update the title of the command prompt window from the java command line application? Every time I run my application, the command prompt window title shows: C:WINDOWSsystem32cmd.exe – java MyApp. I’d like to change and update the window title as the java program runs, for exampl…
Java 256-bit AES Password-Based Encryption
I need to implement 256 bit AES encryption, but all the examples I have found online use a “KeyGenerator” to generate a 256 bit key, but I would like to use my own passkey. How can I create my own key?…
Display Hibernate Query in JTable
I’m seeking an efficient way to display an SQL table queried via Hibernate in a JTable. It would probably be preferable to use the List returned by that (In this case, that would make a list of Files objects (where Files is an internal class, not java.io.File)), but I won’t be picky as long as it …
How do I use optional parameters in Java?
What specification supports optional parameters? Answer There are several ways to simulate optional parameters in Java: Method overloading. void foo(String a, Integer b) { //… } void foo(String a) { foo(a, 0); // here, 0 is a default value for b } foo(“a”, 2); foo(“a”); One of th…
Java Large Files Disk IO Performance
I have two (2GB each) files on my harddisk and want to compare them with each other: Copying the original files with Windows explorer takes approx. 2-4 minutes (that is reading and writing – on the same physical and logical disk). Reading with java.io.FileInputStream twice and comparing the byte arrays …
Is it possible to disable jsessionid in tomcat servlet?
Is it possible to turnoff jsessionid in the url in tomcat? the jsessionid seems not too search engine friendly. Answer You can disable for just search engines using this filter, but I’d advise using it for all responses as it’s worse than just search engine unfriendly. It exposes the session ID wh…