Tag Archive | "Java"

How To Generate XSD from XML / Convert XML to XSD

Thursday, May 27, 2010

5 Comments

I had to complete a project that involved working with a web service. Problem was, I had the XML files, but needed the XML Schema Definition (XSD) schemas, and coming up with them manually would have been too tedious and would have took too much time. So I went online, and found 2 reliable methods. [...]

Continue reading...

Formatting a Decimal Number to 2 Decimal Places in Java or JSP

Tuesday, October 2, 2007

2 Comments

I was looking around for the class to format a number to 2 decimal places while I was coding Java, or specifically JSP, and I found it. First, you need to import the DecimalFormat class, so have this line at the top of your Java file: import java.text.DecimalFormat; Or if you’re running JSP: <%@page import="java.text.DecimalFormat" [...]

Continue reading...

Running UNIX commands in your Java application

Tuesday, July 3, 2007

0 Comments

I was looking around for a method to run commands from the prompt automatically from within my Java application, and then I found it. Here’s the solution – and it works like a charm! static void doExec1() throws IOException { // use pipes and I/O redirection // but without using a shell Runtime runtime = [...]

Continue reading...

Replace/remove character in a String

Wednesday, April 4, 2007

0 Comments

To replace all occurences of a given character : String.replaceAll("n", ""); // Remove all n String.replaceAll("n", "r"); // Replace n by r To replace a character at a specified position : public static String replaceCharAt(String s, int pos, char c) { return s.substring(0,pos) + c + s.substring(pos+1); } To remove a character : public static [...]

Continue reading...