java

Why is my matcher failing?

I am passing a string into my song parser method and it is failing and I can't figure out why. Every thing is returning null or 0. My parser method is public static Song parseSong(String songString){ Map<String, String> songMap = new HashMap<String, String>(); Pattern pattern = Pattern.compile(".*<key>(.+)</key><(.+)>(.+)</.+>.*...

Clear Console in Java

Hi, Is there any way to clear ALL OF THE TEXT OF THE COMMAND CONSOLE (i.e. all the output of my class AND the output of everything outputted from other programs run before (not always Java)) which started the Java VM? ...

Java document state pattern?

Hi, I am a new to programming with Java and I would like to know if there is some common practice for managing state of opened document (is current state saved or dirty) , saving document, opening, creating new document and so on. How do you approach this? Right now I have my little Swing application and have actions for opening and cl...

Get a List of all Threads currently running in Java

Hi Is there any way I can get a list of all the running Threads in the current JVM (including the Threads NOT started by my class)? Is it also possible to get the Thread and Class objects of all Thread in the list? I want to be able to do this through code. ...

Java: ignoring an input stream - will buffers overflow and bad things happen?

Hi all, I have a client connecting to my server. The client sends some messages to the server which I do not care about and do not want to waste time parsing its messages if I'm not going to be using them. All the i/o I'm using is simple java i/o, not nio. If I create the input stream and just never read from it, can that buffer fill...

Why can't I compile my Java applications using Ubuntu?

I have been trying for what seems like two days now to get my java application to compile from the command line in Ubuntu. I know I have Java installed because I can run my applications in Eclipse & Netbeans and they work fine. But if I want to compile my applications from the command line I get the following error message: javac Main.j...

How to submit JCL on IBM zOS through Java web app?

Can someone tell me the best way to run a piece of JCL on IBM zOS from a Java web app on a different server (Windows). I also need get a response code back from the job. The 2 options at the moment are: 1) Using JES - But its hard to get the response back 2) Make a call through a DB2 procedure. Is there another (better) way ...

When do instance init blocks get called?

Consider this code: public class Main { static String s = "-"; public static void main (String [] args){ go(); System.out.println(s); Main m = new Main(); } {go();} static {go();} static void go(){s+="s";} } Its output is: -ss the instance init block is never called, why? ...

How can I let a user hit enter for a default value using the Scanner in java?

Lets say I wanted to have the following prompt: "Enter the number of iterations (400):" Where, the user can enter an integer or simply hit enter for the default of 400. How can I implement the default value in Java using the Scanner class? public static void main(String args) { Scanner input = new Scanner(System.in); System...

Lucene IndexReader.reopen doesn't seem to work correctly

I have a problem with Lucene 2.4, the situation being as follows: I have to deal with the possibility that there are 2 seperate processes operating on the same Index directory and they need to have the same data. This means that when one Instance adds a Document to the Index, the other application instances shall find the added Document...

Designing simple cell renderer for Nimbus look and feel

I have a simple-ish cell renderer which is composed of a few JLabels (the renderer itself extends JPanel) and I'm trying to get it to render sensibly in the Nimbus look and feel. Basically what is happening is that in the lighter rows (as Nimbus has alternate row coloring), my specific cell renderer is using the table background color (...

configure log4j to log to custom file at runtime

Hi, Can anyone please guide me as to how I can configure log4j to log to a specific file that I specify at run-time.The name and path of the log file are generated at run-time and the application must log to that particular file. Generally file appender entries in the log4j.properties file points to the log file that will be used by th...

Performance of HashMap with different initial capacity and load factor

Here is my situation. I am using two java.util.HashMap to store some frequently used data in a Java web app running on Tomcat. I know the exact number of entries into each Hashmap. The keys will be strings, and ints respectively. My question is, what is the best way to set the initial capacity and loadfactor? Should I set the capacit...

JAI Change JPEG Resolution...

Hi, I am having difficulty using the Java JAI (Java Advance Imaging) API to change the resolution of a JPEG image from lets say 1024x800 to 512x400. I have played around with the API and keep receiving stream or outofmem exceptions. Anyone with a working example. Thanks ...

What would be a quick and dirty way to get PHP talking to java?

We have a php setup for our web pages that is secure with HTTPS. The web app talks to a DB but we also want it to talk to a java server we have. The java server is a standalone java application (not web). We simply want a callback action after the PHP page finished writing to the DB done in the java server. What is a good way for this ...

getClass().getClassLoader().getResourceAsStream is throwing a NullPointerException

In Java How could getClass().getClassLoader() return null? The jar the 'class' is located in is NOT located under common/lib. The jar is NOT being boostrap-loaded. The ClassLoader for all classes within the jar is null. ...

Programmatically call @Controller

I am transitioning code that used implementations of Spring MVC's Controller to use the annotation stereotype @Controller. Everything is going fine except for one issue: Given a request/response, how do I programmatically handle requests for annotation-based controllers? Previously, (regardless of implementation) I was able to call: ...

How does one access a method from an external jar at runtime (part2)?

This is a continuation of the post http://stackoverflow.com/questions/1319661/how-does-one-access-a-method-from-an-external-jar-at-runtime McDowell responded with the code: public class ReflectionDemo { public void print(String str, int value) { System.out.println(str); System.out.println(value); } public static int getNumber...

Can't insert byte[] into MySQL using java

Following is the code I have used: byte[] bkey = key.getEncoded(); String query = "INSERT INTO keytable (name, key) VALUES (?,?)"; PreparedStatement pstmt = (PreparedStatement) connection.prepareStatement(query); pstmt.setString(1, "test"); pstmt.setBytes(2, bkey); pstmt.execute(); And following is an error I got: com.mysql.jdbc.ex...

Axis2 SOAP Envelope Header Information

I'm consuming a web service that places an authentication token in the SOAP envelope header. It appears (through looking at the samples that came with the WS WSDL) that if the stub is generated in .NET, this header information is exposed through a member variable in the stub class. However, when I generate my Axis2 java stub using WSDL...