java

java: StringBufferOutputWriter or StringBufferOutputStream?

I need to take a caught exception and get a String that is what would be printed using printStackTrace(). It looks like the simplest thing is to call printStackTrace(X), where X subclasses a PrintStream or PrintWriter, and gathers it to a StringBuilder and can return a String. Does such a thing exist? If not, any suggestions how to do ...

What's the best way to return multiple enum values? (java and C#)

more of original content deleted to make question easier to reference: So I have a House class that has a method House.buy(Person p), causing the person to buy the house. I want to know if its possible for the Person to buy the House, so I also have a method House.tryBuy(Player p) that returns if the Person can buy the house. I have an ...

Method in Java to create a file at a location, creating directories if necessary?

I am attempting to write a file using java.io, where I am trying to create it at the location "some/path/to/somewhere/then-my-file". When the file is being created, any of the directories on the path may or may not exist. Rather than throw an IOException because there are no such directories, I would like the directories to be created tr...

Java: Instantiate or Inheritance?

I am writing a logging service for one of my applications but I am sure many other applications would use this. In that case, would it make sense to make the application extend a class and have all my logging enabled by default (because some logging like application entry point and exit point are required at any cost) in the original cla...

How to intentionally cause a custom java compiler warning message?

I'm about to commit an ugly temporary hack in order to work around a blocking issue while we wait for an external resource to be fixed. Aside from marking it with a big scary comment and a bunch of FIXMEs, I'd love to have the compiler throw an obvious warning message as a reminder so we don't forget to take this out. For example, some...

Can JBoss instances communicate?

I've got a Java servlet that handles file uploads, but resides in the "intranet" instance of JBoss. It needs to write files to a directory in the "internet" instance of JBoss (on the same machine). The Java servlet can't be moved to the other instance. This is with JBoss 4.2 on a Solaris box. Is there a way for this to happen? Can there...

Memory profiling for Java desktop application

Hi, My application loads a data set of approx. 85bm to 100mb each time. The application's memory limit is set to 512mb, and this is, theoretically, more than enough. However, I found that if, in a single run of the application, I opened and closed the data set 5 times, the total memory consumption steadily increases, until I get an out...

many-to-many (self referencing problem) vs double one-to-many

Hello! I'm facing some of the problem some of you already talked about and sorry to bring this out again. It's just like I still don't get certain aspect of hibernate. I'm using maven2, hibernate 3.2.5 ga, spring 2.6.5 SEC01, hsqldb 1.8.0.10, netbeans 6.7.1. I'm bulding a user and contat management and I've managed to get a working "m...

Tomcat6 + Ubuntu + Servlet

I am trying to make servlet. I have installed tomcat6 on ubuntu with admin examples and docs. I am able to run the examples provided. But when i try to make my own servlet it doesnt work. I did following steps Under the ROOT i create folder with -ROOT ----myapp ------WEB-INF ---------classes I made two files one is index.html whi...

Making Controls public/Global in Netbeans with Java.

So I have multiple forms for my current project and I have made classes that interact and do some utility work behind these forms. However I am unable to access controls on other forms. Say I have a text control on Form A and I want to use a class that receives/manipulates data from a completely different Form B. My classes and Form ...

Java Reflective Method Call with Generics

Given this method: public final void foo (List<MyClass> bar){ .. } I want to be able to call this method reflectively. In order for getMethod to work, I have to change it to: public final void foo (List bar){ .. } This does not seem right for obvious reasons, but no combination of inputs to getMethod seem to work otherwise. I have ...

Recommendation for the Java SE project to use all java skills?

I am looking for a project to use most of my java se skills (oop,java api..),i searched but i can not find good project to dive in and start.It doesnt have to be new one , projects that done before can be solution too.Any advice would be appreciated. ...

Spring's IOC with annotations is confusing for a Guice guy. Help to enlighten me

I came into IOC via Google Guice. And now I've been forced to use Spring 2.5.6 at work & I am lost because Spring is quite complicated. Here are some questions after reading bits of the spring docs: What is the difference between @Service, @Controller and @Component ? If I just want to auto wire my objects like Guice, do I need to be ...

Use datagrams in java to send video/audio from client to server?

Hey everyone, I'm having a bit of a problem with UDP and Datagrams. I'm supposed to make a server that will get a request from the client to send a file in the same directory. The UDP Server will then get this file (a video), put it into a datagram and send it. I think I know how to do it, but I can't put the file in the datagram. I'm...

Determine the classes referenced in a .class file

What's the best way to (programmatically) parse a compiled Java (.class) file and generate a list of any and all other Java classes it references? ...

How do I retrieve the values of checkboxes when the Id values are dynamically generated

I am dynamically naming a set of checkboxes based on certain files names (user is selecting file to include for some processing). Is there a way I can retrieve the files names or do I need to save them to a session object of some sort and then use the retrieved values (from the session object) to retrieve the values of the checkboxes. ...

-server option for Launch4j?

I've been poking around the launch4j website and can't seem to figure out how to set the -server program option, there's an old forum post indicating it might be a future option but no further details are available. Is it possible to run the JVM in server mode using Launch4j? ...

Does anyone have any ideas for an assignment in game programming?

Much like the author of Give me an assignment in C, I'm looking to learn game programming and I learn best by doing, but I don't have any good ideas for games to program which will teach me the skills and for whom the graphics are freely available. I have written a basic pacman game but apart from that I haven't done any other games. ...

Reading a PDF document with iText not working sometimes

I am using iText to read from a PDF doc. I am getting an ArrayIndexOutOfBoundsException. The strange thing is it only happens for certain files and at certain locations in those files. I suspect it's something to do with the way the PDF is encoded at those locations but can't figure out what the problem is. I have looked at this questio...

java.util.LinkedList causing infinite loop/OutOfMemoryError

I'm implementing Cloneable with one of my classes, and I need to make a shallow copy (yes, only shallow) of a java.util.LinkedList to do it. I tried using myList.clone() //myList is a java.util.LinkedList<myType> but that was causing my program to stall, so I switched to using the copy constructor: new LinkedList<myType>(myList) ...