java

Manipulating Hibernate 2nd Level Cache

I am using hibernate as my ORM solution, with EHCache as the Second Level (Read-Write) cache. My question is: Is it possible to access the Second Level cache directly? I want to access this: http://www.hibernate.org/hib_docs/v3/api/org/hibernate/cache/ReadWriteCache.html How can I access the same ReadWriteCache that is being used b...

java interface design: how to handle stateful processing

I'm having trouble designing a good architecture for a particular portion of my application, especially where maintaining state is involved. I have a group of parsing operations: My class Reader reads in a block of data into a buffer and handles the overall control flow. My class Parser takes the block of data in the buffer and a Parse...

How to know if other threads have finished?

I have one object that have one method named StartDownload(), that starts three threads. How do I make to get a notification when each thread as finished the execution? Is there a way to know in one of the threads if one of the other two is finished or is still executing? ...

How do I compare multiple array entries simultaneously, in Java?

I have problem with comparing the value of array elements. e.g. I wanted to compare the value of index 0 and index 2, and index 1 to index 3 and so on. With the code below I suppose to get the result of numOfdifferentShape is 2 but I get 3. How can I solve this problem? :-( int numOfdifferentShape=0; myArray = {40.0, 40.0, 40.0, 40.0,...

Complex Generics Combinations

Imagine a generic class MySet which maintains a parent MySet instance and a child MySet instance. The idea is that the parent should be able to hold a superset of T and the child a subset. So given the following sample, consider the following problem: class MySet<T> { MySet<? extends T> child; void doStuff (Collection<? extends T...

In Java, when using bitshifts, why does 1 << 32 != 1 << 31 << 1 ?

int a = 1 << 32; int b = 1 << 31 << 1; Why does a == 1? b is 0 as I expected. ...

Is it normal for a website to return HTTP Code 200 for a Page not Found(404) Page?

I was doing some testing with some sites (that I will not mention), and they are returning 200 code when they are page not found pages. Is this against any web development standard? This is the code that I am using to see the return code of a URL: System.out.println(new String("getRespCode=" + urlConnection.getResponseCode() + ", Http...

Executing Java programs through Python

How do I do this? ...

Switching from .NET to Java?

For the past few years, I've been working on a team that does .NET and SQL Server. I'll soon be joining a team that is Java and Oracle. What can I read/do to get up-to-speed. ...

Castor unmarshalling exception demanding provided field

I have this schema: <?xml version="1.0" encoding="utf-8" ?> <xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt; <xs:element block="" final="" name="mensaje"> <xs:complexType> <xs:all> <xs:element minOccurs="1" maxOccurs="1" name="identificacion" type="Head" /> <xs:element...

Is Java too complex a programming language for a beginner one man programming team?

I'm trying to learn Java but it just seem like there are too many parts to put together. You have JSP, Java EE, Java SE, Java ME etc.... I can get Netbeans to do basic but just taking a peek at spring framework it seem like a lot of work to get it to run in the ide from the numerous configuration . I want to get into web programming an...

Eclipse + Turn an Existing Project into a JPA Project

Is there a way to turn a normal Eclipse Project into a JPA Project? I have a normal project with Entities in it and a Persistence.xml file, but it is not an eclipse recognized JPA project. What can I do? ...

Draw Gaussian curve in Java

I'm coding an interactive applet with Piccolo and I need to include a Gaussian curve (aka Normal distribution chart) inside it. I imagine any kind of Java implementation would be enough, but I can't find any. Ideally, I'd like to pass a set of values and have the chart drawn in a panel, an image object or anything that can be embedded ...

Why am I getting a NullPointerException when trying to read a file?

I use this test to convert txt to pdf : package convert.pdf; //getResourceAsStream(String name) : Returns an input stream for reading the specified resource. //toByteArray : Get the contents of an InputStream as a byte[]. import java.io.FileOutputStream; import java.io.IOException; import org.apache.commons.io.IOUtils; import conver...

What's the most concise / best way to write this java code?

I'm writing a simple distributed java rmi application and I have a bunch of methods that each need to iterate through a map of client interfaces in order to call various other methods on those interfaces, like so: public void methodX (arg1, arg2) { Iterator<String> itr = clients.keySet().iterator; while (itr.hasNext()) { String ...

How to nicely format floating types to String?

An 64-bit double can represent integer +/- 253 exactly Given this fact I choose to use a double type as a single type for all my types, since my largest integer is unsigned 32-bit. But now I have to print these pseudo integers, but the problem is they are also mixed in with actual doubles. So how do I print these doubles nicely in Jav...

How to change the value of array elements

int A = 300; int B = 400; int C = 1000; int D = 500; int []abcd = {A,B,C,D}; Arrays.sort(abcd); // the sequence of array elements will be {300, 400, 500,1000} I wanted to change the value of the variables A,B,C,D according to their location in the array after sorting. e.g variable A is located at index 0, so the value of A change t...

How can I find out the serialVersionUID of a serialized Java object?

I have several serializable classes that were compiled without specifying a serialVersionUID. I now need to add some data members to these classes but wish to preserve some already serialized objects. Is there anyway to find out the serialVersionUID of these serialized objects so that I can specify the same ID in the source code? ...

What Tools Exist that let me Dump and Recreate a Database from Java?

I'm looking for a tool that lets me replicate the database export and import functionality from PHPMyAdmin so that I can copy a production database to test in a build script (Gradle or Ant). ...

Possible to connect to Outlook WebMail via Java?

I want to create a java program to connect to an outlook webmail server to check for unread emails. I am not looking for an open source java based email client etc.. etc.. I am basically asking if it is possible to create a Java interface to an Outlook Webmail Server. I have been trying to hunt down how I would even begin to do this and...