java

Java: Detect duplicates in ArrayList?

How could I go about detecting (returning true/false) whether an ArrayList contains more than one of the same element in Java? Many thanks, Terry Edit Forgot to mention that I am not looking to compare "Blocks" with each other but their integer values. Each "block" has an int and this is what makes them different. I find the int of a p...

What is the most elegant way to cast a variable you just received as an argument?

More specifically, what's the most elegant way to cast the Graphics object in a paint() call up to a Graphics2D object? public void paint(Graphics g) { // How do I convert/cast/etc the g variable to a Graphics2D object? } Or am I missing the point here? Is there a better way to handle this in general? ...

Log4J - Is there any point in explicitly specifying the class name in the call to LogManager.getLogger()?

I'm working on some legacy code with a lot of code like private final Logger logger = LogManager.getLogger(ThisClassName.class); I'm wondering if there is any advantage to typing out "ThisClassName.class" as opposed to LogManager.getLogger(getClass()); As far as I can tell, there is none, but I'm wondering if there are any negative...

Why are my RenderingHints keys, when applied to a Graphics2D object, not being honored?

When drawing various things using a Graphics2D object and BasicStroke at 1.0f, I can't seem to get the g2d object to honor my RenderingHints settings. Specifically the *KEY_ANTIALIASING* set to *VALUE_ANTIALIAS_ON*. public void paint(Graphics g) { Graphics2D g2d = (Graphics2D)g; g2d.setStroke(new BasicStroke(1.0f)); g2d.set...

Is it possible to do bytecode manipulation when using OSGi?

I'm making an application server and in it I need to use some bytecode manipulation (e.g. inserting custom equals and hashCode methods to classes annotated with @Entity). Now I give the JVM a Java Agent (the -javaagent option) which does bytecode transformations using ASM. I've been considering using OSGi, but I don't know whether it al...

NoSuchTableException being thrown from dbunit test cases

I'm trying to fix the test suite on an project which I've inherited from another programmer for some java database code. The project itself is using hibernate and MySQL for the DB stuff, but for the purposes of the test cases dbunit is being used. I can correctly load and initialize hibernate's session factory, but I keep getting excep...

java bit manipulation

byte x = -1; for(int i = 0; i < 8; i++) { x = (byte) (x >>> 1); System.out.println("X: " + x); } As I understand it, java stores data in two's-complement, meaning -1 = 11111111 (according to wikipedia). Also, from the java docs: "The bit pattern is given by the left-hand operand, and the number of positions to shift by the r...

Is toString() only useful for debugging?

Besides of course, their use with primitives. Most (if not all) of the implementations I see are only useful from a programmer viewpoint. EDIT: I understand that I'm supposed to override the default behavior, that's why I mentioned implementations :). And I do get the value of overriding it in some components requiring a String repres...

How to get involved in Open Source?

Duplicates: http://stackoverflow.com/questions/43649/how-to-get-involved-in-an-open-source-project http://stackoverflow.com/questions/382977/what-are-the-steps-to-start-contributing-to-an-open-source-project http://stackoverflow.com/questions/335036/what-is-a-good-resource-to-help-start-an-open-source-project http://stackoverflow.com/q...

Should I learn Swing before learning JavaFx ?

Does it make sense to start learning JavaFx if I do not have any background in UI programming? Is it more advisable to learn Swing first and then move on to JavaFx ? I tried the getting started tutorial on JavaFx website in Netbeans and the code looked extremely complicated to me. I am wondering if JavaFx is too advanced for a beginnner...

In Java when one interface extends another, why would one redeclare a method in a subinterface?

I've been looking at the JMS API from J2EE and found a strange behavior where certain methods that are declared in an interface (e.g., createQueue in Session) are declared again in the subinterfaces such as QueueSession, and with identical documentation. Since an subinterface "inherits" all the method declarations of the interface it in...

JVM performance tuning for large applications

The default JVM parameters are not optimal for running large applications. Any insights from people who have tuned it on a real application would be helpful. We are running the application on a 32-bit windows machine, where the client JVM is used by default. We have added -server and changed the NewRatio to 1:3 (A larger young generation...

Is Java overkill for news websites?

A client of mine wants a news website designed in Java, and I told him that Java is overkill for that kind of website. I suggested to him that there are dozens of CMS that we can customize for him, as well as other programming languages that are better suited for websites but he insisted. Is Java overkill for news websites? ...

How to abort the call to webservice at both client and server end?

I can abort the web service call from client by calling ABORT method of web service proxy. However at server where web service is hosted, the call only ends when it completes the processing. As server doesn’t expect any other inputs related to already called web method while processing it, I am not able to close it from client. Is the...

Create directory with write permissions for the group

I create a folder in my java program (running on linux) with mkdirs() function of File object. The problem is that the folder gets only read permissions for the group. I need it to have also write permissions (in order to be able to delete its files later). What is the way to do it? ...

Visual swing in Eclipse

Is there any way I can use a visual editor to make swing applications in Eclipse? I'm using Ganymede. ...

Can you store a variable inside a if-clause - Java

I'm kinda waiting for a 'no' answer on this question. I was interested if you can save a variable at the same time when you checking it in an if-clause. Let's say I have this code. if(foo!=null){ if(foo.getBar()!=null){ Bar bar = foo.getBar(); System.out.println("Success: " + bar); } else { System.out.println("Failure...

Converting an array of objects to an array of their primitive types.

If you have an array of java objects which have a primitive type (for example Byte, Integer, Char, etc). Is there a neat way I can convert it into an array of the primitive type? In particular can this be done without having to create a new array and loop through the contents. So for example, given Integer[] array what is the neate...

ICEfaces: How to disable send-receive-updates mechanism for some forms

I am quite new to ICEfaces but already have experience with JSF/Facelets and the Java EE in general. Currently, I am not using to much of ICEfaces except some utility tags like outputStyle and outputDeclaration, but even this is really nice to have. Even though I plan on using some AJAX functionality later, I have some h:forms (or ice:...

What is the best way to display multiple PDF files via browser?

I'm developing an web application using Flex and JSP. I am having some performance issues with displaying multiple PDF files. I am trying to display about 50-100 PDF files. I know that is a little crazy. Hence, I made the project to convert PDF files to JPG format and display the JPG files. I'm wondering if there is a way to decrease t...