java

Java: Easiest way to replace strings with random strings

A string will be made up of certain symbols (ax,bx,dx,c,acc for example) and numbers. ex: ax 5 5 dx 3 acc c ax bx I want to replace one or all of the symbols (randomly) with another symbol of the same set. ie, replace one of {ax,bx,dx,c,acc} with one of {ax,bx,dx,c,acc}. replacement example: acc 5 5 dx 3 acc c ax bx or c 5 5 dx 3 acc ...

Using Regular Expressions to Extract a Value in Java

I have several strings in the rough form: [some text] [some number] [some more text] I want to extract the text in [some number] using the Java Regex classes. I know roughly what regular expression I want to use (though all suggestions are welcome). What I'm really interested in are the Java calls to take the regex string and use it ...

Could "attach source" be made easier for popular Java libraries?

I run into this obstacle when my debugger steps into some classfile without corresponding source. Finding it is often difficult: You have to search for the site hosting the respective project, and find its ``download source'' page (for instance, last time I searched for the JPA API, and it took me hours to obtain the sources). Or, yo...

How do I create a custom JPanel extension and use it from the NetBeans palette?

I have a JPanel extension that I've written and would like to be able to use it in the NetBeans designer. The component is simply adds some custom painting and continues to function as a container to be customised on each use. I have properties to expose in addition to the standard JPanel ones and have a custom paintComponent() metho...

abstract methods in skeletal implementations of interfaces

I was re-reading Effective Java (2nd edition) item 18, prefer interfaces to abstract classes. In that item Josh Bloch provides an example of a skeletal implementation of the Map.Entry<K,V> interface: // Skeletal Implementation public abstract class AbstractMapEntry<K,V> implements Map.Entry<K,V> { // Primitive operations ...

What's the best way to check to see if a String represents an integer in Java?

I normally use the following idiom to check if a String can be converted to an integer. public boolean isInteger( String input ) { try { Integer.parseInt( input ); return true; } catch( Exception e ) { return false; } } Is it just me, or does this seem a bit hackish? What's a better way? EDIT:...

Java: How does the VM handle a 64bit `long` on a 32bit processor

How does the JVM handle a primitive "long", which is 64bits, on a 32bit processor? Can it utilise mulitple cores in parallel when on a Multi-Core 32bit machine? How much slower are 64bit operations on a 32bit machine? ...

What's your favorite feature in Java?

After the series of Hidden feature posts, now is the time for listing down your favorite features. This thread will be used for listing Java specific features. This is a community wiki. Please be specific. Update : For .Net, please post your answers here: What’s your favorite feature in .NET? ...

What is the easiest way to do 'is' in Java?

Many languages have a facility to check to see if an Object is of a certain type (including parent subclasses), implemented with 'is' and used like this: if(obj is MyType) Or slightly more tediously you can in other languages check by using the 'as' keyword to do a soft typecast and seeing if the result null. I haven't used Java i...

Java Vector Field (private member) accumulator doesn't store my Cows!

Edit: This code is fine. I found a logic bug somewhere that doesn't exist in my pseudo code. I was blaming it on my lack of Java experience. In the pseudo code below, I'm trying to parse the XML shown. A silly example maybe but my code was too large/specific for anyone to get any real value out of seeing it and learning from answers ...

java.lang.Exception vs. rolling your own exception

At what point would you create your own exception class vs. using java.lang.Exception? (All the time? Only if it will be used outside the package? Only if it must contain advanced logic? etc...) ...

Java Comparator

Does any one know of some kind of Comparator factory in Java, with a public Comparator getComparatorForClass(Class clazz) {} It would return Comparators for stuff like String, Double, Integer but would have a public void addComparatorForClass(Class clazz, Comparator comparator) {} For arbitrary types. ...

How do I get my dependenices inject using @Configurable in conjunction with readResolve()

The framework I am developing for my application relies very heavily on dynamically generated domain objects. I recently started using Spring WebFlow and now need to be able to serialize my domain objects that will be kept in flow scope. I have done a bit of research and figured out that I can use writeReplace() and readResolve(). The ...

Java HTML Parsing

Hello everyone. I'm working on an app which scrapes data from a website and I was wondering how I should go about getting the data. Specifically I need data contained in a number of div tags which use a specific CSS class - Currently (for testing purposes) I'm just checking for "div class = "classname"" in each line of HTML - This wor...

Worst Java practice found in your experience?

Similar to this question... What are the worst practices you actually found in Java code? Mine are: using instance variables in servlets (it's not just bad practice but bug, actually) using Collection implementations like HashMap, and not using the appropriate interfaces using seemingly cryptic class names like SmsMaker (SmsFactory) ...

question about java interfaces

Let's say I have the following ruby code : def use_object(object) puts object.some_method end and , this will work on any object that responds to some_method,right? Assuming that the following java interface exists : interface TestInterface { public String some_method(); } Am I right to presume that interfaces are java's wa...

java package for encryption

hi to every one . I want to ask a small question.. I need to write program that encrypt text with 32-bit algorithm using Java . so what is the appropriate package or library to do that ? thanks for all ...

What technology should I use to create a distributed Accounting Software?

Here are my current options. .Net : Using WPF, Visual C#, SQLServer Java : Using Spring, Hibernate, Enterprise DB, web-based Can you suggest which one is better?, especially with regards to building complex forms. ...

Is it possible to obtain warnings from javadoc when something missed in javadoc-comments?

Accidentally I may forget to describe some parameters or exception throwing (or something else) when documenting methods or classes, etc. Is it possible to run javadoc in such a way that it warns me about missing documentation items? (I use ant script for generating documentation) ...

Missing ant-javamail.jar file on Macintosh

I've been running the built-in Ant from the command line on a Macintosh (10.5.5) and have run into some trouble with the Mail task. Running the Mail task produces the following message: [mail] Failed to initialise MIME mail: org.apache.tools.ant.taskdefs.email.MimeMailer This is most likely due to a missing ant-javamail.jar file in th...