java

hashCode() method when equals() is based on multiple independent fields

i have a class whose equality is based on 2 fields such that if either one is equal then the objects of this type are considered equal. how can i write a hashCode() function for such an equals() so that the general contract of hashCode being equal when equals returns true is preserved? public class MyClass { int id; String name; ...

Questions to indicate competency in Java

As a beginner in Java, I would like to know where I'm learning things (correctly), where I'm learning things incorrectly, and what I should learn next. I find I learn best by being given problems I can't immediately solve, and I need to do some research/learning to work out the best solution, then go onto the next problem. I then repea...

Data structures in JDK, under what scenario which one to use?

Does there exist a cheat sheet for data structure like TreeMap, SortedMap, HashSet etc and under what circumstances which one to use. Are there good articles you recommend ...

How to limit JTextArea max Rows and Coloums?

I am using JTextArea in JScrollPane I want to limit the maximum number of lines possible and the maximum chars in each line. I need that the string will be exactly like on the screen, each line will end with '\n' (if there another line after it) and the user will be able to insert only X lines and Y chars in each line. I tried to limit ...

JTable values "jump" in another cell after pressing Enter

Hello, I am working with Java. I have created a JTable, and I have made the cells of the table editable. My problem is that when I select a cell and write a value in it, and then click Enter, the value, which I have typed does not stay in the cell where I have typed it, but jumps in another cell somewhere in the table. The value stays t...

Replace a database connection for subreports with JRC

Hi Since I'm using a newer release of JRC a replacement of database connection information do not work any more. I've no idea why. This code worked with a JRC version from last autumn (unfortunately I don't have a release number): ReportClientDocument doc = new ReportClientDocument(); doc.open("report.rpt"); IDatabase db = null; // g...

Choices: Migrating from Classic ASP to .NET or Migrate to Open-Source Platform

My organization has a lot of legacy ASP software on its hands. Since our perception is that Microsoft has shown a distinct lack of support for its older products, we need to figure out what to migrate to next. If we migrate to ASP.NET from Classic ASP, It feels like that'd be a 'complete rewrite' "migration". Since that is probably th...

Exception to the Law of Leaky Abstractions

I've had an argument with a friendly coder who was mildly damaged by Joel's Law of Leaky Abstractions. It is very hard to convince him of using any new framework/toolbox at all. I'm trying to present a point where "abstractions are fine as long as they allow low-level access to abstracted level". Examples: GWT - Google's superb Java-t...

Good intro to TCP socket programming in Java?

I'm looking for a good tutorial on tcp socket programming in Java. The emphasis is on Good here, often I find that when I lookup this kind of guide I get halfway through before realising that either the person who has written the guide doesn't know what they are talking about or can't express what they know in a way that is condusive to...

Java: Swing --> Maximize window

I'm putting together a quick and dirty animation using swing (hehehe). I would like the window to be maximized. How can I do that? Thanks in advance :) ...

How do you get resin to serve index.html by default if you navigate to a directory? (equivalent of DirectoryIndex in Apache)

Is it possible to configure Resin to serve static files such that navigating to e.g. http://localhost:8888/foo/bar/ will serve the file foo/bar/index.html (without performing a redirect)? I can't find the answer in the Resin docs, though I might be looking in the wrong place. The equivalent in Apache would be the DirectoryIndex directiv...

Why does Eclipse use a native launcher ?

Eclipse the IDE is one of the best examples of a huge desktop application written in Java. Most Java applications I've seen usually rely on a batch or shell script to build a string with the class path of the application, and launch the JVM with the class path as an env variable. Eclipse, on the other hand, relies on a native launcher....

How do you define a class of constants in Java?

Suppose you need to define a class which all it does is hold constants. public static final String SOME_CONST = "SOME_VALUE"; What is the preferred way of doing this? Interface Abstract Class Final Class Which one should I use and why? Clarifications to some answers: Enums - I'm not going to use enums, I am not enumerating anyt...

Java Struts: preselect value in s:select?

Hi guys, I have this struts tag: <s:select name="country.id" list="countries" listValue="name" listKey="id" headerValue="Select Country" headerKey="" label="Country" /> which outputs the following html code: <select name="country.id" tabindex="12" id="registration_country"> <option value="">Select Country</option> <optio...

Forwarding incoming TCP "Commands" to a function?

In Java, how would you set up a socket listener that listened to a socket for a series of bytes that represented a command and on recieving called a method which parsed the incoming data and invoked the appropriate command? Clarification: My issue is not with handling the commands (Which might also be error codes or responses to comman...

Java library for free-text diff

I need to match up two almost-the-same long freetext strings; i.e., to find index-to-index correspondences wherever possible. Because this is freetext, the comparison should not be line-based as in code diffing. Any suggestions for Java libraries? A simple example (In real life , of course, there would not be extra whitespace to lin...

Does Java have buffer overflows?

Does Java have buffer overflows? If yes can you give me scenarios? ...

How to quickly find added / removed files?

I am writing a little program that creates an index of all files on my directories. It basically iterates over each file on the disk and stores it into a searchable database, much like Unix's locate. The problem is, that index generation is quite slow since I have about a million files. Once I have generated an index, is there a quick w...

Problem trimming Japanese string in java.

I have the following string (japanese) " ユーザー名" , the first character is "like" whitespace but its number in unicode is 12288, so if I do " ユーザー名".trim() I get the same string (trim doesn't work). If i do trim in c++ it works ok. Does anyone know how to solve this issue in java? Is there a special trim method for unicode? ...

Porting from PHP to Java - framework recommendations?

Im porting a project from php to java. The project is a web-app based on php and ajax techniques with a javascript front-end. What java-frameworks would you use for something like this? ...