java

Cannot decrypt cyphertext from text file, symmetric key implement. in java

Hello there. So basically my program encrypt/decrypt string from text file which user choose. He can select one of five algorithms. The problem is when I create ciphertext with eg. AES and then save this ciphertext to text file and want to decrypt it to get the original string it does not work. Can someone point out where is the problem ...

Resize form objects in Java

I have a Java applet, which is a form that draw shapes into it (Rect, Oval, Line). Each shape is represented by 2 points and can draw itself to the form. When the JApplet form resizes, I need to resize the shapes also while keeping the aspect ratio. I didn't find an high quality solution for doing this that solves this problem. Tried t...

Why isn't this method chosen based on the runtime-type of its object?

Consider this: class A { int x =5; } class B extends A{ int x =6; } public class CovariantTest { public A getObject() { return new A(); } /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Covar...

Why is this class not Serializable?

I was using the Mersenne-Twister implementation at http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/JAVA/MTRandom.java as a drop-in replacement for the default java.util.Random class. However, four fields (an int, a boolean and two byte[]) are marked as transient. This means that I can't serialize an object of this class without ...

multidimensional array row to single array java

Hi I have the array below, I need to copy the contents into another single dimensional array but only the first row e.g. 0 and 1 String data[][] = new String[][] { {"0", "1", "2", "3", "4"}, {"1", "1", "2", "3", "4"} } The above code is an example of how I have set my array, I just need the first row but for every co...

Install Maven2 on Karmic

Is there a .deb for Maven2 on Karmic Koala? I see maven2, but it has 100+MB of dependencies (!). Is there a package that is only mvn and none of those dependencies? ...

How to play a sound in a JSF web app?

Is it possible to play a sound (.wav or .mp3) in a client's browser using a JSF web app? I have tried using javax.sound.sampled.SourceDataLine and it worked on Windows, but when I deploy the .war on a Linux host I get this exception: "javax.sound.sampled.LineUnavailableException: Audio Device Unavailable" ...

How to easily copy one type of list into another type?

Say I want to copy all elements of list A into list B. But the elements in list A are of type ExampleClass and elements in list B are String. ExampleClass { String a; } Since ExampleClass has an attribute a which is a String, when converting from ExampleClass to String I want the value of a to be returned as the String that repres...

Java: How to "trim" a byte array?

So I have some code that reads a certain amount of bytes from a file and returns the resulting byte array (this is basically used for chunking up files to send over the network as (eventually) base64-encoded ascii text). It works fine, except that when the last chunk of the file is generated, it isnt a full chunk. Therefore, the resulti...

How can I introspect a freemarker template to find out what variables it uses?

I'm not at all sure that this is even a solvable problem, but supposing that I have a freemarker template, I'd like to be able to ask the template what variables it uses. For my purposes, we can assume that the freemarker template is very simple - just "root level" entries (the model for such a template could be a simple Map). In other...

Dealing with ugly SQL in Java

Here goes a SQL-Java coding style question... How do others here deal with creating complex custom queries in Java cleanly? I am speaking of the seemingly simple task of preparing a string which is the SQL statement to be executed. I am aware of HQL, and also of stored procedures, but honestly I don't really love these solutions. Perh...

Embedding Processing in Java/Groovy

Is there a way to embed seamlessly Processing code into a Groovy application? If it not exists, is there a way to do it in Java? I mean something to attach a component like a JFrame with the content of a processing script having possibility to exchange data between both. ...

URL shortening: redirection to a 'file://' target (file protocol target)

Hi, I am trying out a simple implementation of a URL shortener such as tinyurl.com or bit.ly. Currently I do a response.sendRedirect(targetURL) in my servlet - which works fine for http/ftp target URLs. However, I'm having problems redirecting to targets such as file:///c:/temp (where c:\temp is of course on the local/client system). ...

What is the differance between applets and SWING?

What is the difference between applets and SWING? ...

Looking for a dynamic DNS server written in Java

I'm experimenting with an idea for a local network application that requires a dynamic DNS server that get new addresses from a database. This is only for prototyping but I need to be able to extend it using some Java logic and a SQL database. Any ideas? ...

question about "Java Concurrency in Practice" example

I'm looking at a code sample from "Java Concurrency in Practice" by Brian Goetz. He says that it is possible that this code will stay in an infinite loop because "the value of 'ready' might never become visible to the reader thread". I don't understand how this can happen... public class NoVisibility { private static boolean read...

why it returns SQL exception?

I have a "Manager" class and also one frame which is"Report" .In the frame I have three radio buttons which their texts are "Years before 1970","between 1970 and 2000","years after 2000" and if one of them is selected , in the text field below these radio buttons I will show the number of rows that have this situation which are in my SQ...

how to convert xml string to xml file?

Hi All, I have String in xml format i need to convert that to a xml file,how would i do this? ...

Someone please help me with this Web Content Display problem in Liferay..im stuck !

Hello, Any way to make the web content appear maximized by default instead of minimized ?.Im using Liferay v5.2.3 Community Edition. Please Help. Thank You ...

How do I conditionally include or exclude a file from an archetype when project is generated?

I'm creating Maven 2 archetypes for our project (Weld). I would like to be able to control which files are placed into the generated project based on the value of a property that is defined during archetype:generate. For instance, I foresee the following prompt: Define value for groupId: : com.example Define value for artifactId: : mypr...