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…
Executors.newCachedThreadPool() versus Executors.newFixedThreadPool()
newCachedThreadPool() versus newFixedThreadPool() When should I use one or the other? Which strategy is better in terms of resource utilization? Answer I think the docs explain the difference and usage of these two functions pretty well: newFixedThreadPool Creates a thread pool that reuses a fixed number of t…
How do I access a config file inside the jar?
I’m using FlatPack to parse and load data from flat files. This requires loading a config file that stores mappings of the columns of the flat file. I have a constant to define the location of the mapping file: I have a parse(File dataFile) method that actually does the parsing: When I jar up everything…
Getting the class name from a static method in Java
How can one get the name of the class from a static method in that class. For example public class MyClass { public static String getClassName() { String name = ????; // what goes here so …
How can I avoid ResultSet is closed exception in Java?
As soon as my code gets to my while(rs.next()) loop it produces the ResultSet is closed exception. What causes this exception and how can I correct for it? EDIT: I notice in my code that I am nesting while(rs.next()) loop with another (rs2.next()), both result sets coming from the same DB, is this an issue? A…