java

Spring view resolution problem

Spring, Spring MVC 2.5, Tomcat 6.0. In my controller: ModelAndView returnModelAndView = new ModelAndView(new InternalViewResolver("/sandbox/test1.jsp")) Was working. Then I switched the Tomcat (6.0) context path from "/appname" to "" in order to reference the webapp from the root context "http://localhost:8080/". All my filter, intercep...

[Java6] Same source code, Eclipse build success but Maven (javac) fails

Keep getting this error when compiling using Maven: type parameters of <X>X cannot be determined; no unique maximal instance exists for type variable X with upper bounds int,java.lang.Object Generics type interference cannot be applied to primitive types. But I thought since Java5, boxing/unboxing mechanism works seamlessly between pr...

java - IO on internal class

Is it possible to ObjectOutputStream/ObjectInputStream an internal class? I can write it OK, and examine the created file, but when I try to read it back in using ObjectInputStream, I get an EOFException just trying to read an Object o = oos.readObject(); I use the same File object to open both streams, so that's not the problem. It s...

NullPointerException when trying to run an applet of multiple classes

I'm trying to display an applet in an html page. I've had success doing this in the past, but now that I have more than one class in the applet, I seem to get an error every time I try to load the applet in an html page. For a bit, I was writing the html page by hand, but then I realized the applet viewer in netbeans (the IDE I'm coding ...

System.out.println() don't throws Exception, but System.in.read() throws Exception, Why????

I got this from Java™ I/O, 2nd Edition By Elliotte Rusty Harold :- it would be inconvenient to wrap a try/catch block around each call to System.out.println( ), Sun decided to have PrintStream (and later PrintWriter) catch and eat any exceptions thrown inside a print( ) or println( ) method. If you do want to check for exceptions ins...

Problem to represent midnight for 01 May 1921 by java.util.Date class

I want to represent midnight by java.util.Date class. To check this I output this value and obtain unexpected result. The code follows: Calendar calendar = new GregorianCalendar(1921, 4, 1, 0, 0); Date date2 = calendar.getTime(); System.out.println(date2); I obtain the following output: Sun May 01 00:20:08 EET 1921 But I expect to...

Howcan I get started with Spring Batch?

I'm trying to learn Spring Batch, but the startup guide is very confusing. Comments like You can get a pretty good idea about how to set up a job by examining the unit tests in the org.springframework.batch.sample package (in src/main/java) and the configuration in src/main/resources/jobs. aren't exactly helpful. Also...

What's the best way of parsing a fixed-width formatted file in Java?

I've got a file from a vendor that has 115 fixed-width fields per line. What's the best way of parsing that file into the 115 fields so I can use them in my code? My first thought is just to make constants for each field like NAME_START_POSITION and NAME_LENGTH and using substring. That just seems ugly so I'm curious if there's any othe...

java equivalent to php's hmac-SHA1

I'm looking for a java equivalent to this php call: hash_hmac('sha1', "test", "secret") I tried this, using java.crypto.Mac, but the two do not agree: String mykey = "secret"; String test = "test"; try { Mac mac = Mac.getInstance("HmacSHA1"); SecretKeySpec secret = new SecretKeySpec(mykey.getBytes(),"HmacSHA1"); mac.init(...

Unsafe generic cast when deserializing a Collection

public Configuration(Node node, File file) { HashMap<String, String> conf = (HashMap<String, String>) SerializationUtils.deserialize(new FileInputStream(file)); } I understand why this gives an unsafe cast warning, but what's the best/accepted way to do this safely? Is there any good way? ...

How do I configure Eclipse to create protected java methods by default instead of private?

When I use Eclipse 3.5 to auto-create methods for me (for example, by calling a method that does not yet exist, then using Quickfix to create the method), Eclipse creates the method with private scope. I'd like to change that so that it's created with protected scope by default. How can I do so? ...

How to return array from JNI to java?

Hello, I am a beginner programmer and I am attempting to use the android NDK. Is there a way to return an array (in my case an int[]) created in JNI to java? If so, please provide a quick example of the JNI function that would do this. -Thanks ...

Extracting email messages from a Lotus Notes NSF file using Java API

I'd like to use the Java API (Notes.jar), and I'm running a Windows box with Lotus Notes 8.5 installed. I know nothing about Lotus Notes, and I only need to do this one narrow task: extracting email messages from an NSF file. I want to be able to iterate through all the email messages, grab the metadata (From, To, Cc, etc) or the raw M...

Why do floats having trailing .0 when it is exactly an integer?

Read this question carefully because I am not asking how to get rid of trailing zeros, that's easy. What I am asking is why does 123d become "123.0"? A IEEE 64-bit float can represent integers from 0 to 2^52 exactly, so this isn't a loss in precision but a decision during the implementation of Double.toString(). My question is why did...

Tomcat does not recognize the MySQL .jar library

I tried several different ways such that Tomcat loads the MySQL drivers when running my web application. I'm using Ubuntu 8.04, and the libraries come from the libmysql-java package. They are located in the directory shown below: ~$ ls /usr/share/java/mysql* /usr/share/java/mysql-connector-java-5.1.5.jar My CLASSPATH includes this fi...

When I try to read a file with Java using Eclipse, it always says it can't find it?

I've created this simple program in Eclipse: import java.util.*; import java.io.*; public class prob1 { public static void main(String[] args) { try { FileReader in = new FileReader("practice.in"); Scanner scanner = new Scanner(in); while(scanner.hasNext()) { ...

How to attach a file to an HTML email using apache commons email

I'm using Apache Commons Email 1.1 and I can't figure out how to attach a file to an HtmlEmail. If I run the code below, I get an email with an attachment, but the html message comes across as an attachment also. If I don't call email.attach() the html message come through as you would expect, but I need both the html message to come t...

java.lang.NoClassDefFoundError help

I'm trying to read a mail from Tomcat 6.0. Whenever I put the byte code and source code of the class MailReader in the same folder(and putting the main method), I can compile and run the class and read mail from command prompt, but when I put that class in the folder WEB-INF/classes of tomcat(by removing main method), I'm getting big fat...

Automated Web Application Testing Framework

What is a good web application testing framework that I can use for a fairly large JavaEE based app? I am currently using Canoo Webtest, but we are running into issues with jQuery. I have tried upgrading the htmlunit to the current version, but that causes even more strange errors to occur. I am looking to see what other automated web ...

Shallow copy of a collection in Java

For this method, I have to make a shallow copy of a linked list stack. So, first I would initialize the linked stack then would I use a for loop to go through the values to copy the stack. But, to put them in the right order, would I just have a nested loop to reverse the group of values? here is what I got so far, am I missing somethi...