java

Using commons digester how do I parse a single xml entry into multiple fields in an object?

How do I map "Joe Smith" to first name "Joe" last name "Smith"? I already have code to split up the name, I'm not sure how to make that work with the Digester though. <guestlist> <guest> <name>Joe Smith</name> </guest> </guestlist> public class Guest(){ private String firstName; private String lastName; ... } ...

What do you think about returning the logging sentence

I have this java code: if(isNull(office) || isNull(pricelist)) { log.warn("The document {0}-{1} is not valid.",codDoc,numDoc); return null; } Do you think it is ok if I rewrite it as: if(isNull(office) || isNull(pricelist)) return log.warn("The document {0}-{1} is not valid.",codDoc,numDoc); That way public void warn...

Options for Client Server Communication in Android

I'm currently in the research phase of my dissertation project. My project is a ticket booking system for a mobile device and I have chosen to target Android. I anticipate the need for a client/server architecture with a central server, and so am currently looking at how Android could communicate with such a server. The server would gr...

Cannot get this Java code to compile, any ideas?

I could not compile the following code in Java, error is: misplaced construct(s). What's wrong? public class ExceptionsTutorial { public static void main(String[] argv) throws Exception{ try{ System.out.println("A"); try{ System.out.println("B"); throw new Exception("1"); } catch{ ...

need suggestions on getting started with Junit

I have not used Junit before and have not done unit testing automatically. Scenario: We are changing our backend DAO's from Sql Server to Oracle. So on the DB side all the stored procedures were converted to oracle. Now when our code calls these thew Oracle Stored Procedures we want to make sure that the data returned is same as comp...

Abstract Generic class

Hi, I have the following class : public abstract class Step { public abstract <S,T> S makeAStep(S currentResult, T element); } and I'm trying to Implement it so it will take two int's and return the sum of them , something like this : public class sumOfInts extends Step { public <Integer,Integer> Integer makeAStep(Integer cu...

Differences when compiling Java with GNU Compiler for Java instead of the Sun JDK

I'm working on a school project where I am required to use the GNU Compiler for Java. I've always worked using the official Sun JDK and now I'm concerned about differences that might complicate my work. I'm specially interested in which version of Java is the one supported by the latest GCJ compiler Could someone shed some light in the...

How can I Convert XML to an Object using Spring 3.0 mvc while making RESTful request

Hi, I'm using the Spring 3.0 RC1 framework and I'm currently testing out Spring mvc. I wanted to use Spring mvc to handle restful requests. I have set up my controller to handle the URI request. I am passing in xml with the request. So on the controller I have a method like follows: public void request(RequestObject request) { d...

GUI objects not showing in Java on Mac

I've only just begun writing GUI programs, this being my second one. With both projects (both homework assignments) I have had the same issue. The GUI objects (such as JTextField) do not show when the application runs until after I resize the window or move keyboard focus to them. If I do not do one of those two things, then I'll just ha...

Update Windows path variable when Java is updated automatically?

This question asks how to setup your path variable in Windows to include the Java bin directory allowing you to use the javac command from the prompt. The solution posted to this question states you should hard code the absolute path of the latest Java installation. In this case it happens to be c:\program files\java\jdk1.6.0_16\bin I...

One-to-Many Unidirectional Parent-Child ID Cascade Save

When trying to save an ID from my parent class into a child class, I keep getting the error "ERROR - Field 'parent_id' doesn't have a default value" I have tried all types of mappings. I am using annotations. Any help on this would be appreciated Parent: @Id @Column(name="id") @GeneratedValue(strategy=GenerationTyp...

[Java] Containers class owner's child object having to add components into his parent's container problem

Hi, I am having problems dealing with containers and components in my JApplet. I don't put my code because I think there is no need for it. The main class owns the getContentPane(). Another class (let's call it class1) owns a JLayeredPane() and components that are added to it. Another class (let's call it class2) only have components...

Glassfish doesn't load jdbc

I've a application in swing and ejb3 inside glassfish v2ur2 and until one week ago all was ok. in sometime, the glassfish never more load the jdbc driver of postgresql and the connection with the bd fail, but the jdbc driver is in the project and in the classpath. the only way to fix it was put the jar inside lib folder of glassfish doma...

Compile a Java class against an interface even if none was specified

I'm teaching an intro to programming course and we're using Java. I want to help the students learn how to translate a written class specification into a working program. I will provide the written specification. It specifies the name of the class and behavior in the form of method signatures. I want the students to translate that into a...

How do I wrap long lines of text in a Java TextBox?

Hello! I want to load a text box in Java from a text file. This sounds simple but the big question is how to return at the end add newlines when text get close to the edge of the box, for example. | | | Java java java Java java java |Java java java...

What is a scripting engine?

I've seen here that what sets a programming language apart from a scripting language is the scripting engine. But I don't understand how it works, so I don't know the difference. For example, I see code in Java calling methods in imported libraries, but it doesn't seem "different enough" from Python or Ruby code - both are scripting lan...

How to submit a form programmatically in Java servlet?

Hello, I have a java servlet which get the form request from one webpage in domain A, and it would deal with the form, and would send the result in another form as a request to another webpage in domain B. I'm wondering how to submit the form programmatically in Java servlet? I tried to use javax.servlet.RequestDispatcher.forward(req...

Conceptual Question About Java Concurrency

If I I have a class whose run() method sleeps for 1000 ms and then print "Thread". And I start this thread from my main program, then have my main program immediately sleep for 2000 ms, and then print "Main Thread". Is it guaranteed that Thread will be printed before Main Thread? ...

please tell me why "else" is a syntax error here.

import java.util.Scanner; public class SW { /** * @param args */ public static void main(String[] args) { int length; int width; int number; int perimeter; int area; Scanner input = new Scanner( System.in ); System.out.println("1. Dimensions of the rectangle"); System.out.println("2. Perimeter of the rectangle"); System.out...

Java Web Project referencing another Java project

I have a Java Project, for which I'm now creating a Web interface, using a Dynamic Web Project from Eclipse. The Web project consists of a single servlet and two JSP's. Something like this: /JavaApplication /src /lib /resources /WebApplication /src /Servlet.java /WebContent /WEB-INF index.jsp other.jsp Now, I...