java

Can Haml be used in Java web apps?

I hear about Haml as a templating engine mostly in the Ruby world. Can it also be used in Java projects? ...

Upcasting in java

In Java, suppose I have 3 classes, C extends from B which extends from A. And I have one method: public void f(A a); If I do something like this: C c = new C() B b = (B) c; f(b); f accepts b as type C since C and B both extend from A. I wanted f to receive b as type B and not type C. Is there anyway to force this upcasting? ...

how can I create a temporary folder in java?

Duplicate: stackoverflow.com/questions/375910 Is there a way of creating a temporary folder in java ? I know of File's static method createTempFile, but this will only give me a temporary file. ...

What library can I use to encode video in a Java Applet?

I would like to record the user's interaction in my Java Applet as a video to send (potentially stream) to my server with the intention of uploading to Youtube (or similar). A high frame-rate is not required (a couple frames per second is sufficient). Minimizing the bandwidth used is preferred, so sending jpeg snapshots to the server a...

how do i pass EntityManager to @PostUpdate

I want to save history of changes, so in @PostUpdate i want to create new instance of another entity and save it, how do i pass EntityManager to that method? ...

How to display html in a java application?

Hi, Now I am working on implementing a browser in Java. I need to display the contents of a website (provided a url-address) inside a JFrame window. Is there a simple way of doing that? I tried JEditorPane, but it only supports HTML 3.2, so the contents of the website looks very weird. Thanks ...

JTable or some other Java table class with advanced cell selection?

Right now I'm using a JTable for what I'm doing. After looking through the Java API and various web resources, I don't think a JTable is going to cut it anymore. What I'm looking for is a table for which I can specify very strict selection procedures. I want to be able to not only select rows and columns, but also select cells in a diago...

[java thread safety] Object visibility across threads

Hi, I have a general doubt regarding publishing data and data changes across threads. Consider for example the following class. public class DataRace { static int a = 0; public static void main() { new MyThread().start(); a = 1; } public static class MyThread extends Thread { public void run() { // Access a...

time since JVM started

Is there a way to find out the time since the JVM started? Of course, other than starting a timer somewhere near the beginning of main, because in my scenario I am writing library code and the requirement that something be called immediately after startup is a too burdensome. ...

What is the difference between Serializable and Externalizable in Java?

What is the difference between Serializable and Externalizable in Java? ...

When and how should I use a ThreadLocal variable?

When should I use a ThreadLocal variable? How is it used? ...

Why do we need constructors and private members in the abstract class?

Why do we need constructors and private members in the abstract class? It is not like we are ever going to create an instance of that class. ...

Cloning an abstract object in java

I am trying to grab an object from an array list and copy it to another array list. as per a request public abstract class codeType{ stuff } public class drawOval extends codeType{ } main{ arrayList<codeType> a arrayList<codeType> b a.add(new drawOval(stuff)) a.add(new drawOval(other Stuff)) b.add(a.get(0)...

How to sort search results on multiple fields using a weighting function?

I have a Lucene index where every document has several fields which contain numeric values. Now I would like to sort the search result on a weighted sum of this field. For example: field1=100 field2=002 field3=014 And the weighting function looks like: f(d) = field1 * 0.5 + field2 * 1.4 + field3 * 1.8 The results should be ordered ...

jstl/jsp - iterating over a vector of beans.

I have a vector of beans that holds information I want to display in my jsp page. I'm currently just using standard java expressions to display this, I want to look into using jstl to separate concerns. Is this possible, and how? I've been googling but I can't seem to find anything. ...

Make JScrollPane display scrollbars when JList inside is changed

Hi! I'm trying to change a JList inside a JScrollPane dynamically, using myList.setListData(someArray); After this I would expect the JScrollPane to show Scrollbars as needed, but this doesn't happen. Googling the issue was not very helpful. I tried various combinations of the following methods, with little success (basically poking ...

No default radio button selected (J2ME, Java)

Currently working on a mobile app in J2ME and have questions with radio button answer options. Any suggestion on how to make it so that no default answer is selected? We've tried: cg8.setSelectedIndex( -1, true ); But get an out of bounds exception error and setSelectedFlags( boolean[] ) with all false, but also get another error. T...

Changing JTable cell color

This is driving me absolutely insane. I know that, to change the formatting of table cells with JTable, I have to use my own renderer. But I cannot seem to implement this properly. This is my current setup: public class MyClass { public static void main(String args[]) { JTable myTable = new JTable(10, 10); myTable.se...

JAXB: How should I marshal complex nested data structures?

Hello! I have several complex data structures like Map< A, Set< B > > Set< Map< A, B > > Set< Map< A, Set< B > > > Map< A, Map< B, Set< C > > > and so on (more complex data structures) Note: In my case it doesn't really matter if I use Set or List. Now I know that JAXB let me define XmlAdapter's, that's fine, but I don't want to def...

Problem with paths in a java jar.

I have a folder called Etc which has an image I want to use in another file in the same folder, Example.java. So I have Etc\image.png and Etc\Example.java. I've tried using "Etc/image.png" as the image path, but that didn't work. How should I go about this? Also, suppose the files were in different packages, how would I do it? My main ...