java

% sign in Java's PreparedStatement

PreparedStatement ps = con.createStatement("select * from table1 where last_name like ?"); ps.setString(1, "'%"+lastName+"'"); Will this work the same as... Statement s = con.createStatement("select * from table1 where last_name like %"+ lastName); Or does PreparedStatement strip out the % sign? ...

Automated way to find JUnit tests that leak memory

The root of our problem is Singletons. But Singletons are hard to break and in the meantime we have a lot of unit tests that use Singletons without being careful to completely clear them in the tearDown() method. If figure that a good way to detect tests like these is to look for memory leaks. If the memory used after tearDown() and S...

Taking input in Java without program hanging?

I was just wondering how i would let my java program continue running, but always be ready to take input. Right now i am using a bufferreader and reading in a line, but that makes my program halt and wait for input. I want the program to continue running but be ready to take input whenever needed, is there a way to do this? ...

What is the most elegant way to map one list to another in Java?

I am new in Java so please be patient. It is common to map (convert) lists to lists. Some languages have a map method, some (C#) Select. How is this done with Java? Is a for loop the only option? I expect to be able to do something like this: List<Customer> customers = new ArrayList<Customer>(); ... List<CustomerDto> dtos = customers....

Overriding return type in extended interface - Bad idea?

In Java, you can do the following : public interface IEngine{} public interface ICoolEngine extends IEngine{} public interface Car { IEngine getEngine(); } public interface ICoolCar extends ICar { @Override ICoolEngine getEngine(); } While this nicely solves a problem I've been grappling with, something about it "feels" wr...

How to use the Netbeans Profiler programatically ?

Hello I want to be able to do some profiling to some app using the Netbeans Profiler API. I'm not intreseted in using Visual VM , but rather in programatically collecting data from the application[let's say CPU usage, and method execution times]. For instance, using CPU usage and hot methods. How to get that data and print it on console...

Generic Test harness for java.util.Map?

I have a custom implementation of the Map interface which does some fancy stuff, like lazy evaluation of functions. the implementation should appear immutable after construction from outside (e.g. no put() and putAll() methods are supported) I it looks like it works in the most basic conditions. Since it is quite complex, i am sure ther...

Can I use JAVAC to compile a project with multiple files and directories?

I'm working on a very large project that has associated class files in multiple directories, all stemming from the root dir \src. I'm trying to compile a file in src\solution\ (called Console.java) that uses imports from other directories in the src, which are still uncompiled. So if I want to compile Console.java outside of an IDE, ho...

Why does my method throw a NoSuchMethodError?

I have implemented successfully the reflectionEquals method, with a list of excluded fields. return EqualsBuilder.reflectionEquals(this, obj, new String[] {"files", "notes", "status"}); However, I recently compiled my program on Java 1.5 and now I get the following error when the program hits the above line: java.lang.NoSuchMet...

How Long Does it Take to Learn Java for a Complete Newbie?

I have absolutely no programming experience but need to learn Java - enough to take a J2ME fasttrack course. I only have 10 weeks. Can I do this? What's your advice about the best resources I can use ?(currently using Sun's Java Tutorials). ...

Where can I find a syntax highlighting library for Java?

I'm writing a source-code editor in Java (for Java source code), and I'd like to add simple syntax highlighting (distinctive coloring for keywords would suffice). Any suggestions? ...

Is it possible to use JSTL to display a date in the client's timezone?

In Javascript, I have this function to display the current date on our page header: <SCRIPT language="Javascript"> var today = new Date(); document.write(today.toLocaleDateString()); </SCRIPT> I would like to do this via JSTL, but I'm not sure if it's possible. So far, I have this fragment of code: <jsp:useBean id="date" cla...

Resource for learning Java generics?

Hello I'm clearly in need of improving my knowledge in this Java field, or I'm doomed to produce "look the same but not exactly" code. I'm already have the bases... but I'm looking for a training / tuturial oriented only to this. Thanks ...

Spring frame work Wraps Checked Exceptions inside RuntimeExceptions

have this method call -> simpleJdbcTemplate.queryForInt(sql,null); -> queryForInt() method in the springs SimpleJdbcTemplate throws a DataAccessException which is a runtime exception. i want to propegate exceptions to the view tier of the application since Spring frame work Wraps Checked Exceptions inside RuntimeExceptions i ...

Does WCF FaultException<T> support interop with a Java web service Fault

I have written a java axis2 1.4.1 web service and .net 3.5 WCF client and I am trying to catch the wsdl faults thrown. Unlike .net 2.0 the .net 3.5 claims to support wsdl:fault and the service reference wizard does generate all the correct fault classes in the client proxy. But when I try to catch a fault it doesn't seem to correctly s...

Elegant way of holding large static typesafe dictionary in java - or avoiding code too large

Basically I would like to have some dictionary that is an abstaction over legacy #define directives. I have an old header file that contains 6000+ defines, that are used as flag parametersome function and these defines denote one type of entity parameter. In C i have GetParameter(... , T_CTITLE, ...); In Java i would like to call...

Deploying modules in a web application

I have a web application - deployed on Tomcat. It has two modules Module A and Module B Both have java code as well as UI component (struts\JSP etc.) Functionally, Module A is independent an doesn't depend upon Module B For ModuleA: We create a war for Module A and deploy it as ModuleA.war Now Module B depends upon Module A We so "me...

how to create an InputStream from a Document or Node

How can I create an InputStream object from a XML Document or Node object to be used in xstream? I need to replace the ??? with some meaningful code. Thanks. Document doc = getDocument(); InputStream is = ???; MyObject obj = (MyObject) xstream.fromXML(is); ...

Is there any better way to do filefilter for many ext?

File files[] = rootDir.listFiles(new FileFilter() { public boolean accept(File file) { if (file.isDirectory()) return true; String name = file.getName().toLowerCase(); if (name.endsWith(".zip") || name.endsWith(".jar") || name.endsWith(".z") || name.endsWith(".gz") || name.endsWith(".tar") || n...

how to provide API for our system

I have not had much experience with Webservices or API's. We have a website built on Oracle->Sun App Server->Java->Struts2 framework. We have a requirement to provide an API for our system. This API will be used by other systems outside of our system. API is just for a simple SP that we have on our database. The other system does n...