java

How to reduce the total memory hogging by compacting my Objects in Java?

I have a table with around 20 columns with mostly consisting of varchars and decimals. This table has almost 1.5M rows. But few things are common in them like column1 consists of only 100 distinct strings , column2 has almost 1000 and column3 has almost 500. Right now, I am storing all these column values in a map with Key as first 5 c...

"No context factory" exception thrown when using JBoss' VFS

Hi everybody, I am trying to get a ressource contained in a JAR file . This Jar is used as a dependancy of a web projet MyWebApp. I am using JBOSS 5.1.0 The code in the jar file is : // MyClass Class // part of myFunction ... Enumeration<URL> configEnum; configEnum = this.getClass().getClassLoader().getResources("MyFile"); while (co...

Set logging level at handler or logger?

I'm using the Java Logger for the first time and noticed it is possible to set the logging level either through handler.setLevel(...) or through logger.setLevel(...). I can't seem to find a difference though. Is there a difference? And if there is, what is the recommended way to do it? ...

How do i input a string from a buffered reader?

Im used too using Scanner mainly and want too try using a buffered reader: heres what i have so far import java.util.*; import java.io.*; public class IceCreamCone { // variables String flavour; int numScoops; Scanner flavourIceCream = new Scanner(System.in); // constructor public IceCreamCone() { } // methods public String getFlavou...

How to make sure I'm using the "server" JVM?

Sun's JVM comes in two flavors: -client and -server, where the Server VM is supposed to be optimized for long running processes, and is recommended for server applications. When I run java with no parameters, it displays the usage options, which includes the following text: The default VM is server, because you are running o...

How to properly roll back to an older version in CVS HEAD using Eclipse?

I have a CVS repository in which I have a set of Eclipse Java projects where I need to roll HEAD back to the state it was at a specific time yesterday essentially abandoning all commits happened since said time. I've tried different things, including using "Replace with another branch or version" which gives the proper sources, but wher...

JUnit: pause for user input

I'm learning JUnit. Since my app includes graphical output, I want the ability to eyeball the output and manually pass or fail the test based on what I see. It should wait for me for a while, then fail if it times out. Is there a way to do this within JUnit (or its extensions), or should I just throw up a dialog box and assertTrue on th...

Bulk import from Informix into Oracle

Hi. We need to pull some tables from an Informix SE database, truncate tables on Oracle 10g, and then populate them with the Informix data. Does a bulk import work? Will data types clash? I'd like to use a simple Java executable that we can schedule daily. Can a Java program call the bulk import? Is there an example you can provide? T...

Java Stanford NLP: Part of Speech labels?

The Stanford NLP, demo'd here, gives an output like this: Colorless/JJ green/JJ ideas/NNS sleep/VBP furiously/RB ./. What do the Part of Speech tags mean? I am unable to find an official list. Is it Stanford's own system, or are they using universal tags? (What is JJ, for instance?) Also, when I am iterating through the sentences, lo...

Known incompatibilities between Java 1.4 to Java 5

A list of potential compatibility problems is provided by Sun : http://java.sun.com/j2se/1.5.0/compatibility.html Have you encountered other problems when running/testing old-1.4-applications against Java 5 (eg. A specific library no longer working ....) ? ...

xstream > backwards compatibility when making an abstraction in the model

I have class A { @xstreamalias("obj1"); Object obj1; @xstreamalias("obj2"); Object obj2; } and I want to change to class AbstractA { @xstreamalias("obj1"); Object obj1; } class A extends AbstractA{ @xstreamalias("obj2"); Object obj2; } without loosing the contents of obj1. currently I have no trouble read...

StringBuffer append("")

I'm currentlly refactoring an application using a lot of this: StringBuffer buff1 = new StringBuffer(""); buff1.append("some value A"); buff1.append(""); buff1.append("some value B"); The coder that made those code lines didn't seems to be an idiot, is there any reasons I can't see to use the append("") to a StringBuffer? ...

java newbie question

if I have something like this Map<String, Foo> foos; ... Foo f = foos.get("key1"); foos.removeAll(); Am I still able to do String s = f.getSomeProperty(); ...

Understanding Java's GC logs

I turned on verbose GC options on my JDK, and now I'm seeing lines such as 25.598: [CMS-concurrent-sweep-start] 25.622: [CMS-concurrent-sweep: 0.023/0.024 secs] [Times: user=0.02 sys=0.00, real=0.03 secs] 25.623: [CMS-concurrent-reset-start] 25.629: [CMS-concurrent-reset: 0.007/0.007 secs] [Times: user=0.01 sys=0.00, real=0.00 secs] ...

Java Reflection: Count of methods with an annotation?

This works fine for filtering out methods with the Analyze annotation: for (Method m : ParseTree.class.getMethods()) { if (m.isAnnotationPresent(Analyze.class)) { What if I just want a count, without looping through? Is there some method that returns how many methods in a certain class have a certain annotation? ...

Comparing strings in java

String string1 = "Hi there"; String string2 = "Hi"; String string3 = "Hi"; System.out.println(string1.substring(0, string2.length()) == string2); //1 System.out.println(string1.substring(0, string2.length()).equals(string2)); //2 System.out.println(string1.substring(0, string2.length()).compareTo(string2)); //3 System.out.println(string...

When to use intern()

I see a lot of legacy code like this: class A { public static final String CONSTANT = "value".intern(); ... } I don't see any reason for the intern(), as in the Javadoc one can read: "All literal strings and string-valued constant expressions are interned." Is there some intent of this, maybe in past revisions of the language?...

Setting source port on a Java Socket?

I'm very new to socket programming: Is it possible to explicitly set the the source port on a Java Socket? I am working on a client/server application in which clients could potentially be listening for replies from the server on several ports. It would be nice if I could set this reply port on the client side when initializing the So...

Generating simple crud applications in Spring based off existing database or hibernate configurations?

I'm attempting to learn Spring MVC but have been spoiled by Grails. While I am able to get a basic web application working I was wondering if there were any tools that could do some of the work to create a crud application given a database or hibernate data model? The only one I've found so far is http://www.skywayperspectives.org/portal...

Which Java based MVC framework is most similar to ASP.NET MVC?

I have been learning ASP.NET MVC in the last few months and I think it is a great improvement over ASP.NET. For me personally, it is a joy to use (as opposed to ASP.NET WebForms :)) I started wondering how the .NET world managed to live so long without any such framework (at least not wide spread and supported by Microsoft as there may b...