TagJava

How To Generate XSD from XML / Convert XML to XSD

H

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. Oh, and they are free! Generate XSD from XML Tool The first is Trang. You can get it here from the...

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

F

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: And here’s the actual code that does the magic: double price = 10.59; DecimalFormat...

Running UNIX commands in your Java application

R

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 = Runtime.getRuntime();
runtime.exec(“ls | wc >out1”);
}

Replace/remove character in a String

R

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 String removeChar(String s, char c) { String r = "";...

About Author

I've over 17 years of entrepreneurship experience, having built a tech company to be the top in the country, which was subsequently acquired for an 8-figure sum. As CEO, I led the company through robust growth to 150 employees across 4 countries. After the acquisition, I embraced minimalism, sold off my personal possessions, and started living around the world.

Read more about my story here.