java

Formatting strings in java

I am reading the serial buffer with readLine() method. The string returned by readLine() is in the format "str1 : str2". In a while loop when I use readLine() number of times for a response of serial port command I get weird output like this : String1 : string1 SString11 : String2 StringString2 : String23 String4 : String5 But I need...

Why does it throw an IndexOutOfBoundsException?

Hi, I have a frame that has a table and an exit button. I want to add some data to my table, but this doesn't work correctly: when I open my frame at first, the data is OK, e.g., "Nima,Rahmani,...", then I click the exit button and open my frame again, the table now has "Nima,Rahmani,..." two times, and when I click exit button now, a...

Print service on java web application

Hi, I have an Enterprise Java web application that all of the business is migrated from client-server application. So I need to adapt all requirement including printing on every client (Using Dot Matrix / Plain text). Printing requirement for client on separated client is they must get the report right away after the process is finished...

Cannot get hostname from getHostName

Hi experts I am trying to get hostname/computer name using this method. Unfortunately i only can get localhost but not other computer. private String getHostName(String _strIP) { try { InetAddress inetAddress = InetAddress.getByName(_strIP); System.out.println("getHostAddress : " + inetAddress.getHostAddress()); ...

spring dependency injection in any java bean

I have application that look like below without spring (prior) UI-> service --> javabean p.s: my ui call service (not using DI) and i want to remain this way new service() I want my javabean to do DI for certain bean from applicationcontext.xml file. Should i use Applicationcontext.getBean(the ..xml) file in javabean or is th...

How do you embed XHTML into APT file when using Maven to generate a site?

I am using maven to generate a website for a Java project, which uses APT "Almost Plain Text" as a wiki like markup. Maven takes this and turns it into XHTML. I already have a custom template/skin that I am using for the site, but the index page will have a couple of extra custom design elements that are beyond the capabilities of APT. ...

Difficulties with Iterator and Generics in Binary Search Tree Implementation

Hey everyone! I am studying Data Structures in java and I am having difficulty with using generics in Binary Search Trees. For our assignment we are to implement a Binary Search Tree using nodes that contain a parent, left and right node as well as a data value. The data value in our case takes the form of a Pair object. This is what i...

Java: Roller program - debug - variables not updating from JTextField and NumberFormatException thrown regardless of valid information.

Problems: I am unable to get the values of the JTextFields or the rollResultTotal to update. Even if the data in the JTextFields are valid, a NumberFormatException is still thrown. Questions: Why don't the variables stay? Is this due to declaration in the class itself? Is it possible to update a JLabel panel to show an updated resu...

Is there a standard in java to use _ [underscore] in front of variable or class name

I have seen some of our colleagues using _ [underscore] in front of class names [entities in JPA], and few more people using it for local variables. Is there a standard[or atleast best practice] in java to use _ [underscore] in front of instance[private] instance variable or class name???? I have looked at the following link in SO [Sta...

Cachesecond in Spring module

I am currently new to web programming and is trying out to learn spring framework. I have basic understanding on Servlets and JSP. Currently, I am confused on the property cacheSecond on the Spring Controller. Can anybody point me to resource where I could understand below concepts? I made some reading on browser caching but I am not...

SAP JCo connector loaded forever in GlassFish v2.1 (can't unload)

Hi mates! I've a problem with GlassFish and SAP JCo connector (sapjco3.jar) I load it at start up of an J2EE application (jwm.ear) and initialize it wrapped in a singleton the first time a connection to SAP is needed. The problem is that this jar remains always initialized in memory, I need to restart glassfish to unload the initializ...

How can I prevent a java 1.4 project from using 1.5/1.6 specific API?

Is there any way to restrict a java project configured with 1.4 compiler compliance level from using 1.5/1.6 specific API where the system is playing with 1.6 JRE? Setting only 1.4 compiler compliance level on my project does not warn me from using especially 1.5/1.6 specific java.lang.String methods. ...

Get number of free connections in connection pool

In my project Spring manages connection pool with org.apache.commons.dbcp.BasicDataSource class. Is possible to get how many connections are free or used in current time? Thanks. ...

Where is the localhost development datastore for gae java sdk/eclipse plugin?

I am testing my gae java jdo routines in eclipse. The actual question is, how to clear/clean out the localhost development datastore so that I could start with a virgin datastore for a new cycle of tests? Addional info - For those who don't know: GAE = google app engine, google's "hosting solution" for java and python applications. ...

JAX-RS, Map<String,String> to JSON without the overhead?

Hi! I'm using JAX-RS to create restful webservices in Java. I am getting to much overhead in the produced JSON. Data class: @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class Test { private Map<String,String> data; Test() {} public Test(Map<String,String> data) { this.data = data; } publ...

Classpath resource within jar

Hi, I have a project A, which contains some java files and a classpath resource R.txt. Within the project I use ClassLoader.getSystemResource("R.txt"); to retrieve R.txt. Then I have a project B which includes project A's jar-file. Now getSystemResource("R.txt") wont find the textfile (and yes, it's still in the root of the jar file)...

Encrypting zip files with a password based on Zip 2.0 encryption

Hi, I am trying to zip and encrypt files in Java (1.6) with a password based on the earlier Zip 2.0 encryption. I have used AES 256 bit encrytpion to encrypt zip files with password and have successfully been able to do so. Though AES is a stronger and a more secure encryption standard, i need to find a standard that is more widely s...

generating Variations without repetitions / Permutations in java

I have to generate all variations without repetitions made of digits 0 - 9. Length of them could be from 1 to 10. I really don't know how to solve it, especially how to avoid repetitions. Example: length of variations: 4 random variations: 9856, 8753, 1243, 1234 etc. (but not 9985 - contains repetition) I would be really gratefu...

What are the static tool analysis options (apart from CAST) via plug-ins for Java code with framework?

Need to know about static tool analysis options via Eclipse plug-ins for Java code with framework especially for Struts, Spring and Hibernate. The purpose is primarily analysis (and not Quality metrics) of references (similar to References option in Eclipse). The task to accomplis is impact analysis for applications with a lot of framewo...

How can I create a "Drop-Down" menu in a Java Swing toolbar?

I've created a drop-down menu on my Swing JToolBar. But it doesn't create behave the way I want. I'm aiming for it to work like Firefox's "Smart Bookmarks" button. It disappears when the user selects a menu item: CORRECT! It disappears when the user presses ESC: CORRECT! It disappears when the user clicks somewhere in the main frame o...