java

Open WIth dialog in Java

I was wondering if there's a cross platform way to mimic the Windows Open With dialog from inside a Java Swing application. My application is an editor for elearning packages and one of the users wanted to be able to open the content files in the editor of their choice from within the application, resources are generally HTML files, ima...

Casting objects in Java

I saw a few topics on SO about this but none really answered my question so here it is: String s = "a string"; Object o = s; s = String(o); // EDIT this line was wrong s = (String)o; // EDIT Corrected line Now this compiles fine but throws a ClassCastException. The only thing is that I thought there was some way to make this work. i...

concurrency object for writer-takes-precedence-over-reader

I'm looking for a concurrency object that can assist in the following use case: threads/entities: 1 publisher (unique), 0-many readers publisher frequently / erratically updates a data structure, needs to do so quickly and with minimal latency each reader has read access to the data structure (either through something that doesn't allo...

Has anyone used GWT and can say it really delivers what it promises?

I am a long time Java web developer and as most web developers I have used quite a lot of JavaScript. Even though I don't hate JavaScript as many other Java developers, I am still aware of its faults. GWT is a way to write javascript using java. Since I know both languages for a long time I am pretty skeptical about this claim. I mean,...

Why SQL select takes more CPU time in java?

Hi, I have a java web application that selects one column from table (with 6 million rows) and it takes a lot of CPU time. This select (SELECT id FROM mytable WHERE filename = 'unique_filename') takes significantly less time when executed in query browser. What can cause this? Where should I start to look for bottlenecks? Database i...

EJB Factory Class

Hi all I'm trying to create an EJB factory class, which works like this: You have a method which takes as argument a class of an EJB, then it checks whether the EJB has a remote interface (if not throw an exception) and if it does, it returns the concerning EJB. The code below does exactly this. However the object it returns is of the ...

Looking for an easier way to write debugging print statements in Java

EDIT: I would love to read reactions to Steve Reed's AOP approach. Comments to his answer are encouraged! I'm a novice, and at some point I realized it would be helpful to know the contents of a variable during program execution. So I started doing this: EDIT: fixed this. Used to be: var + ": " + var, which was totally wrong. Dumb typo...

What's wrong with this code?

I wrote this code: public class FileViewer extends JPanel implements ActionListener { /** * */ private static final long serialVersionUID = 1L; JFileChooser chooser; FileNameExtensionFilter filter = null; JEditorPane pane = null; JTextField text = null; JButton button; JTextArea o = null; URL url; public FileViewer(JTextArea...

Anyone heard about a standard property deployment.name?

I've just fought for a whole day with a strange maven problem: I had a custom property called "deployment.name" that was never to resolved to what I configured for it, but rather the maven filtering mechanism always replaced it by the project's name. I tried the goal "help:expressions" to find out whether this is a preconfigured prop...

dynamically creating & destroying logging appenders

I have a legacy PSVM application which I'd like to redirect its logging output to unique files per execution. So, if I invoke it at 10:00, then have it redirect it's output to {thread-id}-10:00.log; and another thread of execution may begin an execution at 10:01, and its output would go to {thread-id}-10:01.log. I understand that this i...

Filtering XML while preserving its structure

I'd like to remove certain tags from an XML document as part of a filtering process but I cannot otherwise modify the appearance or structure of the XML. The input XML comes in as a string eg: <?xml version="1.0" encoding="UTF-8"?> <main> <mytag myattr="123"/> <mytag myattr="456"/> </main> and the output needs to remove mytag...

How can I open an HTML page and show it in a text area?

How can I open an HTML page and show it in a text area? (If I choose the HTML file with the JFileChooser, how can I open that page and show it in the text area?) URL url = new URL(String s); JEditorPane pane = JEditorPane(url); But how can I find the link of the HTML file for inserting as s, here!? ...

AS400 Java Java program completed with exit code 1

Every attempt to run a java program on our AS400 (I5 OS VR4, JVM 1.4.2) result in the same error message: Java program completed with exit code 1 Any suggestions? ...

Helper in order to remove null reference in Java List ?

Hi, Suppose the following List List<String> list = new ArrayList<String>(); list.add("s1"); list.add("s2"); list.add(null); list.add("s3"); list.add(null); list.add("s4"); I need a Helper class that removes null references. Something like SomeHelper.removeNullReference(list); Now, list only contains "s1", "s2", "s4", "s4". Non-nul...

Why is it allowed to access Java private fields?

Consider this example : import java.lang.reflect.Field; public class Test { public static void main(String[] args) { C c = new C(); try { Field f = C.class.getDeclaredField("a"); f.setAccessible(true); Integer i = (Integer)f.get(c); System.out.println(i); } catch (Exception e) {} } } cl...

Do final members assigned constants on declaration get optimized at run-time to 'static final's?

When I define constant values in my Java code, I generally declare them 'private static final', but recently I've been maintaining code where the constants are defined 'private final'. I'm optimizing at the moment and was wondering whether to 'static'ize these. For example public class X { private final String SOME_CONST = "Whatev...

Changing a JLabel's Value from a JSlider's Value

I have a single JPanel that contains a JSlider and a JLabel. I want to configure it so that when the JSlider's value is being changed by the user, that new value is reflected by the JLabel. I understand that I can fire ChangeEvents with the Slider, but I don't know how to add a ChangeListener to the JLabel. Here's a snippet of my code. ...

How do you do a limit query in HQL

In Hibernate 3, is there a way to do the equivalent of the following MySql limit in HQL. select * from a_table order by a_table_column desc limit 0, 20; I don't want to use setMaxResults if possible. This definitely was possible in the older version of Hibernate/HQL, but seems to have disappeared. ...

What is your favorite linux environment for Web Development especially in Java?

Which Linux distribution are you using? Which Linux tools are you using? (I know Eclipse is one of them.) ...

Serve a jar file from within a war file (as a resource)

I have a web app: MyApp.war, inside it, I have a jar file: WEB-INF/lib/PublicJar.jar I want client applications to be able to download that jar like a web resource. e.g http://theserver.com/myapp/jars/PublicJar.jar I want the web application to be able to compute the hashcode of the jar file to see if it has changed, so clients know i...