java

How do I compare strings in Java?

I've been using the "==" operator in my program to compare all my strings so far. However, I ran into a bug, changed one of them into .equals() instead, and it fixed the bug. Is "==" bad? When should it and should it not be used? What's the difference? Thanks ...

Java Rule Engine for Game AI

I would like to use a rule engine for my game. It will be used for NPC AI, and GM AI. What might be a good and fast Rule Engine for this purpose ? It must be Java and Open Source. I would like to hear from people who have used Java Rule Engines for Artificial Intelligence about their experience. ...

Whats the best way to process an asynchronous queue continously in Java?

I'm having a hard time figuring out how to architect the final piece of my system. Currently I'm running a Tomcat server that has a servlet that responds to client requests. Each request in turn adds a processing message to an asynchronous queue (I'll probably be using JMS via Spring or more likely Amazon SQS). The sequence of events is...

Alternatives to Regular Expressions

I have a set of strings with numbers embedded in them. They look something like /cal/long/3/4/145:999 or /pa/metrics/CosmicRay/24:4:bgp:EnergyKurtosis. I'd like to have an expression parser that is Easy to use. Given a few examples someone should be able to form a new expression. I want end users to be able to form new expressions ...

Saving a BufferedWriter instance in a class. Any problems ?

I am creating a service that looks similar to this: interface MyLogger { void logStuff( int id, String message ); } The implementation basically opens a file and caches an instance of the BufferedWriter in the class. The method is synchronized. Is it ok to have an opened file wrapper by a BufferedWriter in a long live manner ? A...

Need help fixing a regular expression

I'm using the Java matcher to try and match the following: @tag TYPE_WITH_POSSIBLE_SUBTYPE -PARNAME1=PARVALUE1 -PARNAME2=PARVALUE2: MESSAGE The TYPE_WITH_POSSIBLE_SUBTYPE consists of letters with periods. Every parameter has to consist of letters, and every value has to consist of numerics/letters. There can be 0 or more parameters. ...

Factory methods for implementations of Java interfaces wrapped with Scala implicits?

I'm using Scala implicits to define a rich wrapper for a Java interface: class RichThing { def richStuff: Unit = {} } In the companion object I define the implicit conversion and an apply factory method: object RichThing { implicit def rich( thing: JavaThing ) = new RichThing() def apply() = new RichThing() } With this, I...

Can someone explain to me what the reasoning behind passing by "value" and not by "reference" in Java is?

I'm fairly new to Java (been writing other stuff for many years) and unless I'm missing something (and I'm happy to be wrong here) the following is a fatal flaw... String foo = new String(); thisDoesntWork(foo); System.out.println(foo);//this prints nothing public static void thisDoesntWork(String foo){ foo = "howdy"; } Now, I'm w...

Modify JVM args from inside the JVM

Is there a way to modify the jvm args from inside of the jvm? Specifically, I want to be able to change the maximum heap size of the jvm from inside of it. Is this possible? Edit: I guess I should add the reason I wanted to do this. I have a few Java programs that are run on different machines/platforms. These programs have configur...

Java HTTP Snooper(Proxy) Does Not Forward Server Response

I am writing somewhat of a proxy program in Java. Here's how it works: The browser will be connected to the program. Any requests by the browser will be first be printed out to standard out, then forwarded to the server. The server then returns a response, which is also printed to standard out, then forwarded back to the browser. My ...

Truncate String on closest word boundary.

Is it possible to truncate a Java string to the closest word boundary after a number of characters. Similar to the PHP wordwrap() function, shown in this example. ...

How to initialize a value in web.xml from a JNDI variable?

Hi All, In my Java web application, the NTLM domain controller name is specified in web.xml like this: <filter> <!-- other code --> <init-param> <param-name>jcifs.http.domainController</param-name> <param-value>DCNAME</param-value> </init-param> <!-- other code --> </filter> In the above XML, we've hard-coded t...

How to make the output text attribute value as a hyperlink?

I should display the bookmarks as hyperlink.so on clicking the bookmark will take me to corresponding web page.Can any one tell me how should i achieve my goal?Thanks. <html> <f:view> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> ...

Java: Basic OOP Question

I have written a program with both a Advanced Mode and a Beginner Mode to allow the user to get the hang of my program before it is actually used. The Advanced Mode is almost identical to the Beginner Mode apart from one or two methods needing to be replaced by another, so I have decided to create a general Mode class for both Advanced M...

Insert rows (parent and children) programmatically

I am using Spring and JDBCTemplate. The scenario is a CUSTOMER table and ORDERS table - parent-child relationship. I want to do an insert (for example 1 customer and 5 orders) - but I am unsure how you programmatically insert a row in the CUSTOMER table (some how get hold of the Oracle generated unique id), and then insert the correspo...

How expensive is Java Locking?

In general, how expensive is locking in Java? Specifically in my case: I have a multi-threaded app in which there is one main loop that takes objects off a DelayQueue and processes them (using poll()). At some point a different thread will have to remove errant elements from the queue (using remove()). Given that the remove() is relat...

What does cmd /C mean?

I can understand cmd but not /c. I was trying to invoke a java program from the current for which I use Runtime.getRuntime().exec("cmd /C java helloworld") There arises my doubt. ...

Netbeans, Ant and RMIC (Java RMIC Compiler) (Help with)

Hi guys, I'm rather miffed / baffled at the moment. I've got a Netbeans project, that compiles fine. I've edited the build.xml file to create a "-post-compile" target, which does an rmic ant task. So now, when I "clean and build" it compiles my main code, then generates the rmic stubs for me. However, when I chose to 'Run' my netbeans...

Looking for a .NET 3.5 / J2EE architecture concept comparison article/chart

We are thinking about combining .NET technology with Java technology (WCF, JBoss/ESB, MOM, WPF, WF) and I need to have a high-level idea of what are the apples and oranges in the .NET 3.5 and Java worlds. Does anyone know of a good, clear article or better yet a simple chart which answers questions such as: WCF in the Java world is _...

How to access objects/arrays defined in JavaScript from Java applets.

Using LiveConnect getMember(String) method of a window JSObject, a Java object of type "Object" is returned but I don't find the expected members defined on it. Neither can I cast it to a JSObject to continue using the getMember(). Accessing DOM nodes and elements (DOM Objects) works as expected. ...