java

Hibernate and padding on CHAR primary key column in Oracle

I'm having a little trouble using Hibernate with a char(6) column in Oracle. Here's the structure of the table: CREATE TABLE ACCEPTANCE ( USER_ID char(6) PRIMARY KEY NOT NULL, ACCEPT_DATE date ); For records whose user id has less than 6 characters, I can select them without padding the user id when running queries using SQuirre...

Java : replacing text URL with clickable HTML link

Hello, I am trying to do some stuff with replacing String containing some URL to a browser compatible linked URL. My initial String looks like this : "hello, i'm some text with an url like http://www.the-url.com/ and I need to have an hypertext link !" What I want to get is a String looking like : "hello, i'm some text with an url ...

java Semaphore north south que

There are two queues of children waiting to use a roundabout in a playground – one is facing it from the north, one from the south. Children may only enter the roundabout from the front of either queue and may only enter if there is a space available (only one child may use each segment at a time). Once on the roundabout they use it for ...

Unix stat()/lstat() for Java

Suppose I want to get several of a file's properties (owner, size, permissions, times) as returned by the lstat() system call. One way to do this in Java is to create a java.io.File object and do calls like length(), lastModified(), etc. on it. I have two problems so far: Each one of these calls triggers a stat() call, and for my pur...

Why does ant ignore task jars in $HOME/.ant/lib/

Configuration: I'm running stock Fedora 12 with the ant that Fedora ships: ant-1.7.1-12.fc12 java-1.6.0-openjdk-1.6.0.0-33.b16.fc12 I have svnant.jar and svnClientAdapter.jar in my $HOME/.ant/lib/ I'm using the following build.xml: <project name="antlibtest" default="doEcho"> <taskdef resource="svntask.properties"/> <targ...

Java Exception Handling - Style

Historically I have always written my Exception handling code like this: Cursor cursor = null; try { cursor = db.openCursor(null, null); // do stuff } finally { if (cursor != null) cursor.close(); } But recently, for reasons of readability and laziness, I have started to do this: Cursor cursor = db.openCursor(null, nul...

Invalid Authsub token in Google sites for apps

I do not get any error while trying to access feed content for google sites from application hosted on gmail authenticated account. But I get Token invalid - Invalid AuthSub token. when I try to access application from google apps accounts managed GAE application. I have tried both https://sites.google.com/feeds/ and http://sites.go...

Should methods with return type void use a return statement?

I know that there are times when using return; can serve a useful purpose in Java, such as in guarding: public void foo(Bar bar) { if(bar == null) return; // bar is not null, go ahead and do stuff with it } But what about just reaching the end of a method with return type void? For example, public void printMenu() {...

How can I access the configured Log4J appenders at runtime?

I want to configure an appender at startup and then dynamically add and remove it from various loggers on demand. I'd prefer to have log4j configure this appender itself, and just grab a reference to it when needed. If that's not possible, I'll have to instantiate the appender myself and hold onto it. ...

Implementation of a simple algorithm (to calculate probability)

EDIT: I've got it, thanks for all the help everyone! + Cleaned up post a little bit. Also, this article was very helpful: http://www.codinghorror.com/blog/archives/001204.html?r=1183 Hi all, I've been asked (as part of homework) to design a Java program that does the following: Basically there are 3 cards: Black coloured on bot...

Where to close a JDBC Connection while I want to return the ResultSet

It seems that the resultSet will be automatically closed when I close the Connection. But I want to return the rs and use it in another method,then I don't know where to close conn and pstmt. public ResultSet executeQuery(String sql, String[] getValue) { Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null;...

Can actual Perl Regular Expressions be implemented in Java via existing library?

Is there an existing robust Java library which implements a fairly substantial subset of Perl regular expression syntax? Background: I wish to implement a file renamer where renaming is done using Perl regular expressions. The trick is that the project containing said renamer as a component is, currently, 100% in Java in Windows. NOT...

Garbage Collection in Java and Circular References

From my understanding, garbage collection in java cleans up some object iff nothing else is 'pointing' to that object. My question is, what happens if we have something like: class Node{ public object value; public Node next; public Node(object o, Node n) { value = 0; next = n;} } //...some code { Node a = new Node("a", n...

How to make a property nullable in JPA - GAE/J?

I have a entity class User. I want to add some more properties but to keep them nullable. I want to know the annotation used for this in JPA. I am using JPA in Google App Engine. Thanks ...

How can I split an ArrayList into several lists?

Hi, See the following ArrayList: List<Integer> values = new ArrayList<Integer>(); values.add(0); values.add(1); values.add(2); values.add(3); values.add(4); values.add(5); values.add(6); So we have: integerList.size(); // outputs 7 elements I need to show a Google chart as follows: http://chart.apis.google.com/chart?chs=300x20...

Java servlets and receiving XML from Flash's xml.sendAndLoad() function

All, I'm working on a Flash application that's supposed to send XML data to a Java Servlet. I'm responsible for the Flash app; another team is responsible for the Java Servlet. The problem we're having is that I'm familiar with Flash but not Java and Servlets; the other team is expert in Java and Servlets, but unfamiliar with Flash. ...

Understanding Pattern and Matcher

Consider this code: import java.util.regex.*; public class Pattern3 { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Pattern p = Pattern.compile("Our"); //line 1 Matcher m = p.matcher("Our mom and Our dad"); //line ...

Fibonacci Sequence Algorithm

I am attempting to find the first number in the fibbonacci sequence to contain N digits (N being somewhere in the range of 500 and 2000). I attempt to do this with the following code: BigInteger num = BigInteger.valueOf(2); BigInteger num1 = BigInteger.ONE; BigInteger num2 = BigInteger.ONE; int record = 0; BigInteger TEN = BigInteger.va...

SLF4J Message Format In WebSphere App Server

So, I'm beating my head against the wall with logging again. I know, how complex can it be? Well, let's see... I'm starting a new project to be run on WebSphere Application Server 6.1 (actually Portal Server 6.1, but it's WAS 6.1 under the hood - whatever). I usually use java.util.logging for my WAS projects and everything is fine. ...

Copy of the internal data structure of a class

Out of curiosity: Id like to know if exists any class in Java with a method that returns a copy of its data structure. I ask it because in class the teacher said a method like this breaks privacy but I think to get the copy of the structure is useful if you want to rearrange the structure. Id like an example. Thanks. ...