javarevisited

javarevisited


Sybase and SQL Server PATINDEX CHARINDEX Example to split String in Stored procedure

Posted: 24 Dec 2012 09:16 PM PST

Some time we need to split a long comma separated String in Stored procedure  e.g. Sybase or SQL Server stored procedures. Its quite common to pass comma delimited or delimiter separated String as input parameter to Stored procedure and than later split comma separated String into multiple values inside stored proc. This is not just case of input parameter but you can also have comma separated string in any table data. Unfortunately there is no split() function in Sybase or SQL Server 2005 or 2008 which can directly split string based on delimiter just like in Java string split method. Fortunately Sybase Adaptive Server and Microsoft SQL server has functions like CHARINDEX and PATINDEX which can be used to split comma separated String. This is next on our SQL tutorials after seeing SQL query to find duplicate records in table and How to find 2nd and Nth maximum salary in SQL.
Read more »

How to get current date, month, year and day of week in Java program

Posted: 24 Dec 2012 06:56 PM PST

Here is quick Java tip to get current date, month, year and day of week from Java program. Java provides a rich Date and Time API though having thread-safety issue but its rich in function and if used locally can give you all the date and time information which you need for your enterprise Java application. In last Java tutorial on Date and Time API we have seen how to get current date and time from different timezone using DateFormat and SimpleDateFormat classes and in this post we will get some more details like current month, year, day of week etc by using java.util.Calendar class.  Just keep in mind that Calendar instance should not be shared between multiple threads. Calendar class in Java provides different fields to get different information e.g. Calendar.DATE gives you current date while Calendar.MONTH gives you current month based on what type of Calendar you are using, which depends upon locale.
Read more »

How to create and modify Properties file form Java program in Text and XML format

Posted: 24 Dec 2012 05:04 AM PST

Though most of the time we create and modify properties file using text editor like notepad, word-pad or edit-plus, It's also possible to create and edit properties file from Java program. Log4j.properties, which is used to configure Log4J based logging in Java and jdbc.properties which is used to specify configuration parameters for database connectivity using JDBC are two most common example of property file in Java. Though I have not found any real situation where I need to create properties file using Java program but it's always good to know about facilities available in Java API. In last Java tutorial on Properties we have seen how to read values from properties file on both text and XML format and in this article we will see how to create properties file on both text and XML format. Java API's java.util.Properties class provides several utility store() methods to store properties in either text or xml format. Store() can be used to store property in text properties file and  storeToXML() method can be used for creating a Java property file in XML format.
Read more »

How to count occurrence of a character in String - Java programming exercise

Posted: 24 Dec 2012 03:26 AM PST

Write a program to count number of occurrence of a character in String is one of common programming interview question not just in Java but also in other programming language like C or C++.  As String in a very popular topic on programming interviews and there are lot of good programming exercise on String like "count number of vowels or consonants in String", "count number of characters in String" , How to reverse String in Java using recursion or without using StringBuffer etc, it becomes extremely important to have solid knowledge of String in Java or any other programming language. In Interview, most of the time Interviewer will ask you to write program without using any API method,  as Java is very rich and it always some kind of nice method to do the job, But it also important to know rich Java and open source libraries for writing production quality code. Anyway in this question we will see both API based and non API based(except few) way of to count number of occurrence of a character in String on Java.
Read more »

How to read input from command line in Java using Scanner

Posted: 24 Dec 2012 12:27 AM PST

Java 5 introduced a nice utility called java.util.Scanner which is capable to read input form command line in Java. Using Scanner is nice and clean way of retrieving user input from console or command line. Scanner can accept InputStream, Reader or simply path of file from where to read input. In order to reading from command line we can pass System.in into Scanner's constructor as source of input. Scanner offers several benefit over classical BufferedReader approach, here are some of benefits of using java.util.Scanner for reading input from command line in Java:
Read more »


Post a Comment