java

How to force a Http HEAD command to terminate (for HttpClient and curl) ?

If you run this command: $ curl -XHEAD -i -H "User-Agent: myuseragent" http://www.google.com HTTP/1.1 302 Found ... snip ... Server: gws Content-Length: 222 X-XSS-Protection: 0 you will notice immediately that the curl command hangs. (I am running this in cygwin/VISTA) If you run it against twitter or facebook, curl terminates immed...

Do interfaces solve DDD with code duplication?

AccountController can't extend BaseAccount and BaseController at the same time. If I make all BaseAccount or BaseController methods empty, I can have an interface, but if I implement that interface in two different places, that is, I make a contract to implement a method in two different places, I will have duplicated code. Do interfaces...

Translating LOCs

Hi, Has anybody come across a situation where an existing code-base written (say) in Java and written by (say) French programmers had to be converted to code that English speaking programmers could understand? The problem here is that variable/method/class names, comments etc would all be in that particular language. Is there any any ...

Iframe issue in displaying java object.

Hi all, Is it possible to display a java object(by pointing it in iframe src) obtained from a servlet(In a jsp page) in an Iframe? Here is what I've tried. I'm storing a pdf file in mysql database as blob type. In the Hibernate bean class I have declared the corresponding variable as Byte[]. Now I'm trying to display the object throug...

RGB color change in oval using repaint

Write a program that shows a frame with three buttons labeled "Red", "Green", "Blue" and a label containing an icon showing a circle that is initially Red. As the user clicks the buttons, the fill color of the circle should change. When you change the color, you need to invoke the repaint method on the label. the call to repaint ensures...

How to interleave a String with a character sequence

What is the best way to interleave a java String with a given character sequence. The interleave interval should be changeable. Example: String s = " .... 0000000000000 ..."; // length random String b = interleave(s, 3, "-"); Result: ... 000-000-000-000-000 ... another example: String s = " .... we all we all we all ..."; String ...

Compiler optimization: Java bytecode

I'm currently writing a toy compiler targeting Java bytecode in the translation. I would like to know if there is some kind of catalog, maybe a summary, of various simple peephole optimizations that can be made in the emitted bytecode before writing the .class file. I actually am aware of some libraries that have this functionality, but...

is it possible to build a debugger around the java scripting engine?

hi, we are using the java 6 scripting engine in our product, and now we are thinking on adding some debugging abilities. my question is: is it possible? does the java 6 scripting engine has the same capabilities like rhino as far as debugging. some documentation about how to start doing it, some code samples any information would be...

Javas DecimalFormat: how to reject "invalid" input with grouped decimals?

When using the following NumberFormat: NumberFormat amountFormat = NumberFormat .getNumberInstance(I18N.getThreadLocale()); amountFormat.setMaximumFractionDigits(2); amountFormat.setMinimumFractionDigits(2); I get the following results when parsing via System.out.println(amountFormat.parse(value)); 10,50 => 1050 10,5 => 105 ...

Getters on an immutable type

I am writing some immutable types in Java and wonder about how to name the accessor methods. The Java Bean specification says that the names of accessors should be getX or isX, but since the fields are final, there is no setter and the fields are more like attributes than properties. There for I'd prefer naming the getter methods like: ...

Security framework for java with object granularity

I am looking for a security framework for Java web application with Object granularity. What it means is that I don't just want to filter by urls or by roles, but by specific user ownership of domain objects inside the system. For example, if there is a Message object that has a Sender user and a Receiver user I would like to be able ...

Web Application, which route to go!?

Hi, I'm going to develop a web application based on mathematics. It's going to provide stuff like canvas' showing graphs (quadratics etc.) and also provide an exercise area to test knowledge. I am stuck as to which route to take. I haven't developed a Web Application before and I am most confident working in C# applications. I would pr...

Best Duration type in Java or .Net

I have seen way to many places where a method takes a long or an int to represent durations in either nanoseconds, milliseconds (most common), seconds and even days. This is a good place to look for errors, too. The problem is also quite complex once you realize that you can mean for the duration to be a certain number of seconds, or an...

Java key - key map

Hi, I need a kind of map which is accessible in two directions, so with a key-key structure instead of key-value. Does this exist in Java? If not, what is the best way to create it? So example: mySpecialHashMap.put("key1", "key2"); mySpecialMap.getL2R("key1") returns "key2"; mySpecialMap.getR2L("key2") returns "key1"; ...

How do I kill a thread from another thread in Java?

I am calling two threads from a main thread, call them thread 1 and thread 2. When thread 1 stops, I want to stop or kill thread 2 also. How can I do this?There is a change in actual output what i want.That is There is a main class which is also thread.From main class i am calling thread1 and thread2.I am giving an input to thread1 from ...

DBUnit, run insert-select statement

Hi, I use DbUnit to load data into a DB for some integration tests. The data is specified in a flat XML file like so: <user id="2" name="bob" type="user"> <user id="1" name="john" type="admin"> However in the case of one table, the rows I wish to insert are based on rows already inserted into other tables. The most convenient way for...

JAXB - generating classes from XSD - converting enums to strings

Using JAXB, we generate our Java beans directly. In the XSD, we have an enumerated type: <xs:simpleType name="promptBeforeCloseType"> <xs:restriction base="xs:string"> <xs:enumeration value="default"/> <xs:enumeration value="always"/> <xs:enumeration value="never"/> </xs:restriction> </xs:simpleType> JAXB ge...

How can I Monitor cpu usage per thread of a java application in a linux multiprocessor environment?

Hello, I'm running a multithreaded java app in Linux RedHat 5.3 on a machine that has 8 cores (2 quad-core cpu's). I want to monitor the cpu usage of each thread, preferably relative to the maximal cpu it can get (a single thread running on 1 of the cores should go up to 100% and not 12.5%). Can I do it with jconsole/visualVM? Is ther...

Communication between two separate Java desktop applications

I'm looking to develop two separate (but related) Java desktop applications. I want the ability for one application to trigger the other, passing in data that can then be edited and passed back, i.e. the communication will be two way. If the other application is already running I want them to just communicate, i.e. I dont want to just ...

How to test java code?

I've recently starting learning java web development and I want to learn/understand: What constitutes good java test good? For example, if there is back-end java code that validates user input from a form and then inserts into a db table, what should the respective test code look like? How do testing frameworks like TestNG, JUnit, etc....