java

Java: Load a resource contained in a jar

In my application I load resources in this manner: WinProcessor.class.getResource("repository").toString(); and this gives me: `file:/root/app/repository (and I replace "file:" with empty string)` This works fine when I run my application from the IDE, but when I run the jar of my application: java -jar app.jar The path become...

Passing exclamation point to java program on command line

I want to pass the string "!changeme!" to a java program on the command line like: java -cp "!AXIS2_CLASS_PATH!" ClientJava --userid admin --passwd "!changeme!" Using Windows XP, Java jdk 1.6.0_07. The AXIS2_CLASS_PATH gets replaced as normal, I assume by the java runtime. However the password of !changeme! also seems to be replaced...

Adding Java Objects to database

For this university assignment I have a Prize object which contains either text, Image, Video. I would like to save this information into a Blob field in a database which will be running on a PDA on Apache Derby. How can i add this data to the database? Thanks in advanced. ...

Java applet double buffer trouble (and loop trouble)

For some reason when I try to double buffer my Java applet it shows up a white square even though I'm not telling it to. Also if I try to put a loop in start() I get only a white screen even if repaint() is at the end. /** * @(#)vo4k.java * * vo4k Applet application * * @author William Starkovich * @version 1.00 2009/2/21 */ import jav...

How to detect when a variable changes value

How can I easily detect when a variable changes value? I would like the execution of the program to break on the debugger whenever a specified variable changes value. Right now I'm using Eclipse's debugger. ...

Optimizing the speed of insertion in java.util.Map/Set

Hi all, is there a way to optimize the speed of the insertions in a java.util.Collection by specifying the order of the items ? For example java.util.Set<String> set = java.util.TreeSet<String>(); will this solution: set.add("A"); set.add("B"); set.add("C"); set.add("D"); set.add("E"); be faster than this one (random order) ? set...

Java Regex - reduce spaces in a string

I dont have time to get my head around regex and I need a quick answer. Platform is Java I need the String "Some text   with spaces" to be converted to "Some text with spaces" e.g. 2 spaces to be change to 1 in a String ...

Why is C# suddenly so popular?

Why is C# suddenly so popular? There's been like a repeat explosion in the blogs lately about it; It reminds me of the earlier part of this decade when all of those frameworks for Java came out like Spring, JSF, Hibernate, Struts, Struts2, Tapestry etc... I've actually been thinking about learning C#, and it seems to contain a lot of ...

Looking for simple Java in-memory cache

I'm looking for a simple Java in-memory cache that has good concurrency (so LinkedHashMap isn't good enough), and which can be serialized to disk periodically. One feature I need, but which has proved hard to find, is a way to "peek" at an object. By this I mean retrieve an object from the cache without causing the cache to hold on to ...

Graphics2D: Drawing black on white?!

I'm sure this is a very stupid question but I can't find the answer, I'm not experienced with the Java2D API. I'm trying to create an image and write it to GIF or PNG, and I want it to use a black pen on a white background. If I don't set any colors, I get white on black. If I use setPaint() (intended for subsequent draw operations) I ge...

Website Design or Back-end logic first?

I'm currently working on a pet project of mine: a web application using Servlets/JSP and some jQuery and Javascript goodies. I just started on the project and my dilemna is: should I focus first on the website design or should I implement the back-end logic then start tweaking the design? Right now, the website is hideous (looks like puk...

How to display animation in a JTable cell

I am looking for a way to display an animated progress indicator (animated GIF, a rotating wheel rendered through Java2D etc., no preference here) in a table cell until the value that is to be finally displayed has been computed or retrieved. So far I have just put a static "pending..." text into each cell that is not yet ready to speed...

Need help with designing "infinite" threads.

I have some database table and need to process records from it 5 at a time as long as app is running. So, it looks like this: Get a record that hasn't been processed yet or not processing now by other threads. Process it (this is a long process that depends on internet connection so it could timeout/throw errors). Move to the next reco...

Is a Ruby module equivalent to a Java Interface?

As I understand it, an interface is Java is intended to enforce a design by laying out methods for classes implementing the interface to fill in. Is this the idea with a Ruby module also? I see that just like with Interfaces in Java, you can't instantiate a module in Ruby. ...

clear() impl in Java's LinkedList

I fear this is a really stupid question, but here goes: Why does the clear method in Java's default LinkedList implementation bother to walk the list and unhook all the nodes? Why not just unhook the header and leave the rest of the list connected -- the GC will get it anyway, no? Here's the method: /** * Removes all of the elements...

Math help - Can't rotate something (knowing Java would be a plus)

Okay I'm trying to rotate a Java Polygon based on it's original position of angle 0. x, and y end up being converted to an int at the end of me using them, so I could understand not seeing some change, but when the difference in angles is big like 0 to 180 I think I should see something. I've been at this for a little while and can't t...

Re-throwing exceptions in Java

In java there is a possibility of re-throwing the exception but there is any advantage in it? ...

Why are the methods of the Math class static ?

Why are the methods of the Math class static ? ...

code works for java graphics, but not graphics2d

inside a paintcomponent. it takes g as parameter, and g can be graphics or graphics2d. the class extends jpanel. then: super.paintComponent(g); this.setBackground( Color.BLACK ); if g is graphics it works, but if it's graphics2d it doesn't. it compiles with both, but graphics2d doesn't change the background color. how come? ...

Are true and false keywords?

Are true and false keywords in Java? ...