java

Why does ClassCastException not show the class name?

In Java 1.4.2 and earlier versions, if you get a ClassCastException, you can see the exception stack trace but not the class name. If you want to find out the class of the object for which casting failed, you have to debug. Is it still the same in later Java versions? If so, when did it change? ...

Is it ok to instantiate an exception without throwing it?

Suppose I have a MyException class that subclasses Exception. I'm using this class to include contextual information when errors occur in my code. I typically use it to wrap one of the "standard" exception classes. For example, if an error happens during input validation, I will do something like if (invalidInput()) throw new MyExcep...

Java Illegal class modifiers Exception code 0x209

I have an issue with a legacy code base. I want to start compiling it with 1.6 class format, but there is one problem which reveals itself only when I try to run the compiled code. I get the following exception: java.lang.ClassFormatError: Illegal class modifiers in class FooBar 0x209 Googling this doesn't reveal a lot of details. Acco...

Java milli second precision

Is there a Java API/suggestion to use instead of System.currentTimeMillis() to get current time in milli second precision on windows - requirement is two subsequent calls with a sleep time of 1ms in between should give two different time - currently i need to explicitly sleep for 15 ms to get different times ...

Adding image to borderlayout CENTER

I have a class Background that extends JPanel. The point of this class is that contains an image that is displayed on it. I also have a class GraphTest that extends JFrame (this is the programs main window). In this frame, I have a menu with the option "new". When I press new, I am supposed to get a filechooser window where I can select...

Avoid printing unicode replacement character in Java

In Java, why does Character.toString((char) 65533) print out this symbol: � ? I have a Java program which prints these characters all over the place. Its a big program. Any ideas on what I can do to avoid this? ...

PNG image with transparency on SWT

I've got a Composite and would like to use a png file as background image. I can do that, the problem is when the image uses transparency it doesn't work and shows a white colour instead. Any thoughts on how to get this to work? Thanks! ...

error marshalling return;

I am getting the following exception when I tried to execute one my service in my server which is deployed as EJB2.0 stateless session bean. Error executing services::error marshalling return; nested exception is: java.io.NotSerializableException: xxx.xxx.xxx.PmsService here xxx.xxx.xxx.PmsService is my class which is already implem...

How to run a Maven JME project in netbeans ?

I have created a maven project with j2me-archetype using netbeans. It creates a project with a default MIDLet (SampleMIDlet.java). But when I try to run the project it says that No Main Class Found. Can anyone tell that why it is going for Main class instead of existing Midlet ? ...

Which Swing layout(s) do you recommend?

There are 8 layout managers in the Java library alone, and then there's a bunch of 3rd party products as well. The other day, I tried to use SpringLayout and... well, it ain't working out for me. See my other question. So... if you have a Swing app to design, and you want your layout just so, what are your preferred layout managers? Any...

What causes JVM exit code 10?

An Eclipse RCP aplication running on Mac OS X 10 is crashing with java exit code 10. What does this mean, and what might be a possible cause? Additional information: eclipse.buildId=unknown java.version=1.5.0_20 java.vendor=Apple Inc. BootLoader constants: OS=macosx, ARCH=x86, WS=carbon, NL=fi_FI Command-line arguments: -os macosx -ws ...

Windows 7 Application Icon and Taskbar

I have an application that uses 25x25 png image for application icon on Windows xp this fits perfectly on the taskbar however I installed Windows 7 on a virtual machine and taskbar on windows 7 resizes the icon, it becomes a big blur. What type of icon should i use the on the task bar? Forgive my ignorance, if this is a stupid question b...

String relate source code

Question 1. I want to print my from the String s = " This is my house"; using core java? Question 2. I want to print house is my This from the String s = " This is my house "; using core java? ...

What pattern fits between a façade and a DAO?

I'm in the process of designing part of my companies architecture for its JEE web applications. I'm pretty clear on the reasons to use a façade and one or more DAOs. The problem I have is this: There will be some logic that definitely belongs in the integration tier because it's all about keeping the data model consistent. Except the lo...

Checking serial code correctness

Hi, I have a method in java which generates a serial code based on a number of parameters. Now I would like to have another method which accepts the same parameters + the serial code, and tells me whether or not this serial code is correct. However, I do not want to expose the serial code creation method, so if someone knows the method...

Unzip files created with WinZIP with I18N file names?

People these days create their ZIP archives with WinZIP, which allows for internationalized (i.e. non-latin: cyrillic, greek, chinese, you name it) file names. Sadly, trying to unpack such file causes trouble: UNIX unzip creates garbage-named files and dirs like "®£¤ ©¤¥èì". Java and its jar command fails miserably on such archives. I...

problem subclassing ObjectFactory in jax-ws web service

In a jax-ws web service I cannot directly access the JaxbContext object. JaxbContext uses the class ObjectFactory. I tried extending it (like in Jaxb Adding Behaviors). I put generated code in ObjectFactoryBase, then added public class ObjectFactory extends ObjectFactoryBase {//.. overriden methods} However IllegalAnnotationsException...

Sharing a static object between a servlet and a webservice

I have a servlet which handles http get requests that I'd like to be able to share an object which is also used by a webservice im developing. They are both on the same tomcat server within the same web-app container. Im not sure best how to do it any ideas ? ...

Calling java program dependent on external library

I am trying to call a java program in php to use it with web interface. Java program is dependent on an external lib: commons-cli-1.2.jar So basically I need to export it before calling the java program; but if I export it first as: shell_exec('export CLASSPATH=$CLASSPATH:~/lib/commons-cli-1.2.jar'); then call the java program as: ...

Is it possible to create an "uber" jar containing the project classes and the project dependencies as jars with a custom manifest file ?

I'm trying to create a executable jar(using maven) that contains the project classes and it's dependencies with a manifest file that has the entry for the main class and the class path entry that points to the dependencies packed in the root of the jar;something like this : Manifest File: ..... Main-Class : com.acme.MainClass Class-Pa...