java

Defaults for Eclipse run configurations

I'm writing a Java library with a lot of jni code. Pretty much every test case needs to load my jni dll, and I have a lot of test cases. In order to run the test cases out of Eclipse's Junit launcher, I have to create a run/debug configuration and edit the VM arguments and environment variables. I would like a way to set the VM argument...

Why is java.util.Date's setTime() method not deprecated?

All the other mutators got deprecated back in JDK 1.1, so why was setTime() left as is? Surely java.util.Calendar - the correct way to manipulate dates - can create new instances of java.util.Date as needed using the java.util.Date(long) constructor? ...

Setting a parameter as a list for an IN expression

Whenever I try to set a list as a parameter for use in an IN expression I get an Illegal argument exception. Various posts on the internet seem to indicate that this is possible, but it's certainly not working for me. I'm using Glassfish V2.1 with Toplink. Has anyone else been able to get this to work, if so how? here's some example ...

Need an input dialog to populate with text

I am a student at ISU. I was working on a homework assignment where I wanted to get text that was selected (highlighted) in a TextArea to appear in a JOptionPane dialog. I tried many of the methods for JOptionPane, but I could not get any of them to place the text the user selected in the input field of the dialog. I guess that I could ...

Strange behavior of RandomAccessFile object

Hi, Here is a snippet of code that is behaving strange. private void saveToFile() throws IOException { JFileChooser fileChooser = new JFileChooser(); File name = null; int returnVal = fileChooser.showSaveDialog(fileChooser); //Sets the variable name to the file the user selected. if (returnVal == JFileChooser.APPROVE_OPT...

Does JUnit support properties files for tests?

I have JUnit tests that need to run in various different staging environments. Each of the environments have different login credentials or other aspects that are specific to that environment. My plan is to pass an environment variable into the VM to indicate which environment to use. Then use that var to read from a properties file. Do...

Help needed to write a comparator for my job interview code sample

I need help to write a comparator :- I want this output :- Martin Joseph Male 4/2/1979 Green Ramya Patil Female 5/4/2009 Red Don kelly Male 5/6/1986 Yellow Van Shinde female 3/4/1984 Green But i am getting the following output :- Output 1: Van Shinde female 3/4/1984 Green Don kelly Male 5/6/1986 Yellow Ram...

Configuring Netbeans with JNotify

I'm trying to use the JNotify library along with netbeans, however I don't know the proper way to configure it. Everything I try, the lines involving jnotify (eg. import net.contentobjects.jnotify.*) are underlined in red. Google seems to show nothing helpful regarding netbeans with jnotify, although I assume it's something simple like a...

Rendering vector shapes in Java

I have a series of shapes (Approx. 50), that each have 5 points, and a color (with alpha transparency). I want to render these shapes onto a pixel grid. I program as an amateur, so I have no idea how I should go about doing this. Can someone give me a starting point, or some pseudo-code? Thanks in advance. ...

How do you add GUI to this java program?

I know only basic stuff in java. And I need to create a GUI for this type of program. It shows your credit card info. It has some other classes and makes use of the rmiregistry. This works fine in console but I need to show it in a GUI. The first thing that promps here is to enter your name (java Shopper localhost my name). Then it shows...

openfire smack sending packet 404 error means?

when sending packet to openfire using Smack, i get error remote-server-not-found(404) . Can anyone please explain what does thet error means? it mean fail to connect to server or the packet has problem? PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID()); PacketCollector response = connection.createP...

XStream or Simple

I need to decide on which one to use. My case is pretty simple. I need to convert a simple POJO/Bean to XML, and then back. Nothing special. One thing I am looking for is it should include the parent properties as well. Best would be if it can work on super type, which can be just a marker interface. If anyone can compare these two wi...

Java - Eclipse: Externalize Strings ?

It looks like the "Externalize Strings" feature takes everything, makes a Messages class, and a .txt file in which to store the Strings themselves. This is interesting, but I've got another way to store constants: public final class Constants { //for parsing commands public static final String REGEX_COMMAND = "(\\w*) *= *\"(.*)\...

Hibernate Inheritance Mapping and Attribute Override

The system I'm working on has a domain object named Order which inherits from AbstractPersistentObject. Now I need to add another domain object named ExternalOrder which has some of the properties of Order but not all. I would like these two objects to be treated polimorphically in certain places. Hence I'm thinking of implementing inher...

JPA+Hibernate: Change of createNativeQuery() + getResultList() behaviour?

What I am going to describe is a bit of legacy code. So there is a lot of stuff I cannot touch/change. This pseudo-code runs well the in Jboss 4.0.3, big_messy_sql = "select t1.f1 as somealias, t2.f2 as somehthingelse from obj1 t1, obj2 t2 where crazy_conditions...."; Query query = entityManager.createNativeQuery(big_messy_sql); L...

extracting a number from a string in Java

hi all I have a string with a number inside and I want to retrieve that number. for example if I have a string "bla bla 45 bla bla" I want to get the number 45. I have searched a bit and found out that this code should make the work Matcher matcher = Pattern.compile("\\d+").matcher("bla bla 45 bla bla"); if(matcher.matches()) String...

Using rownum in EJBQL for Pagination CMP 2.1

I need to implement Pagintion of CMP2.1 Entity Beans. Is it possible to do it using EJB-QL ? Am using weblogic10.3 + Oracle DB. I was planning to use "rownum >= min_row_size + PreparedQUery.setMaxResult()" to get desired result . But rownum in EJB-QL is not recognized by weblogic . Is there any way to specify psuedo column in EJb-QL ? ...

A rule-based system in Java and C# environments

I need to build a "rule-based" system that can be run and developed in both C# and Java (for a chemistry application). The system needs to be able to get computed properties of objects (through existing libraries) and make decisions on those values. I am not sure what the system will look like but the rules need not be formally consisten...

Static vs Instance members in Stateless EJBs

I have a stateless session bean which needs access to a factory class. Is it best to declare this factory class as a static or instance member in the SLSB? Am I correct in saying that, as SLSBs are reused, only one instance of the factory will be created per bean (when going with the instance member option), as opposed to one instance pe...

Format number in Struts 2 <s:property/> tag

I would like to format number displayed by <s:property value="summary.total"/> tag in Struts 2. There is a double value. How can I do that? Should I use OGNL? Or maybe I must use <s:text/> tag and define my format in resuource file? ...