java

Remove Swing Component Using Validate or Revalidate

Whenever I remove and add swing components from say JPanel, shall I perform call on validate or revalidate? ...

Why String.indexOf do not use exception but return -1 when substring not found?

Why String.indexOf do not use exception but return -1 when substring not found? The purpose of this question is: when we start custom exception. I believe avoid the need to return special error code is right design path. What's your opinion? ...

Whats the best way to recursively reverse a string in Java?

Hi, I have been messing around with recursion today. Often a programming technique that is not used enough. So.. I set myself the task to recursively reverse a string, heres what I came up with : //A method to reverse a string using recursion public String reverseString(String s){ char c = s.charAt(s.length()-1); if...

Java Enums and Switch Statements - the default case?

For people suggesting throwing an exception: Throwing an exception doesn't give me a compile-time error, it gives me a runtime error. I know I can throw an exception, I'd rather die during compilation than during runtime. First-off, I am using eclipse 3.4. I have a data model that has a mode property that is an Enum. enum Mode {on(......

Java : Is there a tool to make code (in a 3rd party JAR) forward compatible (1.4 - 1.6)

Hi I have a 3rd party JAR file that is compiled using Java 1.4. Is there a tool that can make the jar file compatible with Java 1.6? (Something like 'retrotranslator' but what does the reverse of it). I tried decompiling the class files and re compile them in 1.6 but it fails. Here is the issue: My project uses 'rsadapter.jar' for wa...

How to get the memory address of the Java heap?

How can I determine the address in memory of the Java heap for a JVM running in the current process? That is, get a void* pointer or equivalent to the contiguous area of memory that the JVM has allocated for the heap, using Java, C, or other calls? Matlab has a JVM embedded in its process. The memory the JVM allocates is unavailable for...

java servlets : duplicate key row in object with unique index 'XAK1timItem'

I've written this java servlet which inserts items into a table however it fails. I think it might be due to my insertion and deleting which got me in trouble some how. The java servlet runs an insert statement into sql server. In my error log, it says: com.microsoft.sqlserver.jdbc.sqlserverexception: cannot insert duplicate key row ...

A Fast Way to Determine Whether A Componet is Found In JPanel

May I know how can I determine whether a component is found in JPanel? boolean isThisComponentFoundInJPanel(Component c) { Component[] components = jPanel.getComponents(); for (Component component : components) { if (c== component) { return true; } } return false; } Using loop is not efficient...

Respond to local http request in Android

I have an application the requests a media stream from a server, however the request needs to include a cookie or else the server returns a 500 error. MediaPlayer does not have the functionality to send a cookie along with a URI request. My way around this is to have Android proxy the requests. I'll have the MediaPlayer make a request t...

What's the best way to store app settings? (MVC)

Hi I'm developing a swing app which suits the MVC pattern and I'm wondering about the best place to store settings such as width/height, xml files location... Should those settings be avaiable also only through the Model? Should I use a global static class? A singleton? Thanks in advance ...

Federal Government Coding Style Guide

Does the US Federal Government have a coding style guide for C# and or Java? If there isn't, I think there should be given the amount of time they put into the Federal Enterprise Architecture and Document Standards. ...

Where's javax.servlet?

I have jdk1.6.0_13 installed, but when I try to find a javax.servlet package, or press ctrl+space in Eclipse after Servlet I cannot get anything. Where can I download this package, and why isn't it included in standard distribution for developers? ...

How to get request parameter to an array in Java, in the style of PHP and Rails?

The situation is as follows: page.jsp?var[0]=foo&var[1]=bar How can this be retrieved in an array in Java? The following: page.jsp?var=foo&var=bar I know can be retrieved using request.getParameterValues("var") Any solutions for the above though? ...

Java problem: Need a sorted JList to represent a database table

I've found a sample for a sorted JList, but my application is powered by an embedded H2 database so I'm wondering if there isn't a better way to implement this with that in mind. Especially considering the table in question could become enormously large, and duplicating all that data in a JList's list model seems to kinda defeat the poi...

Java Open Source Course Management System

I'm looking for an Open Source Project for delivering a course trainings and to manage courses, instructors. I need something similar to Moodle but in Java. Thanks ...

Access restriction on class due to restriction on required library rt.jar?

I'm attempting to compile Java 1.4 code that was created by IBM's WSDL2Java on Java5 without recreating the stubs and saw this error in Eclipse. I'm under the assumption that the stubs created should just compile as long as the runtime jars are available (they are). Access restriction: The type QName is not accessible due to restriction...

First time a Java loop is run SLOW, why? [Sun HotSpot 1.5, sparc]

In benchmarking some Java code on a Solaris SPARC box, I noticed that the first time I call the benchmarked function it runs EXTREMELY slowly (10x difference): First | 1 | 25295.979 ms Second | 1 | 2256.990 ms Third | 1 | 2250.575 ms Why is this? I suspect the JIT compiler, is there any wa...

write HTTP Proxy in Java

How would I go about creating an HTTP Proxy in Java for use recording and playing back HTTP Sessions? This would be for entirely legitimate performance monitoring purposes. Are there any classes in the standard JDK or does anyone know of any examples that are available? Thanks. ...

How would I run a java process as a Windows Server 2003 service?

I'm looking for the best way to run a java app as a Windows Server 2003 service. What are my options, and what's the basic general process for going about doing this? Thanks much. ...

Stack overflows from deep recursion in Java?

After some experience with functional languages, I'm starting to use recursion more in Java - But the language seems to have a relatively shallow call stack of about 1000. Is there a way to make the call stack bigger? Like can I make functions that are millions of calls deep, like in Erlang? I'm noticing this more and more when I do Pr...