java

How to focus on JTextField within a table.

I'm writing a search & replace function in a kind of spreadsheet program. What I want is that if you search for a string, the program shows a table with the element that has been found. So far so good, but I cannot get the element to obtain the focus, with the cursor in it so you can immediately start typing. I'm using a customized JTa...

converting string to date object

I am parsing xml file. In this file there is one tag containing date string "2008-11-10T05:51:33Z" And I want convert this string in to java.util.Date object. is there any body who will help me... ...

What exactly happens while you assign a reference to an element in Array in Java?

I am doing the following statements in Java, Obj t[] = new Obj[10]; Obj a = new Obj("a"); t[0] = a; a = new Obj("b"); t[1] = a; Why in java, when i access t[0] , it returns me "a", rather than "b"? Is this because of the GC? and can i believe it is safe to do such an operation ...

Creating xml from with java

Hi folks, I need your expertise once again. I have a java class that searches a directory for xml files (displays the files it finds in the eclipse console window), applies the specified xslt to these and sends the output to a directory. What I want to do now is create an xml containing the file names and file format types. The format ...

How to set icc color profile in Java and change colorspace

First, I would like to say I'm not an image processing specialist. I would like to convert image colorspace from one to another, and change icc color profile at the same time. I managed to do it using JMagick (the ImageMagick Java port), but no way in pure Java (even using JAI). ...

Downcasting in Java

Upcasting is allowed in Java, however downcasting gives a compile error. The compile error can be removed by adding a cast but would anyway break at the runtime. In this case why Java allows downcasting if it cannot be executed at the runtime? Is there any practical use for this concept? public class demo { public static void mai...

Casting to a Class which is determined at run-time

I have a method fetchObjects(String) that is expected to return an array of Contract business objects. The className parameter tells me what kind of business objects I should return (of course this doesn't make sense in this construed case because I already said I will return Contracts, but it's basically the situation I have in my real ...

True random generation in Java

I was reading the Math.random() javadoc and saw that random is only psuedorandom. Is there a library (specifically java) that generates random numbers according to random variables like environmental temperature, CPU temperature/voltage, or anything like that? ...

How can I replace strings in a text in Java?

In a project we have text files looking like this: mv A, R3 mv R2, B mv R1, R3 mv B, R4 add A, R1 add B, R1 add R1, R2 add R3, R3 add R21, X add R12, Y mv X, R2 I need to replace the strings according to the following, but I am looking for a more general solution. R1 => R2 R2 => R3 R3 => R1 R12 => R21 R21 => R12 I know I could d...

Advantages/disadvantages of Glassfish v3 Prelude vs Springsource dm server for Web applications?

Both of these appservers are at least in part OSGI based. One (Glassfish) is obviously J2EE while the other isn't. Now I'm at the stage of choosing a platform for a new project and the natural choice is Glassfish v3 Prelude. This does raise the issue of perhaps we should be using S2AP instead. The question then is this: does the spri...

Anyone doing mainframe or AS/400 Batch processing with Java?

I'm going to propose to a client that I build some batch jobs in Java that will run on their mainframe and/or AS/400s (sorry System z and System i). Both platforms are up to date system software wise. I'm wondering if anyone has done this and can provide any pointer or gotchas to watch out for. The motivation is to have access to the to...

Is it possible to monkey patch in Java?

I don't want to discuss the merits of this approach, just if it is possible. I believe the answer to be "no". But maybe someone will surprise me! Imagine you have a core widget class. It has a method calculateHeight(), that returns a height. The height is too big - this result in buttons (say) that are too big. You can extend DefaultWid...

Which JDBC jar should I use with java 1.5.0_16 and PostgreSQL 8.3.5?

Title says it all: Which JDBC jar should I use with java 1.5.0_16 and PostgreSQL 8.3.5? ...

Insert fail then update OR Load and then decide if insert or update.

I have a webservice in java that receives a list of information to be inserted or updated in a database. I don't know which one is to insert or update. Which one is the best approach to abtain better performance results: Iterate over the list(a object list, with the table pk on it), try to insert the entry on Database. If the insert f...

Benefits of using JSTL vs Velocity for view layer in MVC app?

I'm currently building a Spring MVC application. I was looking to use JSP pages with tag libraries for handling the view layer and formatting of the HTML, but I've come across another group in my company that uses Velocity templates for the same purpose. From what I can see, it seems to me as if there are a lot of similarities between t...

Is there a way to obtain names of method parameters in Java?

Hello, I'm writing small and very DRY framework, which heavily relies on metadata. I'd like to know if there is a way to obtain method parameter names, i.e. given some method public void a(int myIntParam, String theString) { ... } get the strings "myIntParam" and "theString". I know I could annotate parameters, but that wouldn't be n...

How can I display a byte array as a String in java's debug detail formatter?

I'd like to write a simple detail formatter that displays byte[] data in the form of a String (using String.<init>([B) to do the dirty work). However, I'm not sure how to find the class name for [B to use when creating the formatter. Is this even possible? Or, alternatively, is there another way to view byte arrays as strings in the d...

outputting the value of a "Watch" in Eclipse to a log file.

I have a piece of Java code I can't edit which I want to debug. The issue is that one of my 10,000 records has a data error and is causing the application to crash. I can remote debug the live application and add watch which would pick up the id of the record as each is processed. The problem is when the "bad record" is processed and t...

C/objC/C++/Java compilers

I downloaded NetBeans (for first time) to use Java and found that it can handle C/C++ etc too. Wanted to know following -- 01- Is there any better C++ tool (IDE) other than NetBeans and MS Visual Studio? Better means very mature and popular (and free). 02- What is the difference between GNU Java and Sun Java compilers? 02- Is there...

I want more syntactic sugar in my Java!

Syntactic sugar for properties for example in C#: private int x; public int X{ get { return x; } set { x = value; } } or simply public int X{ get; set; } I am missing verbatim strings in java... @"C:\My Documents\" instead of "C:\\My Documents\\" Do you agree Java needs more "sugar"? Any one knows is there is sugar comin...