java

TreeMap memory usage

How can one calculate how much memory a Java TreeMap needs to handle each mapping? I am doing an experiment with 128 threads, each dumping 2^17 longs in its own array. All these 2^24 longs are then mapped to ints (TreeMap<Long,Integer>), each array reference is nulled before moving to the next. That should amount to 128+64 MB for the ...

java different sorting methods on one set of data

Hello, Suppose that I am collecting n amount of Strings into an array, or an array list, or some other data structure. I want to come up with a design that will allow the user to specify how the Strings will be sorted: -If the user specifies option A, then the Strings will be put into a Vector, and then sorted and printed. -If the u...

String to Multidimensional Arrays

I have a string which represents a multidimensional array in the format: [[A, a], [B, b]] Is there a easy way to convert this string into multidimensional arrays. Though, for now I am just looking for the above solution the string itself is bit more complicated. for example in [[A, a], [B, b]] where A could be "This is a sample te...

Why is it more memory efficient to read input as stream vs. string?

We're using HTTPClient to implement a REST API. We're reading the server response using: method = new PostMethod(url); HttpClient client = new HttpClient(); int statusCode = client.executeMethod(method); String responseBody = method.getResponseBodyAsString(); When we do this we get this warning: Dec 9, 2009 7:41:11 PM org.apache.com...

Saving each of this boards into a Data Structure

This is a dumb question and I feel embarrassed to ask it, but I'm pressed for time and I'm burnt out. I have this sambple input: 1 4 2 3 0 5 6 7 8 3 1 2 6 4 5 0 7 8 -1 -1 -1 each group of numbers represents a board of the 8 puzzle, I don't know how many boards will appear on the text file. I only know its end is marked with -1 -1 ...

file: URIs and Slashes

An application I'm working on involves accessing files on network file shares, and we're using URIs to specify the files' locations. My understanding of the file: URI is that they should take the form of file://+path. In the case of a Windows network share, this path looks something like \\servername\dir\file, so the resultant URI beco...

How to escape quotes "" characters in mysql and java

How can we escape quotes "" characters in Java and MySQL? Incoming xml file has quotes and am parsing through that file using java and so i want to escape quotes here but in database it should contain quotes and while am doing query the result would have quotes and while displaying on webpage also it should show quotes. Hope am making m...

security problem with Java ScriptEngine

I just started to use the Java ScriptEngine to do little extensions to my Application then i noticed that i can import all the java classes in the script and use them without restrictions. Is there a way to specify what classes a script can use? I dont want them to do things like java.lang.System.exit(1); ...

reseting a flow layout with a button

What I am trying to do here is set the layout scheme once I press a button to align all the buttons to the left of the contentPane I have three buttons this is the code i have for that particular button leftButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cp.setLayout( new FlowLayout(F...

how long can spring hibernatetemplate createSQLQuery where in(..) can be?

is there any limit of statement i can use where in(1,2,3,4,5,6....) in createSQLQuery in spring hibernatetemplate() ? ...

Can i start a thread in a catch in JAVA

I am trying to solve the collatz conjecture. I am using HashMap and Vector classes. I have to iterate the loop 2 147 483 648 times, but after I store 8,438,409 values in HashMap I'm getting an OutOfMemoryError. I'm running the program in Eclipse and have set -Xmx1024m option, but it didn't help. So, I'm catching the above error and try...

How to resolve swing listener memory leaks?

Background So I read that often memory leaks within Swing applications originate from the use of various listeners (mouse, key, focus, etc). Essentially, you register an object as a listener and forget to deregister the object, the notifier ends up holding onto the reference of the object, leaking a bit of memory. I knew our applicatio...

Strategies for deploying an exploded ear

I have a build process that creates an ear in a fairly complicated manner (multiple EJB jars, a couple of wars, a couple of sars (which are JBoss specific). The ant process for piecing this together is somewhat complex. What is the best strategy to not recreate the creation logic of the ejb creation in ANT but still be able to deploy ex...

Tackling the 8-puzzle problem via BFS

I've heard that the 8-puzzle problem can be tackled via BFS, but I don't understand how. I wanna know the intermediate steps that I need to get from a board like this: 3 1 2 6 4 5 0 7 8 to 1 2 3 4 5 6 7 8 0 Are the intermediate steps "levels" on a BFS search? By the way, this is basic homework, I don't care about optimality. ...

Java generics, explain please

What do T and S mean? public void main(String... abc) ; what does ... mean? Is ... called generic as well? ...

Using MySQL and database and having ClassNotFoundException

I have these two classes in my database package:(DBManager and TaskManager class) and I create a new object in my main frame which is in the other package and I also imported the database package for my main frame and I call addBirth() on my object,and I want to insert these arguments in my table="birthsql" in MySQL but I found this exce...

What happens when subclasses don't define a constructor in Java?

I have a few cases I wonder about. First, if you have no constructor: class NoCons { int x; } When I do new NoCons(), the default constructor gets called. What does it do exactly? Does it set x to 0, or does that happen elsewhere? What if I have this situation: class NoCons2 extends NoCons { int y; } What happens when I call new N...

Return generic type in a WebService

I'm green hand in web-service. I wrote a generic class as a value holder like this: public class SearchResult<T> { private List<T> resultSet; } Then I write a web-service method: public SearchResult<Book> getSearchResult(){ ... } When I was using maven-jaxws-plugin to generate client files, I found that the generic type inf...

Best free Code Review tool for Eclipse/Java/Flex Development

I'm using Eclipse and I'm wondering what the best Eclipse/Java/Flexbuilder code review tool is. If it matters we're using SVN as our SCM. Here are the following I've come across: Jupiter - seems like it's been around for awhile it looks like there is only a single developer on the project and the documentation mentions rather old vers...

Jump over parent constructor to call grandparent's

The problem is this: I have an abstract class that does some work in its constructor, and a set of child classes that implement the abstract class: class AbstractClass { AbstractClass(){ /* useful implementation */ } } class ConcreteClass1 extends AbstractClass { ConcreteClass1(){ super(); /* useful implementation */ } } Th...