java

Efficiency of Java "Double Brace Initialization"?

In Hidden Features of Java the top answer mentions Double Brace Initialization, with a very enticing syntax: Set<String> flavors = new HashSet<String>() {{ add("vanilla"); add("strawberry"); add("chocolate"); add("butter pecan"); }}; This idiom creates an anonymous inner class with just an instance initializer in it, w...

Maven doesn't resolve hibernate-c3p0's dependency on slf4j

When I include hibernate-c3p0 in my Maven's pom.xml file, I get a runtime NoClassDefFoundError as it can't find org.slf4j.impl.StaticLoggerBinder. It was my impression that Maven would resolve this dependency – so if c3p0 requires slf4j, then slf4j would be downloaded and included. My pom.xml file has: <dependency> <groupId>org.hiber...

Google Spreadsheet API - find the first empty cell in a column?

Is there a good way to get the first empty cell in a column from Google's spreadsheet service via Java? I know I can use: public CellFeed CheckColumn(int row, int col) throws IOException, ServiceException { CellQuery query = new CellQuery(cellFeedUrl); query.setMinimumRow(row); query.setMaximumRow(row); query.setMi...

How to get file name without the extension?

Can anyone tell me how to get file name without the extension? Example: fileNameWithExt = test.xml; fileNameWithOutExt = test; ...

JSTL access a map value by key

I have a Map keyed by Integer. Using JSTL, how can I access a value by its key? Map<Integer, String> map = new HashMap<Integer, String>(); map.put(1, "One"); map.put(2, "Two"); map.put(3, "Three"); I thought this would work but it doesn't (where map is already in the request's attributes): <c:out value="${map[1]}"/> Follow up: I tr...

how to repackage eclipse for my team

Hi all, I'd like to set up eclipse with a bunch of plugins and DB connection configurations, etc and re-zip it up so my team-mates and new starters can all be working on the same platform easily. It seems that installing plugins is fine, but when I add in custom jars (e.g. ivy2, ojdbc, etc) they all save with full, absolute paths whic...

Am I correctly interning my Strings ?

I want to make sure I don't pummel the permgen space, so I'm carefully interning my strings. Are these two statements equivalent ? String s1 = ( "hello" + "world" ).intern(); String s2 = "hello".intern() + "world".intern(); UPDATE How I framed my question was totally different from the actual application. Here's the method where I...

how to fill series color for a chart called from a subreport in java with jasper report

i am trying to change the series color for a chart which is called from a subreport in java with Jasper Report JRChartPlot pl; JRFillObjectFactory fac; JRFillChartPlot plot = new JRFillChartPlot(pl, fac); how to intanciate JRChartPLot to my JRFillChartPlot constructor, The previous code gives me null pointer exception ...

Changing the Compression mechanism in Installshield?

I am working on a Java Installer project that user InstallShield. (Java panels) The installer package is created automatically while building the installer. The final installer contains of a setup.exe file and a setup.jar. All my 3rd party jar files are packaged within the setup.jar (It is the general way the installshield follows) But...

reading single charecter from serialport java

Hi,i'm reading data from serialport,problem is i'm not getting complete data what written by other side,data is breaking and it comes for next event,so if read single charecter from port for second event is data is appended to pevoius data inside inputstream? wat the process javax.comm do plz give the information. Thank u in adavance ...

Axis webservice with type="xsd:base64Binary"

So i have a wsdl that defines a message part like the following <wsdl:message name="processEnvelopeResponse"> <wsdl:part name="processEnvelopeReturn" type="xsd:base64Binary"/> </wsdl:message> This maps to a xsd, wich then imports other xsds and so on. I have the following questions: How can i generate the Message part objects fro...

How do I use a Maven 2 repository protected using SSL and a wildcard/self-signed certificate?

I am trying to use a Maven 2 repository via SSL secured with a self-signed certificate. I followed the instructions at HTTPS and Self-Signed Certificates in Java but I doesn't to work. I think its because the certificate is a wild-card certificate. So I wonder if I should be doing something different to import the wild-card certificate?...

How do I add an Implementation-Version value to a jar manifest using Maven's assembly plugin?

I'd like to add an Implementation-Version line to a manifest in my jar file that reflects the POM version number, using the maven assembly plugin. Note that this is similar but different to another of my recent questions about the jar plugin. ...

JDBC Batch Update Problem

Hi, I have a slightly unique requirement with the Java-JDBC API along with Oracle Database. I have autoCommit to be default which is true for Oracle and I am using the example similar to this link. However, when I add say 1000 batches and lets say each of them are inserts. And Let us assume that about 20 records violated some constraint...

How to Cache InputStream for Multiple Use

I have an InputStream of a file and i use apache poi components to read from it like this: POIFSFileSystem fileSystem = new POIFSFileSystem(inputStream); The problem is that i need to use the same stream multiple times and the POIFSFileSystem closes the stream after use. What is the best way to cache the data from the input stream an...

Incorrect / missing font metrics in Java?

Using a certain font, I use Java's FontLayout to determine its ascent, descent, and leading. (see Java's FontLayout tutorial here) In my specific case I'm using Arial Unicode MS, font size 8. Using the following code: Font font = new Font("Arial Unicode MS", 0, 8); TextLayout layout = new TextLayout("Pp", font, ...

how to reference XSD Schema location while parsing XML Doc via SAX Xerces?

how to reference XSD Schema location while parsing XML via SAX Xerces? < ?xml version="1.0" encoding="ISO-8859-1"?> < com.firma xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > < !-- xsi:noNamespaceSchemaLocation="F:\...\myschema_v2.5.xsd" Must I reference this element really within the XML Doc??? I hope, not... ...

Java NTP client

I need my software to communicate with an NTP server to determine the local clock offset. I have tried using the org.apache.commons.net.ntp package, but its implementation is rather poor when running on Windows, because of the use of System.currentTimeMillis() to determine the time before and after the NTP packet exchange. As you may or ...

Why does Java BigDecimal return 1E+1?

Why does this code sometimes return 1E+1 whilst for other inputs (e.g. 17) the output is not printed in scientific notation? BigDecimal bigDecimal = BigDecimal.valueOf(doubleValue).multiply(BigDecimal.valueOf(100d)).stripTrailingZeros(); System.out.println("value: " + bigDecimal); ...

How can I see a page error in jMeter?

How can I see a Error in jMeter? In other words if a test fail how is possible to see the page returned with error ? Regards ...