java

Killing a windows session from a Java program

I am running a tomcat server and am attempting to update code on that server. To do this I need to shut down the server reliably in a Windows environment. To the best of my knowledge, the tomcat shutdown.bat script can have issues with runaway threads, and I need this to work even if I accidentally create a thread that will keep the .b...

Are Java daemon threads automatically killed when their parent exits?

If a Thread creates a daemon Thread, can I rely on the fact that when the parent exits the run method, the son will also terminate? ...

Java AOT + loading java classes dynamically

I'm building a plugin system for my application. I've read that anyone can decomple .class files and therefore I'm forced ot use a Ahead-Of-Time compiler (right?). The problem is that I need to load some plugin classes dynamically. Right now I'm loading all .class files in a folder and invoking a static method (I never create a object) a...

Java: Search in HashMap keys based on regex?

I'm building a thesaurus using a HashMap to store the synonyms. I'm trying to search through the words based on a regular expression: the method will have to take a string as parameter and return an array of results. Here's my first stab at it: public ArrayList<String> searchDefinition(String regex) { ArrayList<String> results = new ...

What are Reified Generics, how do they solve the Type Erasure problem and why can't they be added without major changes?

I've read Neal Gafter's blog on the subject and am still unclear on a number of points. Why is it not possible to create a implementations of the collections api that preserve type information given the current state of Java, the JVM and existing collections API? Couldn't these be them replace the existing implementations in a future ve...

Are there any good Maven ant tasks documentation/tutorials?

I would like to try using maven from ant (for exaple to build my Java SE apps that needs all dependencies stored in ./lib/*, or just because doing anything short of dependency management in maven is too damn hard ;)). But the documentation is nonexistent, and google also didn't give me a clue on how to use them. So any good docs/tutori...

Workaround for no default browser on Linux?

I am trying to use Desktop.browse() to invoke a URL, this works fine on Windows machines or on Linux machines with a default browser configured. However, it throws an IOException exception when no default browser is found on Linux. What are some of the ways to work around this? I suppose I can attempt to launch Firefox and assume its ...

What does it mean to be a daemon thread?

I'm fully aware of the impact of flagging a thread as a daemon thread on JVM exit (if all non-daemon threads exit, the JVM will exit.) Are there other side-effects to setting a thread as a daemon? (as a complete aside, which is really irrelevant except for semantics, is the meaning of a daemon thread not backwards in this case: shouldn...

How to detect unused properties in Spring

I'm working on a Spring 2.0 project, without annotations. We're using several PropertyPlaceholderConfigurer beans with different pre- and suffixes to load properties from different property files. This works beautifully. Because of the large number of property files and properties, I wanted the application to list the properties which a...

Generics confusion

Below is a question from Kathy & Bert Bates SCJP 5 preparation CD. I have posted this elsewhere too, but have not gotten a satisfactory explanation until now.... Please help me understand this: public class BackLister { //Insert code here { List<T> output=new LinkedList<T>(); for(T t:input) output.add(0,t); ...

Java: find 'connected components' in graph as HashMap

Ok, so here goes: I'm building a thesaurus using a HashMap <String,ArrayList<String>> to hold words and their synonyms (this data structure is required). For the purpose of the assignment, the synonymity relation is considered transitive. (We can imagine the thesaurus as a graph). What I'm trying to accomplish is to print this graph in ...

Crash reporting for java

Do you know any good crash reporting systems for Java or any open source projects which use a crash reporting system? ...

Any way to Invoke a private method?

I have a class that uses XML and reflection to return Objects to another class. Normally these objects are sub fields of an external object, but occasionally its something I want to generate on the fly. I've tried something like this but to no avail. I believe that's because JAVA won't allow you to access private methods for reflection....

How do I identify that I am at the last byte of a serialized Java object?

Question What is (if there is any) terminating characters/byte sequences in serialized java objects? Background I'm working on a small self-education project where I would like to serialize java objects and write them to a stream where there are read and then unserialized. Since, I will need to identify the borders between serialized ...

Avoiding a lost update in Java without directly using synchronization

I am wondering if it is possible to avoid the lost update problem, where multiple threads are updating the same date, while avoiding using synchronized(x) { }. I will be doing numerous adds and increments: val++; ary[x] += y; ary[z]++; I do not know how Java will compile these into byte code and if a thread could be interrupted in t...

How to load .js files into a Rhino context in Java

Here is my situation: I have access to a Rhino Context object in a Java class. I want to read in a bunch of .js files and pass them along to the Rhino context to have them evaluated. I'm not really interested in having the functions in the .js files available in the scripting context so much as I am in just having the variables that a...

How to convert int[] to Integer[] in Java?

I'm new to Java and very confused. I have a large dataset of length 4 int[] and I want to count the number of times that each particular combination of 4 integers occurs. This is very similar to counting word frequencies in a document. I want to create a Map<int[], double> that maps each int[] to a running count as the list is iterate...

Include one java file in another java file

I'm pretty new in Java, so perhaps this question is not make me sound very stupid. How can I include one java file into another java file? For example: If I have 2 java file one is called Person.java and one is called Student.java. How can I include Person.java into Student.java so that I can exstend the class from Person.java in Stude...

how to draw rectangle on java applet using mouse drag event

hi, i am using java. i want to draw rectangle based on mousedrag event. if user dragging the mouse, then the rectangle on the applet should increase or decrease basing on current mouse coordinates. i have the following code. in the following code i am using [b]SelectionArea[/b] class which extends a canvas on which i am performing drawi...

Convert Semi-Colon Text to Excel

Hi All, I need to convert a semi-colon delimited file to an Excel. However, there are some fields that must be removed from the Excel file, and some extra fields to be added. These extra fields are drop-down fields. Is there any way to do this? Programming language that is preferably to be used is Java, but also welcome the possibility...