java

Calculate distance in meters when you know longitude and latitude in java

Duplicate: Working with latitude/longitude values in Java How do I calculate distance between two latitude longitude points? I need to calculate the distance between two points given by two coordinates. The project I am working on is a Java-project, so Java-code will be great, but pseudo-code can also be given, then I can implement i...

java servlets : passing url variable values with spaces

I'm building a simple java Servlet which passes categories using a URL variable into another Servlet. For example, in the following code ResultSet rs = qw.DBquery("select distinct manufacturer from Products order by manufacturer asc"); try { while (rs.next()) { table+= "<tr><td><a href=\"getItems?manufacturer=" ...

Is there an elegant way to deal with the Ace in Blackjack?

My kiddo had a homework assignment to write Blackjack in Java. I helped him a little but for the most part he did it all himself and it actually plays pretty well. He even caught an error I didn't see in how it was calculating hand values. However, there is a snag that he hasn't dealt with and every solution I can think of is really comp...

Determine when to close a sound-playing thread in Java

I am playing of a sound-file in Java, and is looking for a simple way to determine when the sound-file has finished playing so I can kill the thread. Is there a simple way to accomplish this? ...

Shortest-code for prime-calculation

The newspaper for the Computer Science-line at my school (called readme, is's norwegian, page 19) had a fun competition: Write the shortest possible Java-code for this problem: Take in an integer (as a string in the first entry of a string array, since the Java main method only takes a string array) as an argument, and write out fir...

setting a prototype value (for auto-width calculation) of a JTable column

either this doesn't exist, or I'm not thinking/searching correctly because it's late... I want to set a JTable column width in Swing based on a prototype value for the largest string I expect (or know) to exist in a particular column. I don't know the # of pixels since I don't necessarily know the font at compile time. Is there a way t...

Printing from servlet, why does this not work

I want to print from a servlet. I believe I have the correct syntax. But I get the message "delete these tokens" in Eclipse. PrintWriter out = response.getWriter(); out.println("<html><head><title>Woohoo</title></head><body>\n" + "<form id="report_form" name="report_form" method="post" action="AgReportServlet">\n"+ "<table bo...

Learning about Try-Catch blocks

I'm a Java beginner so please bear with me :P static int load = 100; static int greet; public void loadDeduct(int cLoad, int c){ int balance; balance = cLoad - 7; System.out.println("Your balance: " + balance); } public void loadDeduct(int tLoad){ int balance; balance = tLoad - 1; System.out.println("Your balan...

how to check if a char is passed as an int

Is it possible to check if a char has been passed into a method that requires an int? For example, if you have some function foo(int bar) and someone uses that function like foo('t'), are you able to find out that a char was inputted and not an int? I know that the char is converted into an int but I am trying to limit anything other tha...

array of stacks

Is it possible to create an array of stacks without having to cast the stacks as they come out? Eclipse gives me a warning about not being able to make a generic array of Stack when I do something like this: Stack<Card>[] cards = new Stack<Card>[52]; ...

Java Exception vs C++ Exceptions

Where are exceptions stored ? Stack, Heap. How is memory allocated and deallocated for Exceptions? Now if you have more than one exception which needs to be handled are there objects of all these exceptions created? ...

Visualizing Java project

I have been tasked with porting a large Java codebase to the Android platform. The project makes extensive use of AWT which isn't' supported on Android. I'm looking for a tool that lets me visualize all of the classes in the project. I'd like to be able to see all of the relationships between classes so that I can get a good idea of w...

What is a Connection in JDBC ?

What is a Connection Object in JDBC ? How is this Connection maintained(I mean is it a Network connection) ? Are they TCP/IP Connections ? Why is it a costly operation to create a Connection every time ? Why do these connections become stale after sometime and I need to refresh the Pool ? Why can't I use one connection to execute multipl...

Use cases for Identity HashMap

Could anyone please tell important use cases of Identity HashMap? ...

How to read 'List separator' from OS in Java?

I am writing a CSV exporter in Java that should respect the user's custom settings, especially the "List separator" to use as a delimiter. In Windows, one can set this List separator in Control Panel -> Regional and Language Options -> Regional Options -> Customize I don't know about the other operating systems, but I'm pretty sure t...

way to initialize a javabean to random values

I was looking for some utility class/code that would take a java bean and initialize all its values to random values. It could be done via reflection as some libraries already create the toString() or equals() methods. Is is useful while developing the UI to have some data for example. Other possible nice to haves: recursively initia...

How to get system user in ant (within eclipse)?

How can I access the name of the system user (which eclipse also uses for the javadoc author tag) in my ant build file? I'm trying to show some information about the current program version in my java application. I decided to use jreleaseinfo which passes variables from my ant build script to my java classes (to show them in a window)...

[Eclipse Ganymede] Converting a Java Project to a Dynamic Web Project

Hey, I'm using Eclipse Ganymede to create a web application, but the project's currently just a standard Java project. I want to convert it to a Dynamic Web Project and I need a hand in doing that. I've had suggestions given to me about editing the .project file, but when I restart Eclipse it refuses to open the project claiming the fi...

Simple yet reoccurring naming problem

Let's say we have a method: public String wishes(Date birthday) { String birthayDateString = convertToString(birthay); ... } I wonder what's the best name to give to the string called now "birthayDateString". This string represents date converted to text. I can't name it "birthay" beause this name is alredy used. Do...

Restrictions/disadvantages of developing portlets for Liferay

I'm considering developing an application as portlets, to be integrated in Liferay portal. Are there any significant disadvantages or restrictions in developing such an application, as opposed to developing a normal web application using Spring framework? Liferay seems to require that all content is added as portlets. Another option I p...