Skip to main content

Posts

Showing posts from July, 2008

Java: Numbers only String by removing non numeric characters

With Java, deleting non numeric characters (letters, symbols etc) from a string to produce a numbers-only String is a common requirement in web applications, as application users are used to insert numeric values with non-numeric characters.

For example a phone number will be entered with (-) characters like;
650-212-5710.
A price value may be entered with (,) characters like;
12,500.00

In Java, java.lang.Character class has a method; isDigit() which can be used to identify whether a character is a digit or not. Following method can be used for extracting a numbers-only string, by removing all non-digits.
public static String getOnlyNumerics(String str) { if (str == null) { return null; } StringBuffer strBuff = new StringBuffer(); char c; for (int i = 0; i < str.length() ; i++) { c = str.charAt(i); if (Character.isDigit(c)) { strBuff.append(c); } } return strBuff.toString(); } Calling…

How to open a .war (web archive) or .jar (java archive) files

With Java we generate .JAR files to bundle a set of resources. For J2EE web applications, we generate .WAR (Web Archive) files for deployments. Both of these are ways of archiving a set of files.

Both these .jar or .war archives are in zip format. So there are plenty of ways to open those files to read the content. One way would be to use any tool that you use to open/extract a .zip file. Next will be to use the Jar command itself.

JAR Command JAR (command) utility in Java can be used to open/extract these files as follows. Run following command from the folder where you need the content to be extracted by providing the path to the archive.
jar xf <path-to-file> options: x - extract the files f - file to extract
Let's extract myWebApp.war and myProject.jar files. jar xf myWebApp.war jar xf myProject.jar

Web Services with Apache Axis 1.4 Tutorial: server and client sides

Web services are a handy method of integrating independent systems. Apache Axis is one of the best free tools available for implementing and deploying web services, and also for implementing the web service clients. In this article we will create a simple, but complete web service and a client for this service step-by-step. Article will be explanatory as much as possible to succeed you in implementing it yourself alone after completing this tutorial.PrerequisitesMust be familiar with JavaFamiliar with basics on a web server like TomcatSome knowledge in configuring Axis will be an added advantageSystem Configuration Requirements We will be discussing the configuration in brief as our scope is mainly on web services. (If Axis already configured, jump to implementation). If you find any issues on the configuration part, you can refer to Apache Axis site for troubleshooting. (But if you can not solve it yourself do not worry, post the issue under the comments section in this article, and …

Java2WDSL & WSDL2Java - java.util.Date not handled consistently

Java2WSDL and WSDL2Java tools in Axis (1.4) are pretty handy tools. Those help you to generate a WSDL from a java class as well as generating stubs/skeletons from a WSDL. But if you are dealing with java.util.Date fields in your code, you must pay some attention. Java2WSDL Consider the following java interface which uses java.util.Date as a return type as well as a method parameter. public interface MyService { public java.util.Date getNextDate(); public void updateLastRun(java.util.Date date); } When the Java2WDSL tool generates a WSDL for a class with a Date field, it will represent java.util.Date fields as dateTime fields in WSDL. The generated WSDL file would look as follows. <?xml version="1.0" encoding="UTF-8" ?> <wsdl:definitions targetNamespace="http://service" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://service" xmlns:intf="http://service" xmlns…

Java Sorting: Comparator vs Comparable Tutorial

Java Comparators and Comparables? What are they? How do we use them? This is a question we received from one of our readers. This article will discuss the java.util.Comparator and java.lang.Comparable in details with a set of sample codes for further clarifications.
Creative Commons License Digizol by Kamal Mettananda is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 License .
URL of this page must be supplied in attribution
© 2004-2017