java

Query for system (not JVM) uptime in Java

Is there a OS-neutral method of querying for system (not JVM - I am aware of RuntimeMXBean.getUptime()) uptime in JavaSE 6 ? Thanks ...

JDBC Thin Driver: Invalid Packet Lenght [sic]

I have encountered a strange "Invalid Packet Lenght" (that is how the error is spelled) error when I run an automated bulk test on some of my Java code and I hope that someone has either encountered this error before or can point me in the right direction. I do not encounter this error when testing my code via JUnit unit tests or from...

Scala and interfaces

In Java I would typically declare my entire domain as interfaces, possibly with some kind of Factory to get me implementations. This is partly because I am so old I can remember when some persistence layers required implementation classes to subclass a specific class but also so that I can easily: mock objects for testing purposes prox...

Using excel as UI without VB

I think every business person would like to have excel UI, however they are forced into using web applications that sometimes look like really bad excel. Are there any frameworks that help build excel ui without VB? I dont mean framework like POI or JExcel that allows you to generate excel reports. ...

Making a very large Java array

I'm trying to find a counterexample to the Pólya Conjecture which will be somewhere in the 900 millions. I'm using a very efficient algorithm that doesn't even require any factorization (similar to a Sieve of Eratosthenes, but with even more information. So, a large array of ints is required. The program is efficient and correct, but re...

implementing a "window manager" for HTML in a JSP custom tag

I have a problem: I need to build a custom tag, which can take its child tags (each of which will render as an HTML widget of some sort) and render them into the page in some intelligent manner. It's a fairly open ended question, so I have thought of many different ways to solve it. What I need is some input on how: others have done ...

JUnit tests for POJOs

I work on a project where we have to create unit tests for all of our simple beans (POJOs). Is there any point to creating a unit test for POJOs if all they consist of is getters and setters? Is it a safe assumption to assume POJOs will work about 100% of the time? Duplicate of - Should @Entity Pojos be tested? See also Is it ba...

How do I make my own parser for java/jsf code?

Hi I'd like to make my own 'parser', e.g: computing (4+(3-4^2))*2 or parsing java,jsf,html code. In fact I did something like this but I feel it's not good. Is there anything good for me? I've tried to read more, but I'm bit confused, LL, LR, AST,BNF,javacc yacc etc :). I'm not sure which way to go, when I would like to compute 4+... ...

Scala equivalent of new HashSet(Collection)

What is the equivalent Scala constructor (to create an immutable HashSet) to the Java: new HashSet<T>(c) where c is of type Collection<? extends T>. All I can find in the HashSet Object is apply ...

All keys to a list, for example VK_A..Z for user to select

Hello All, I am making a program that allows user to custom keyboard shortcuts, for this i need the available keys to be displayed, what is the best way to achieve this in java swing? KeyEvent.class.getDeclaredFields() I am intrested in dynamic example of below, keysLST.setModel(new javax.swing.DefaultComboBoxModel(new String[]...

Can I program Java with Flex Builder?

I have no experience with Java, but I want to learn it. I have been using Flex Builder standalone for a few months now, and am familiar with eclipse now. So since Flex Builder is basically eclipse, can I program Java with the same copy or do I need a new installation of eclipse to program Java? Also if anyone can point me to a tutorial t...

Printing distinct integers in an array

I'm trying to write a small program that prints out distinct numbers in an array. For example if a user enters 1,1,3,5,7,4,3 the program will only print out 1,3,5,7,4. I'm getting an error on the else if line in the function checkDuplicate. Here's my code so far: import javax.swing.JOptionPane; public static void main(String...

How to reuse eclipse launch file in a new project

I just checked out an svn project in eclipse as a java project. There is are couple of run launch files in it that i want to reuse but dont know how to point 'Run' to see those launch files or use it. Any tip? thanks ...

Test data directory with jUnit

I'm writing some jUnit tests that depend on data files. Where should those data files go? And how would I (in the jUnit tests) get the location of that directory? In Python, I would use something similar to: datadir = os.dirname(__file__) + "/data/" ...

Converting Java collection into Scala collection

Related to this question, how do convert a Java collection (java.util.List say) into a scala collection List? EDIT; what I am actually trying to do is convert a Java API call to Spring's SimpleJdbcTemplate, which returns a java.util.List<T>, into a scala immutable HashSet. So for example: val l: java.util.List[String] = javaApi.query( ...

How do I get data from a web form?

As a pet project I want to build a program that translate from English to Hebrew. The way I want to make the translation itself is using a web site called morfix. In this site can enter an English word and after pressing the "תרגום" (translate) button the translation is brought. My first choice is to write this program in Java, and I t...

ActionListener problem

I have a problem with my actionListener. It seems that the actionListener runs automatically before I click the button? The "This should not appear in the console before button click" appear in the console before I click the button".... This is strange. .... button1.addActionListener(this); button2.addActionListener(this); .... public...

Java: reconnection on a socket sometimes gives error

I am making a prototype client & server so that I can understand how to handle reconnects. The server ought to create a serversocket and listen forever. A client may connect, send its data, and close its socket but it will not send a "I'm done and closing" type message to the server. For this reason, the server gets a EOFException when...

Setting the JVM via the command line on Windows

Hi, Is it possible to specify the JVM to use when you call "java jar jar_name.jar" . I have two JVM installed on my machine. I can not change JAVA_HOME as it may break code that is all ready running. Kind Regards Stephen ...

Action tag not executes in Struts 2

Hi, I have a problem invoking actions from my jsp pages with tag in struts2. I have the login.jsp file: <s:action name="headerMenu" executeResult="true" namespace="/menu"</s:action> <s:form action="executeLogin"> <s:textfield name="username" label="Username"></s:textfield> <s:password name="password" label="Password"></s:pass...