java

How to insert a "Pair" or n-size into a list collection instead of composing HashMaps?

So, I have a situation where I need to pass in three values into a serial BlockingQueue queue: (SelectableChannel, ComponentSocketBasis, Integer). They don't actually need to be hash mapped at all, and to use a HashMap is ridiculous as there will always be only one key for each entry; it'd be fine if they were just in some sort of o...

Can a empty java string be created from non-empty UTF-8 byte array?

I'm trying to debug something and I'm wondering if the following code could ever return true public boolean impossible(byte[] myBytes) { if (myBytes.length == 0) return false; String string = new String(myBytes, "UTF-8"); return string.length() == 0; } Is there some value I can pass in that will return true? I've fiddled wit...

How to copy properties from one Java bean to another ?

I have a simple Java POJO that I would copy properties to another instance of same POJO class. I know I can do that with BeanUtils.copyProperties() but I would like to avoid use of a third-party library. So, how to do that simply, the proper and safer way ? By the way, I'm using Java 6. ...

Comparison of JDBC Connection pools

Does anyone have any information comparing performance characteristics of different ConnectionPool implementations? Background: I have an application that runs db updates in background threads to a mysql instance on the same box. Using the Datasource com.mchange.v2.c3p0.ComboPooledDataSource would give us occasional SocketExceptions: ...

All possible values of int from the smallest to the largest, using Java.

Write a program to print out all possible values of int data type from the smallest to the largest, using Java. Some notable solutions as of 8th of May 2009, 10:44 GMT: 1) Daniel Lew was the first to post correctly working code. 2) Kris has provided the simplest solution for the given problem. 3) Tom Hawtin - tackline, came up arguab...

java.util.Date to XMLGregorianCalendar

Isn't there a convenient way of getting from a java.util.Date to a XMLGregorianCalendar? ...

Joda-time: First day in this year's ISO week 1

Hi, I would like to find out the date of the Monday in this year's ISO week 1 (For 2009 this would be Monday, Dec 29 2008). I'm sure that joda-time can handle this, but I just can't figure out the API (maybe it's just too late). Can anyone help? Thanks! ...

Java on Linux: Listening to broadcast messages on a bound local address

I have a somewhat weird requirement to be able to listen to a number of network interfaces from Java on a Linux machine and determine if one of them receives UDP packets of a certain type. The output data which I need is the IP address of the interface in question. Is there any way to do this in Java? Listening on the wildcard address ...

How to creata database Schema using Hibernate

After reading Hibernate: hbm2ddl.auto=update in production? some questions arose. First of all, the reason for I'm using Hibernate is to be database vendor independent (no need to write 10 versions of the "same" sql query, eg. tsql vs. sql). My problem appears when it's time to create the database schemas (production environment). As f...

Java Applet Network Connection

Hello, At the moment when my applet runs in a web browser it is blocked from making any outside network connections. Is it possible to change any settings to allow it make connections? It works fine when run from the desktop, but when in a browser it restricts it. Thanks ~ Kyle G ...

Ant: Check if class exists in a jar

How do I check if a particular class exists in a jar file? I tried available task and it does not seem to work If there is a way, can I use patterns in it? For example, I want to check if a class matching pattern **/xyz/foo.class exists in foobar.jar Any direction appreciated. ...

Netbeans ejb project glassfish to apache geronimo

Hi, I have created a project using Netbeans with glassfish. It is a java ee and I have created some ejbs. I need to run this on Apache Geronimo but I don't know how to do this. Any pointers? thx ...

Exception Handling Standards Advice

In the j2ee applications I plan on standardizing the exception handling strategy. No more swallowing exceptions and basically converting all checked exceptions into unchecked (except for some that actually can be recovered from. The standard will be that all Exception will be thrown back up to the container (eg: http://www.onjava.com/pub...

setting up JBoss5 with MyEclipse

Hello, I have been using Weblogic as my company used it. Now I want to try JBoss as an alternative. I'm using Eclipse with MyEclipse 7.1 plugin. I downloaded and unzipped JBoss 5.0.1GA with Java JDK 1.5.0.14. I set the server up using MyEclipse interface and got the following error (couldn't find solution elsewhere online): 10:42:54,24...

Build strings with Spring?

I'm getting reacquainted with Spring and looking at dependency injection and IoC in a way I haven't before. If I want to build a string, say for a file name, and I already have a Spring bean which contains the directory, what is the best way to append the file name? Writing a bean to do this myself seems fairly trivial, but I would thi...

Binary tree remove method

I am doing some extra work in my computer science class trying to get better at understanding the logic of data structures. Specifically, I am trying to write a remove function for a sorted binary tree: private boolean remove(Node cRoot, Object o) { if (cRoot == null) { return false; } else if (cRoot.item.equals(o)) { //e...

What is the right combination in ant?

It doesnt seem that when you combine these Fileset attribute like below: eg: <fileset dir="src"> <include name="gov/nasa/arc/mas/selenium/tests/*.java" /> <excludesfile name="${test.suite}.exclude" /> </fileset> that it has the expected behavior which is to include all *.java under src but exclude all the file specified on the...

Validating SSH Credentials in Java on Unix

I have a text file on a unix machine containing the SSH user name and password that someone might use to connect to it. How do I verify that the user name and password are valid using Java? Do I try to SSH connect to the same machine by using Runtime.exec()? I can grep for the user /etc/passwd. But, the password is shadowed. I'd a...

Splitting a String (especially in Java with java.util.regex or something else) ...

Does anyone know how to split a string on a character taking into account its escape sequence? For example, if the character is ':', "a:b" is split into two parts ("a" and "b"), whereas "a\:b" is not split at all. I think this is hard (impossible?) to do with regular expressions. Thank you in advance, Kedar ...

Extract div content from htmlsource in string (Java)

Hi all, i'm trying to extract the content of an special div-tag(defined by his classname) out of a string that contains html source. I think the regexp-features of Java are not as easy to use as in perl, right? Does anyone did this before and can give me a piece of code? perhaps dom-browsing is a good solution, but i didn't found any tu...