java

Java: why don't these variables initialize?

I'm working on an example from Bruce Eckel's book and i was wondering why the initialized values don't stick when I output them? class InitialValues2 { boolean t = true; char c = 'x'; byte b = 47; short s = 0xff; int i =999; long l =1; float f = 3.14f; double d =3.14159; InitialValues reference; ...

howto increase lines of java stack trace dump?

Is there a way to make Throwable.printStackTrace(PrintStream s) print more lines, so that I can see beyond the final line of "... 40 more" ? Thanks, Ben ...

Check if enum exists in Java

Is there anyway to check if an enum exists by comparing it to a given string? I can't seem to find any such function. I could just try to use the valueOf method and catch an exception but Iv been taught that catching runtime exceptions is not good practice. Anybody have any ideas? ...

Is there a way to get the javadoc tool to document annotations?

In my project, we use a number of annotations that would be very useful to see in the javadoc API documentation. Does anyone know a simple way to include annotations in generated javadocs? I don't want to write my own javadoc plugin. Are there any solutions out there? ...

how to find text in jar file which is in war file?

Hi, is there a way to grep(find) the text in a particular file, which is in *.jar and this *.jar is in *.war? ...

Functional programming applied

I have been interested in programming all my life and for the past 6 years I have worked almost exclusively with Java. I just finished with my University studies and have a job as a Java developer for a company. All these years programming has been a hobby and a favorite past time, but this had a slightly negative effect in the sense th...

Why doesn't Java tell you which pointer is null?

I've always wondered why the JVM doesn't tell you which pointer (or more precisely, which variable) is null when a NullPointerException is thrown. A line number isn't specific enough because the offending line can often contain numerous variables that could have caused the error. Is there any compiler or JVM flag that would make these ...

HtmlUnit property undefined script error

I’m submitting a form using java HtmlUnit package. I am able to get pages and submit forms but on one page I’m getting a ScriptException error. The message is “Cannot set property "disabled" of undefined to "0"” I think it might be caused by a javascript method that tries to set a variable that has not been declared in the form but I’...

Adding java time objects

How do you say, add 1 hour to a given result from calendar.getTime? ...

Why does this() and super() have to be the first statement in a constructor?

Java requires that if you call this() or super() in a constructor, it must be the first statement. Why? For example: public class MyClass { public MyClass(int x) {} } public class MySubClass extends MyClass { public MySubClass(int a, int b) { int c = a + b; super(c); // COMPILE ERROR } } The Sun compiler says "call to super ...

Java serialization: readObject() vs. readResolve()

The book Effective Java and other sources provide a pretty good explanation on how and when to use the readObject() method when working with serializable Java classes. The readResolve() method, on the other hand, remains a bit of a mystery. Basically all documents I found either mention only one of the two or mention both only individual...

Is shifting bits faster than multiplying and dividing in Java? .NET?

Shifting bits left and right is apparently faster than multiplication and division operations on most (all?) CPUs if you happen to be using a power of 2. However, it can reduce the clarity of code for some readers and some algorithms. Is bit-shifting really necessary for performance, or can I expect the compiler/VM to notice the case and...

Problems running unit tests after upgrading from Netbeans 6.5 to Netbeans 6.7

Hi All, I am experiencing issues with existing projects from Netbeans 6.5 in Netbeans 6.7 when selecting a file under "Test Packages" and performing a right click-->Debug, or right click-->Run. The error reported is: java.lang.NoSuchMethodError: main Exception in thread "main" Java Result: 1 I am using JUnit 4.x I have not changed ...

How to get maven to timeout earlier while downloading dependencies?

I am building my project with Apache Maven and have a custom repository configured but when it hits the repository it just hangs for a very long time with Downloading: http://maven.mycompany.com/m2/org/springframework/spring/2.5.6/spring-2.5.6.pom after a few minutes it goes and downloads it from the central repo Downloading: http://r...

authenticate with ntlm (or kerberos) using java UrlConnection

I need to consume a rest web service with java, passing the credentials of a domain user account. right now I'm doing it with classic asp set xmlHttp = server.createObject( "msxml2.serverxmlhttp" ) xmlHttp.open method, url, false, domain request.Credentials = new NetworkCredential(user, password, domain); request.Method = WebReques...

MATLAB + JNI = error?

Anyone out there used MATLAB's javaObject() function with a JAR file that uses JNI? I'm trying to get JHDF5 running and it seems like it bombs when it tries to get access using jhdf5.dll so I don't really know what to do next. :( edit: I am NOT trying to read basic HDF5 files. I have my own custom Java code that does something with HDF...

Java application if/case recommendation

I am writing an application for a Java course. I am a complete beginner and am just going off material I have learned from the course and from the web. The application is exhibiting some behavior and I am not sure what is causing it. The application is GUI based and does calculations on user input. For the action listener section, I hav...

Application to generate Java class hierarchy diagram

Looking for a tool that: Produces a visually appealing, orthogonally structured graph hierarchy Outputs high-quality PNG images (300dpi+) Visually differentiates classes, abstract classes, interfaces, and enumerated types (preferably by colour) Interactive user interface Allows pruning of packages and/or individual classes from the dia...

Hibernate flush and JTAUnexpectedRollbackException

Hi All, I am using Spring and Hibernate. And Atomikos for transactions. I use annotation based transactions. I am having a DAO object and in one of the methods I call entityManager.persist() to save the object. Now whenever there is an ORA- error during update, for example a constraint is violated or one of the columns is having length...

Java tutorials for beginning programmer

I have next to no programming experience, and absolutely none with Java, so I'm looking for some good online tutorials/primers. Please point me to good ones for beginners like me. Thanks. ...