java

Counting the number of files in a directory using Java

How do I count the number of files in a directory using Java ? For simplicity, lets assume that the directory doesn't have any sub-directories. I know the standard method of : new File(<directory path>).listFiles().length But this will effectively go through all the files in the directory, which might take long if the number of files...

hide non-exists variables in Eclipse java debugger

for example I have an ArrayList with 2 elements, but Eclipse Java debugger shows me 10 elements where 3-10 are just nulls. How to disable this "feature"? details on image P.S.: Mac OS 10.5.6, Java6, Eclipse 3.4.2 ...

OSGi bundle's package structure

I've been thinking some about "good practice" regarding package structure within osgi bundles. Currently, on average, we have like 8-12 classes per bundle. One of my initiative/proposal has been to have two packages; com.company_name.osgi.services.api (for api related classes/interfaces. (which is exported externally) and one package com...

PreparedStatements and performance

So I keep hearing that PreparedStatements are good for performance. We have a Java application in which we use the regular 'Statement' more than we use the 'PreparedStatement'. While trying to move towards using more PreparedStatements, I am trying to get a more thorough understanding of how PreparedStatements work - on the client side ...

The drawbacks of annotation processing in Java?

I am considering starting a project which is used to generate code in Java using annotations (I won't get into specifics, as it's not really relevant). I am wondering about the validity and usefulness of the project, and something that has struck me is the dependence on the Annontation Processor Tool (apt). What I'd like to know, as I ...

How to see if a substring exists inside another string in Java 1.4

How can I tell if the substring "template" exists inside a String in java 1.4 It would be great if it was a non case sensitive check. Thanks! ...

Valid Java code that is NOT valid Groovy code?

Most Java code is also syntactically valid Groovy code. However, there are a few exceptions which leads me to my question: Which constructs/features in Java are syntactically invalid in Groovy? Please provide concrete examples of Java code (Java 1.6) that is NOT valid Groovy code (Groovy 1.6). Update: So far we've got five examples o...

Open source survey/questionnaire engine for Java

Is there an open source survey engine for java that will allow branching of questions? i.e. Question 1 has the options of A, B, or C and they each take you to a different set of follow-up questions. I've found a couple (JSurveyLib and Socrates QE), but those seem to be very tied to a GUI. The application that I'm writing has a java bac...

How should I sanitize database input in Java?

Could someone please point me to a good beginner guide on safely running SQL queries formed partly from user input? I'm using Java, but a language neutral guide is fine too. The desired behaviour is that if someone types into the GUI something like very nice;) DROP TABLE FOO; The database should treat it as a literal string and sto...

How to get the last value of Arraylist

Hi, How can I get the last value of arrayList (e.g. I dont know the last index of the ArrayList)? Thanks. ...

Java Map equivalent in C#

I'm trying to hold a list of items in a collection with a key of my choice. In Java, I would simply use Map as follows: class Test { Map<Integer,String> entities; public String getEntity(Integer code) { return this.entities.get(code); } } Is there an equivalent way of doing this in C#? System.Collections.Generic.Hashset doe...

Compile to java bytecode (without using Java)

My compilers class is creating a language that we intend to compile to Java Bytecode. We have made plenty of progress and are nearing the time where it's time for code generation. We are having problems locating information on how to create .class files from our compiler. Do you have any resources that can give us some assistance? We al...

Java Dynamic Proxy without a target object?

Weird question... How can I make use of Java's Invocation Interceptor like when using Dynamic Proxies without actually having a target object? For example, I'd like to make an uber object that can stand in for a dozen or so interfaces specified at runtime without necessarily needing an object that implements any of them. Basically th...

JSP socket only sending string once

Hello everyone and thanks in advance. This is a last ditch effort to figure out what the problem is or find a better solution. I am using JSP filter to filter web access to a tomcat web server. I have a client, a server and the filter. The client and the filter open up sockets the the server receives them. I heard that opening up a ...

What is the fastest way to find out how many non-empty lines are in a file, using Java?

What is the fastest way to find out how many non-empty lines are in a file, using Java? ...

What to do when you need to store a (very) large number?

Hey, I am trying to do a project euler problem but it involves adding the digits of a very large number. (100!) Using java, int and long are too small. Thanks for any suggestions ...

Servlet Filter: Socket need to be referenced in doFilter()

Right now I have a filter that has the sockets opened in the init and for some reason when I open them in doFilter() it doesn't work with the server app right so I have no choice but to put it in the init I need to be able to reference the outSide.println("test"); in doFilter() so I can send that to my server app every time the if state...

OSGi and J2EE - JOSGiEE?

After reading this article, one question came to my mind: 'Is OSGi becoming a J2EE? Is OSGi going to replace J2EE? Is OSGi incrementing J2EE?' It's true that historically OSGi is totally different from J2EE, but considering now the resulting work from the EEG, some of these services are J2EE services. Another fact is that who uses J2EE...

Eclipse Extensions and Declarative Services

I'm a little confused on the approach to extensions/services in the Eclipse architecture. There are two options available to a developer: The use of Eclipse plugin extensions - http://www.eclipse.org/articles/Article-Plug-in-architecture/plugin_architecture.html The use of declarative services - http://www.eclipse.org/equinox/bundles/ ...

Automatic generation of Unit test cases for .NET and Java

Is there a good tool to generate unit test cases given say a .NET or Java project, it generates unit test cases that would cover an almost 100% code coverage. The number of test cases could be directly proportional to the cyclomatic complexity of the code (the higher the nesting of loops and conditions the higher the cyclomatic complexi...