java

Reference Static Methods/Variables in Java from an Instance

Can anyone explain to me why java allows you to access static methods and members from an instance? A bad example, if I have an object called RedShape and it has a static method called getColor() which returns "red", why does java allow you to call the static method from an instance of RedShape? To me this seems to violate some of the co...

Runtime dependency injection with Spring

My current project is leveraging Spring, and our architect has decided to let Spring manage Services, Repositories and Factory objects, but NOT domain objects. We are closely following domain driven design. The reasoning behind not using spring for domain objects is primarily that spring only allows static dependency injection. What i me...

Strings > 4000 to CLOB conversion using hibernate

Hi, i have a java class persisting a string (>4k) into a database table into a CLOB field. If the string is less than 4k then it works. I have the field annotated using @Lob and initially I was getting an exception due to batching not supported for streams so I made the batch size 0 in the Hibernate config which is giving the exception...

Java: SortedMap, TreeMap, Comparable? How to use?

I have a list of objects I need to sort according to properties of one of their fields. I've heard that SortedMap and Comparators are the best way to do this. Do I implement Comparable with the class I'm sorting, or do I create a new class? How do I instantiate the SortedMap and pass in the Comparator? How does the sorting work? Will i...

How to implement Java 256-bit AES encryption with CBC

Hi, I've read the following threads and they've helped a little, but I'm looking for a little more info. How to write AES/CBC/PKCS5Padding encryption and decryption with Initialization Vector Parameter for BlackBerry Java 256bit AES Encryption Basically, what I am doing is writing a program that will encrypt a request to be sent over...

mysql propogate sql exception to java program

i have a java program that is calling a Mysql stored procedure that is rolling back when it gets an SQLException. When i added the rollback (exit handler) to the store procedure the java program stopped getting the sql exception. i need for the java program to get a sql exception and the error message from mysql. does any one know how...

Java: What is the difference between implementing Comparable and Comparator?

I have seen both used. When would you use one over the other? ...

How can I download Maven artifacts within a plugin?

I have a Maven plugin that takes a groupId, artifactId, and version in its confiugration. I want to be able to download that artifact from the remote repositories and copy the file into the project. I can't figure out how to download the artifact though. I understand that I can resolve dependencies using the dependency plugin, but I ne...

Java - removing headers from .wav

I'm reading a .wav file into a byte array with the following code. AudioInputStream inputStream = AudioSystem.getAudioInputStream(/*my .wav file */); int numBytes = inputStream.available(); byte[] buffer = new byte[numBytes]; inputStream.read(buffer, 0, numBytes); inputStream.close(); Is there a simple way to remove the .wav head...

JAX-WS: stateful WS fails in a standalone process

I have a stateful web service deployed onto Tomcat. It consists of factory service and main API service, and works just fine. Factory service returns a W3CEndpointReference to main API instance, and client uses the session. Now, I'm trying to run the very same service as a standalone application. In this case, the W3CEndpointReference r...

First time use of Tomcat and the Stripes framework

I recently decided to try some java web development, so I installed xampp, the tomcat add-on, and java. I have looked at some of the JSP page examples that came with it, so I know that tomcat is at least working. However when I threw the stripes folder into the same examples directory and tried to access the files I received the followin...

JTree updates in realtime?

I'm looking for a threaded solution to updating my JTree every second. Basically, I'm... Importing an external file Creating an Enumeration off of that Building the tree off the enumeration The external file can change at random, and the data in the tree needs to represent this change in a somewhat reasonable time manner. How would ...

How can I resolve an artifact from the Maven repository within a plugin?

In a previous question I got an answer for downloading an artifact from the Maven repository. This works well for me, but I need to read the MavenProject for the downloaded artifact. What is the best way for me to read the MavenProject for the downloaded artifact in my plugin? ...

Idea Live Template to Log Method Args

I would like to be able to create a live template in Jetbrain's Idea that will log the method's arguments. Let's call it "larg". It would work like: public void get(String one, String two) { larg<tab> to create public void get(String one, String two) { log.info("get: one = " + one + " two = " + two); I'm fine with getting t...

What is the difference between setting statement fetch size in JDBC or firing a SQL query with LIMIT clause?

What is the difference between setting statement fetch size in JDBC or firing a SQL query with LIMIT clause? ...

Joda-Time: Period to string

I'm using the Joda-Time library with Java. I'm having some difficulty trying to turn a Period object to a string in the format of "x days, x hours, x minutes". These Period objects are first created by adding an amount of seconds to them (they are serialized to XML as seconds and then recreated from them). If I simply use the getHours()...

GWT - ListBox - pre-selecting an item

Hey there Stackoverflow, I got a doubt regarding pre-selecting(setSelectedIndex(index)) an item in a ListBox, Im using Spring + GWT. I got a dialog that contains a painel, this panel has a flexpanel, in which I've put a couple ListBox, this are filled up with data from my database. But this painel is for updates of an entity in my dat...

How can I find the index of the first "element" in my string using Java?

I'm working on writing a simple Prolog interpreter in Java. How can I find the last character index of the first element either the head element or the tail element of a string in "List Syntax"? List Syntax looks like: (X) (p a b) (func (func2 a) (func3 X Y)) (equal eve (mother cain)) The head for each of those strings in...

Set bufferedimage to be a color in Java

I need to create a rectangular BufferedImage with specified color as a background, draw some pattern on the background and save it to file. My problem comes from how to create the background,I am using nexted loop: BufferedImage b_img = ... for every row for every column setRGB(r,g,b); But it's very slow when the image is large. How ...

Connect to OLEDB data source from Java?

We are trying to connect to a SQL Server instance used by the ACT CRM system. They have managed to lock things down so it isn't possible to connect to the SQL back-end using ODBC (there is some special utility that will add ODBC support that you can install if you purchase the primo version of the software, but that's just crazy). The ...