java

Remove end of line characters from Java string

I have string like this "hello java book" I want remove \r and \n from string(hello\r\njava\r\nbook). I want string as "hellojavabook". How can i do this? ...

Swing GUI : Scrolling not updated when a JTable gets bigger

Hi, I got a Java Swing GUI and got a problem with a JTable in a JScrollPane. For some reason, when the rows of the table model are increased during the program execution, the JScrollPane isn't updated - that is, if the rows are increased so that the height of the table is over the height of the scroll view, the scroll panes aren't updat...

Share application specific data types with server and client

Hi all, I have to create a server(java) - client(c++) system, both server and client will have to work with objects (data types) wich are the same for the client and for the server, for example a car object will be created on the client side and then send to the server where aditional calculations will be done on the car object. What i ...

Display BMP in JLabel

Java can display png, jpg a some other picture formats, but i have to display a bmp file in a JLable by getting the file path. ImageIcon imageIcon = new ImageIcon(imageFile.getAbsolutePath()); ImageIcon support the typical png,gif,jpg images. In the project i am working, i can not open a bmp file and store the same file as a jpg, bec...

JibX: how to map a class and avoid it being outputed as XML node

I am using JibX as a Java Object to XML Binding tool. With it, I want to have the following output: <?xml version="1.0" encoding="UTF-8"?> <FEAPService> <Request> <Function>aaa</Function> <SubFunction>bbb</SubFunction> <Operation>ccc</Operation> </Request> </FEAPService> But I'm getting this: <?xml version="1....

How to suppress Java compiler warnings for specific functions

We are always taught to make sure we use a break in switch statements to avoid fall-through. The Java compiler warns about these situations to help us not make trivial (but drastic) errors. I have, however, used case fall-through as a feature (we don't have to get into it here, but it provides a very elegant solution). However the co...

Best Practice For Creating Stub Files With Ant

Hi all, I'm trying to create myself a little build script to build a project for me - creating the desired directories, downloading any needed jars via Ivy/Maven and creating some stub files. The stub files part is what I'm not too sure on what to do. To take an example, I would want the build script to create a web.xml in a WEB-INF f...

How do I put a StockSeries in front of a BarSeries on a combination chart in BIRT?

Hi all, Consider the below source code where I create a combination chart with a BarSeries and a StockSeries. The StockSeries generates three identical Candle-stick Stock figures with a box from values 12 to 14 and low and high values 10 and 16. The BarSeries generate three bar figures with heights 11, 13 and 15. public class StockBar...

How to instantiate an empty element with JAXB

I use JAXB to create XML messages. The XML I need to create is (for the sake of simplicity): <request> <header/> </request> My code looks like this: import javax.xml.bind.annotation.*; @XmlRootElement(name = "request") public class Request { private String header; @XmlElement(required=true) public String getHeader() ...

Hibernate Annotations - Which is better, field or property access?

This question is somewhat related to http://stackoverflow.com/questions/305880/hibernate-annotation-placement-question. But I want to know which is better? Access via properties or access via fields? What are the advantages and disadvantages of each? ...

String equality vs equality of location

String s1 = "BloodParrot is the man"; String s2 = "BloodParrot is the man"; String s3 = new String("BloodParrot is the man"); System.out.println(s1.equals(s2)); System.out.println(s1 == s2); System.out.println(s1 == s3); System.out.println(s1.equals(s3)); // output true true false true Why don't all the strings have the same ...

ADO.net principles in java

I'm asking on opinion about implementing framework that emulates ado.net in java (data tables, data sets etc). Idea is to avoid writing domain objects since they are, so far, just used to transport data from server to client and back, with no particular business methods inside them. Main goal is to speed up development time. Could i bene...

What standard optimization refactoring can I do to my Java application?

I have a semi big Java application. It's written quite poorly and I suspect there are quite a lot of simple things I can do that will clean things up a bit and improve performance. For example I recently found the String.matches(regex) function used quite a lot in loops with the same regex. So I've replaced that with precompiled Patt...

Practical side of the ability to define a class within an interface in Java?

What would be the practical side of the ability to define a class within an interface in Java: interface IFoo { class Bar { void foobar () { System.out.println("foobaring..."); } } } ...

Webslinger Help

I came across Webslinger project and it seemed interesting. But it lacks any kind of documentation or reference. If anybody worked on it ever could help me to start. ...

How can I implement my security policy in java program itself.

I am really new in java-RMI and developed a small application on it.But to run my server and client I need to execute- Java -Djava.security.policy=client.policy So what should I do to ommite '-Djava.security.policy=client.policy' this command? Or is there any way to implement the security policy in java program? Thanks in advance. ...

How to make JTextField expand with a BorderLayout (Java)

I have a Java program, in which, I'm using a JTextField, but if i don't specify a default size, it'll have the width 0. I'm inserting it in a BorderLayout, so how do I make it expand to fill the whole container? ...

Configuring IntelliJ IDEA to create main class for new projects

A friend is just starting to learn Java, using IntelliJ. He asks how can he set up some template so creating a new project will contain a default main class. Currently, when he creates a new project, it has no source files, and he has to add a Run/Debug application configuration manually, and then select the main class. ...

protected/public Inner Classes

Can someone please explain to me what is the difference between protected / public Inner classes? I know that public inner classes are to avoid as much as possible (like explained in this article). But from what I can tell, there is no difference between using protected or public modifiers. Take a look at this example: public class F...

Loading .properties files in JRun4

Hello, I'm using the echo2 web framework in my application. But trying to start it in JRun4 returns the following exception: 26/02 17:12:21 user Remote: init 26/02 17:12:22 error [1]java.lang.NullPointerException at nextapp.echo2.app.util.PropertiesDiscovery.loadProperties(PropertiesDiscovery.java:67) at nextapp.echo2.app.util....