java

Stuck on testing a method

I am doing some table testing in word, all of the JUnits are done but i am having trouble testing a method - as i am the tester in this project and not the coder i am struggling to understand what is actually correct or not public GregorianCalendar calcDeparture(String date, String time) { String[] calDate = new String[3]; ...

Avoid repeated imports in Java: Inherit imports?

Is there a way to "inherit" imports? Example: Common enum: public enum Constant{ ONE, TWO, THREE } Base class using this enum: public class Base { protected void register(Constant c, String t) { ... } } Sub class needing an import to use the enum constants convenient (without enum name): import static Constant.*; /...

How to sanitize log messages in Log4j to save them in database

Hello, I'm trying to save log messages to a central database. In order to do this, I configured the following Appender in log4j's xml configuration: <appender name="DB" class="org.apache.log4j.jdbc.JDBCAppender"> <param name="URL" value="jdbc:postgresql://localhost/logging_test" /> <param name="user" value="test...

Java Swing: Extend DefaultComboBoxModel and override methods

I am using the DefaultComboBoxModel to display a list of customers in a ComboBox. The list currently displays their name only. I would also like to have a reference to each customer within the DefaultComboBoxModel so that when a name is selected, it also holds the reference to the real customer object. To achieve this, I suspect I have ...

What is the equivalent JVM in C#?

The JVM is required to run a java application. I wanted to know is there any equivalent in c#? If yes what is it? ...

How can we handle the ConnectException?

Hi, I have searched a lot ,but i couldn't find the fine answer for it.I use try_catch block for this exception(if this exception is thrown one frame will be shown to the user that I will tell him/her a message) but it still show the exception in the console.please help me.Thanks. submit() method which will throw this exception: priva...

Embedded Jetty and SOAP

I am trying to run an embedded Jetty and would like to expose a soap webservice. The project is loaded as a WAR generated by netbeans. The webservice is generated from a WSDL. What is the simplest way to add SOAP support to embedded Jetty ...

Extending simple ANTLR grammer to support input variables

I'm still on my quest for a really simple language and I know now that there are none. So I'm writing one myself using ANTLR3. I found a really great example in this answer: Exp.g: grammar Exp; eval returns [double value] : exp=additionExp {$value = $exp.value;} ; additionExp returns [double value] : m1=multiplyE...

Except classes and interfaces is there anything else we can write in a java source file?

Except classes and interfaces is there anything else we can write in a java source file? because what ever .java file i have seen will have either class or interface in it. ...

wsdl2Java fails from Headless Ant

We are working in RAD (7.0.0.x) for development to Websphere 6.1. In our ant script we have the following: <!-- *************************************************** --> <!-- ** Generate WebService Client classes --> <!-- *************************************************** --> <target name="-generate-classes" if="ejbmod...

Java: Load the same dynamic library in two threads (both threads in the same JVM)

Hello, I am using a library (written in C) that is not reentrant(i.e no function in the library is reentrant). Suppose I have loaded the library via System.load to get the handle say 'v'. I cannot use v in two threads because of the reentrancy issues (tried but nonsense results). I could use locks, but that defeats any parallelism i coul...

How can a static method return a different implementation class?

I am writing a unit test by mocking out external services com.example.Service service; service = RealServiceClient.getService().getServiceId("1"); How can I simulate the above RealService class? The thing is RealServiceClient.getService() returns RealService. PS: I am new to Java. ...

Java heap size in JMP

I'm trying to profile a simple application in java, which basically only opens an RMI interface and waits for messages. When I open the application via TIJMP, it reports from the start: Heap: init - 0, used - 3MB, commited - 7MB, max - 643MB. Now I'm pretty sure that simply starting the program didn't push the memory requirement over 6...

need clarification, is this considered an inline class or a callback or something else?

Just reading up on spring's data access, and it has something like this: jdbcTemplate.query(someSql, new Object[] { 1 }, new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) ... Blah blah = new Blah(); blah.setId( rs.g...

calling non-static method in static method in Java

Hi, I'm getting an error when I try to call a non-static method in a static class. "Cannot make a static reference to the non-static method methodName() from the type playback" I can't make the method static as this gives me an error too. "This static method cannot hide the instance method from xInterface" Is there any way to get ro...

Short, Java implementation of a suffix tree and usage?

I'm looking for a short, simple suffix tree building/usage algorithm in Java. The best I've found so far lies withing the Semantic Discovery Toolkit, but the implementation is several thousand lines long and spans several classes. Ideally, the implementation would be as short as possible and span no more than a few hundred lines. Does a...

When you unbox an object, where is the objects datatype stored so the compiler can perform the cast?

Internally speaking, when you cast an object to a strongly typed object like: User u = (User)o; Where is the type of the object stored? is it stored in another location or within the memory block where the actual object is stored? (I don't know much about this topic, so I could very well be asking a question that doesn't make comple...

Java operator to check if either conditions are false, but not both or none

Is there an operator in Java that will give a result of false if either conditions are false, but if both are true or both false the result will be true? I have some code that relies on a user entering some values for a process to run. As the user should only be able to enter x or y but not both or none I would like to show an error mes...

Strange {} Syntax

private final String[] okFileExtensions = new String[] {"csv"}; Would someone please explain why {} is written after a String array decleration? Thanks. ...

JavaMail mail.smtp.ssl.enable is not working

I read on several sites that, when using the JavaMail API, to set the property mail.smtp.ssl.enable to true. I have some code as follows: props.put("mail.smtp.host", "exchangemail1.example.com"); props.put("mail.from", "[email protected]"); props.put("mail.smtp.starttls.enable", "true"); // I tried this by itself and also together wi...