java

Python - Create a list with initial capacity

Code like this often happens: l = [] while foo: #baz l.append(bar) #qux This is really slow if you're about to append thousands of elements to your list, as the list will have to constantly be re-initialized to grow. (I understand that lists aren't just wrappers around some array-type-thing, but something more complicated....

JButton expanding to take up entire frame/container

Hey everyone. I'm trying to make a swing GUI with a button and a label on it. im using a border layout and the label ( in the north field ) shows up fine, but the button takes up the rest of the frame (it's in the center field). any idea how to fix this? ...

Java Private Field Visibility

So I was making a class the other day and used Eclipse's method to create the equals method when I realized that it generated the following working code: class Test { private int privateInt; [...] public boolean equals(Object obj) { [...] Test t = (Test) obj; if ( t.privateInt == privateInt ) { [...] } } t.priv...

Generating partitions in Java

I am given an integer (lets call it x) and I need to generate an array of arrays, where each subarray is a list of elements which are one of a given set of integers, and the sum of all of the elements of each subarray is x. The array of arrays needs to contain all possible distinct subarrays of this form. For example, if x is 3 and the ...

If construct in hashmap.put call

I have a variable of type Hashmap<String,Integer>. In this, the Integer value might have to go some manipulation depending upon the value of a flag variable. I did it like this... Hashmapvariable.put( somestring, if (flag_variable) { //manipulation code goes here new Integer(manipulated value); } else { new Integ...

Starting working with Eclipse RCP

I'm going to start maintaining an Eclipse RCP application for my current employer soon. What are your experiences with this platform? What are the pros, what are the cons, what are the caveats that I should be aware of? Also, what reading materials (books, tutorials) can you recommend? Most of the tutorials I found on the web are outdate...

A COBOL programmer thinking about switching to the modern world

I would like to know what are the best options for a COBOL programmer to switch to more modern platforms. I explored Java but will all its frameworks its overwhelming. .NET appeared much simpler but I'm worried if it will result in a vendor lock-in; we have had enough of it with COBOL. What about other choices such as LAMP, Ruby On rai...

Looking for an embeddable SQL beautifier or reformatter

I am looking for a Java open source beautifier or reformatter for SQL that I can use to clean up DDL statements that I am generating with openArchitectureWare. Nothing in the answer to "Online Code Beautifier And Formatter" is of use to me and I have not been able to get Simple SQL Formatter to work for me. ...

How could I allow only unique strings in a JList ?

I have a JList that holds a bunch of strings . I would like it to act like a Set , so that it will only hold unique values . Is there any way to achieve this without checking that a new string doesn't already exist there ? ...

how many classes per package? methods per class? lines per method?

Hi, I have to give a general note to some huge java project for which I have but little visibility and I was wondering if there were any guidelines for determining: what number of classes per package can be considered right, to low, or to high (this project has 3.89 classes per package, which seems a bit too small for me), number of ...

How to use size of file inside Ant target

I'm currently in the process of replacing my homebrewn build script by an Ant build script. Now I need to replace various tokens by the size of a specific file. I know how to get the size in bytes via the <length> task and store in in a property, but I need the size in kilobytes and megabytes too. How can I access the file size in othe...

How to get rid of the white rectangle flashing that occurs during Java applet loading ?

While an applet is loading, it displays a white rectangle for a split second. How can we get rid of it? ...

Why Doesn't Sun Release Their Own Java Implementation for OS X?

Sun's Java SE 7 is set to release next year, and we still have yet to see a stable, complete implementation of Java SE 6 from Apple. Why doesn't Sun release their own implementation of Java for OS X? ...

How do I track plugin dependencies in maven2 ?

I am trying to locate an evil plugin that includes a stoneage version of a certain jar file. How do I do that ? ...

Why is using a class as a struct bad practice in Java?

We recently had a code review . One of my classes was used so that I could return/pass more than one type of data from/to methods . The only methods that the class had were getters/setters . One of the team's members ( whose opinion I respect ) said that having a class like that is bad practice ( and not very OOP ) . Why is that ? ...

Providing a common interface to SVN and CVS

SVN and CVS are two very different systems that aim to address the same basic issue - source control. They both work in distinct ways, so it's probably difficult to deal with them exactly the same. What I'm wondering is, would it be conceivable to develop a programming library or API that exposes the same interface, but under the hood,...

can jconsole be used with J2EE?

all the examples I see are for J2SE applications by passing your JAR file at the command line. Can JConsole attach to a WAR or EAR and monitor application performance? ...

Can anyone quantify performance differences between C++ and Java?

Java was initially slow before the JIT but today performance is pretty close to C++. I want to know if someone has done measurable performance comparisons between the two languages? Where does Java fall short when compared to C++? Java provides many productivity gains to developers so they can write applications much quicker because o...

Interaction between Java and C#

Is it possible to write a user interface in Java for an application written in C#? I am working on a user interface of a project that is written in C#, but I have no experience with C# and I am an avid Java user. Is it possible to build the user interface in Java using Java's Swing and AWT libraries that operates an application primaril...

Hierarchical table column in Java

Dear All, Is there any Java library that supports hierarchical column? For example (the first three row are columns) : 2008 | January | February | Week1 | Week2 | Week3 | Week 1 | Week2 | Week3 | 10 | 20 | 14 | 12 | 15 | 3 | Thanks ...