<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">

<channel>
	<title>Quick Programming Tips</title>
	
	<link>http://www.quickprogrammingtips.com</link>
	<description>A collection of programming wisdom!</description>
	<lastBuildDate>Thu, 22 Nov 2012 09:11:48 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/quickprogrammingtips" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="quickprogrammingtips" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Sum of Digits of a Number in Objective-C</title>
		<link>http://www.quickprogrammingtips.com/objective-c/sum-of-digits-of-a-number-in-objective-c.html</link>
		<comments>http://www.quickprogrammingtips.com/objective-c/sum-of-digits-of-a-number-in-objective-c.html#comments</comments>
		<pubDate>Thu, 22 Nov 2012 09:11:47 +0000</pubDate>
		<dc:creator>quick</dc:creator>
				<category><![CDATA[Objective C]]></category>

		<guid isPermaLink="false">http://www.quickprogrammingtips.com/?p=120</guid>
		<description><![CDATA[The following Objective-C program prints sum of digits of a number entered by user. This program will only compile in latest compilers as it uses ARC paradigm. The program uses scanf c function to read user input. // Print sum of digits of a user entered number #import &#60;foundation foundation.h&#62; int main(int argc, const char [...]]]></description>
				<content:encoded><![CDATA[<p>The following Objective-C program prints sum of digits of a number entered by user. This program will only compile in latest compilers as it uses ARC paradigm. The program uses scanf c function to read user input. </p>
<pre class="brush: objc;">// Print sum of digits of a user entered number
#import &lt;foundation foundation.h&gt;

int main(int argc, const char * argv[])
{

    @autoreleasepool {
        int number,digit,sum=0, temp;

        NSLog(@&quot;Enter a number:&quot;);
        scanf(&quot;%i&quot;, &amp;number);
        temp = number;
        
        while(temp &gt; 0) {
            digit = temp%10;
            sum += digit;
            temp = temp/10;
        }
        NSLog(@&quot;Sum of digits of %i = %i&quot;,number,sum);
        
    }
    return 0;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.quickprogrammingtips.com/objective-c/sum-of-digits-of-a-number-in-objective-c.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Connecting to Sybase SQL Anywhere Database in Java</title>
		<link>http://www.quickprogrammingtips.com/java/connecting-to-sybase-sql-anywhere-database-in-java.html</link>
		<comments>http://www.quickprogrammingtips.com/java/connecting-to-sybase-sql-anywhere-database-in-java.html#comments</comments>
		<pubDate>Mon, 21 May 2012 08:46:00 +0000</pubDate>
		<dc:creator>quick</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programs]]></category>

		<guid isPermaLink="false">http://www.quickprogrammingtips.com/?p=116</guid>
		<description><![CDATA[Sybase SQL Anywhere is a powerful database server suitable for enterprise applications. It is also a common database backend for Java Web applications. This article provides a step by step tutorial on connecting and querying data from a Sybase SQL Anywhere database using Java. We will also look at a sample Java class which returns [...]]]></description>
				<content:encoded><![CDATA[<p>Sybase SQL Anywhere is a powerful database server suitable for enterprise applications. It is also a common database backend for Java Web applications.</p>
<p>This article provides a step by step tutorial on connecting and querying data from a Sybase SQL Anywhere database using Java. We will also look at a sample Java class which returns database server date using SQL. </p>
<p>Java platform provides a standardized API interface for connecting to databases known as JDBC (Java Database Connectivity). Applications can use this standard API to connect to any relational database. Database vendors provide specific java library files (drivers) which can connect to their database and expose a standard interface through JDBC.When we write programs, we will be directly using Java JDBC API and under the hood Java will make use the driver library to connect to database and execute SQL commands. </p>
<p>This tutorial is written for Sybase SQL Anywhere 12, Java 1.6 and Sybase JDBC 4.0 driver. You may need different versions of Sybase JDBC drivers for other configurations. However the overall approach remains the same.</p>
<p>Sybase JDBC driver (<strong>sajdbc4.jar</strong>) is part of Sybase database installation. It is located under the folder C:\Program Files\SQL Anywhere 12\Java in a Windows machine(assuming default installation). Copy sajdbc4.jar to the folder where SybaseExample.java file (see below) is located.</p>
<h2>Java Program to Connect to Sybase SQL Anywhere &#8211; JDBC 4.0</h2>
<p>Since we are using JDBC 4.0, we don&#8217;t need to specify the driver name using DriverManager.registerDriver. The following Java program connects to Sybase SQL Anywhere 12 database with JDBC 4.0 driver. It then prints the system date received from the database server,</p>
<pre class="brush: java;">// Example Java Program - Sybase SQL Anywhere 12 Database Connectivity with JDBC 4.0
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class SybaseExample {

    public static void main(String[] args) throws SQLException {
        // uid - user id
        // pwd - password
        // eng - Sybase database server name
        // database - sybase database name
        // host - database host machine ip
        String dburl = &quot;jdbc:sqlanywhere:uid=DBA;pwd=DBA;eng=devdb;database=devdb;links=tcpip(host=172.20.20.20)&quot;;
        
        // Connect to Sybase Database
        Connection con = DriverManager.getConnection(dburl);
        Statement statement = con.createStatement();

        // We use Sybase specific select getdate() query to return date
        ResultSet rs = statement.executeQuery(&quot;SELECT GETDATE()&quot;);
        
        
        if (rs.next()) {
            Date currentDate = rs.getDate(1); // get first column returned
            System.out.println(&quot;Current Date from Sybase is : &quot;+currentDate);
        }
        rs.close();
        statement.close();
        con.close();
    }
}</pre>
<p>In order to compile or run the above program, you need to add sajdbc4.jar to the classpath of your program. If you are using IDE such as NetBeans or Eclipse, you can add sajdbc4.jar as a dependent library and NetBeans/Eclipse will automatically add it to classpath.</p>
<p>If you are running the above program from command line, copy sajdbc4.jar to the folder where the above Java program is located and then compile the file using the following command (this adds sajdbc4.jar to classpath),</p>
<blockquote>
<p><strong>javac -classpath ./sajdbc4.jar SybaseExample.java</strong></p>
</blockquote>
<p>Run the Java program using the following command (sajdbc4.jar is added to classpath),</p>
<blockquote>
<p><strong>java -classpath &quot;./sajdbc4.jar;.&quot; SybaseExample</strong></p>
</blockquote>
<p>Note that when you are running SybaseExample, you need both the JDCB jar file and the current folder in the classpath. If everything went well, you will see the following output.</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Sybase connectivity in Java" border="0" alt="Sybase connectivity in Java" src="http://www.quickprogrammingtips.com/wp-content/uploads/2012/04/image13.png" width="428" height="70" /></p>
<p><strong>Java Program to Connect to Sybase SQL Anywhere 12 Using JDBC 3.0 Driver</strong></p>
<p>If you want to connect to Sybase SQL Anywhere 12 with JDBC 3.0 driver (<strong>sajdbc.jar</strong>) use the following code. The only additional item in this program is the loading of driver file. Without the driver configuration, you will encounter the following error,</p>
<blockquote>
<p>No suitable driver found for jdbc:sqlanywhere</p>
</blockquote>
<pre class="brush: java;">// Example Java Program - Sybase SQL Anywhere 12 Database Connectivity with JDBC 3.0
import java.sql.*;

public class SybaseExample2 {

    public static void main(String[] args) throws Exception {
        DriverManager.registerDriver( (Driver)
                Class.forName( &quot;sybase.jdbc.sqlanywhere.IDriver&quot; ).newInstance() );
        // uid - user id
        // pwd - password
        // eng - Sybase database server name
        // database - sybase database name
        // host - database host machine ip
        
        String dburl = &quot;jdbc:sqlanywhere:uid=DBA;pwd=DBA;eng=devdb;database=devdb;links=tcpip(host=172.20.20.20)&quot;;
        
        // Connect to Sybase Database
        Connection con = DriverManager.getConnection(dburl);
        Statement statement = con.createStatement();

        // We use Sybase specific select getdate() query to return date
        ResultSet rs = statement.executeQuery(&quot;SELECT GETDATE()&quot;);
        
        
        if (rs.next()) {
            Date currentDate = rs.getDate(1); // get first column returned
            System.out.println(&quot;Current Date from Sybase is : &quot;+currentDate);
        }
        rs.close();
        statement.close();
        con.close();
    }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.quickprogrammingtips.com/java/connecting-to-sybase-sql-anywhere-database-in-java.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Finding Perfect Numbers in a Range Using Java</title>
		<link>http://www.quickprogrammingtips.com/java/finding-perfect-numbers-in-a-range-using-java.html</link>
		<comments>http://www.quickprogrammingtips.com/java/finding-perfect-numbers-in-a-range-using-java.html#comments</comments>
		<pubDate>Sun, 20 May 2012 08:19:00 +0000</pubDate>
		<dc:creator>quick</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programs]]></category>

		<guid isPermaLink="false">http://www.quickprogrammingtips.com/?p=113</guid>
		<description><![CDATA[Perfect numbers are natural numbers which can be expressed in the form n = a * a. Hence any number which is the result of multiplying a number with itself is known as a perfect number (or square number). For example, 9 is a perfect number since 9 = 3 * 3. Finding Perfect Numbers [...]]]></description>
				<content:encoded><![CDATA[<p>Perfect numbers are natural numbers which can be expressed in the form n = a * a. Hence any number which is the result of multiplying a number with itself is known as a perfect number (or square number). For example, 9 is a perfect number since 9 = 3 * 3.</p>
<h2>Finding Perfect Numbers in a Range Using Java</h2>
<p>The following Java program finds all perfect numbers (square numbers) between two given numbers. The following program prints perfect numbers between 1 and 100. We iterate through the range of values and then check whether each number is a perfect number or not.</p>
<p>To check whether a number is perfect, we take the square root of the number and then convert it to an integer and then multiply the integer with itself. Then we check whether it is same as the given number.</p>
<pre class="brush: java;">// Finding perfect numbers (square numbers) in a range using Java
import java.io.IOException;

public class SquareNumbersInRange {

    public static void main(String[] args) throws IOException {
        int starting_number = 1;
        int ending_number = 100;
        System.out.println(&quot;Perfect Numbers between &quot;+starting_number+ &quot; and &quot;+ending_number);
        for (int i = starting_number; i &lt;= ending_number; i++) {

            int number = i;

            int sqrt = (int) Math.sqrt(number);
            if (sqrt * sqrt == number) {
                System.out.println(number+ &quot; = &quot;+sqrt+&quot;*&quot;+sqrt);
            } 
        }
    }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.quickprogrammingtips.com/java/finding-perfect-numbers-in-a-range-using-java.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Checking Whether a Number is a Perfect Square Number in Java</title>
		<link>http://www.quickprogrammingtips.com/java/checking-whether-a-number-is-a-perfect-square-number-in-java.html</link>
		<comments>http://www.quickprogrammingtips.com/java/checking-whether-a-number-is-a-perfect-square-number-in-java.html#comments</comments>
		<pubDate>Fri, 18 May 2012 07:51:00 +0000</pubDate>
		<dc:creator>quick</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programs]]></category>

		<guid isPermaLink="false">http://www.quickprogrammingtips.com/?p=111</guid>
		<description><![CDATA[A number is known as a square number or perfect square if the number is a square of another number. That is an number n is square if it can be expressed as n = a * a where a is an integer. Some examples of perfect numbers (square numbers) are , 9 = 3 [...]]]></description>
				<content:encoded><![CDATA[<p>A number is known as a square number or perfect square if the number is a square of another number. That is an number n is square if it can be expressed as n = a * a where a is an integer. Some examples of perfect numbers (square numbers) are ,</p>
<blockquote><p>9 = 3 * 3,&#160;&#160; 25 = 5 * 5, 100 = 10 * 10</p>
</blockquote>
<p>An interesting property of square number is that it can only end with 0, 1, 4, 6, 9 or 25.</p>
<h2>Java Program to Find Whether a Number is a Perfect Square Number</h2>
<p>The following Java program checks whether a given number is a perfect square number or not. We take the square root of the passed in number and then convert it into an integer. Then we take a square of the value to see whether it is same as the number given. If they are same, we got a perfect square number!</p>
<pre class="brush: java;">// Finding whether a number is a perfect square number in Java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class PerfectSquareNumber {
    
    public static void main(String[] args) throws IOException{
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        System.out.print(&quot;Please enter an integer : &quot;);
        int number = Integer.parseInt(reader.readLine());
        
        int sqrt = (int) Math.sqrt(number);
        if(sqrt*sqrt == number) {
            System.out.println(number+&quot; is a perfect square number!&quot;);
        }else {
            System.out.println(number+&quot; is NOT a perfect square number!&quot;);
        }
        
    }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.quickprogrammingtips.com/java/checking-whether-a-number-is-a-perfect-square-number-in-java.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find Smallest Number in an Array Using Java</title>
		<link>http://www.quickprogrammingtips.com/java/find-smallest-number-in-an-array-using-java.html</link>
		<comments>http://www.quickprogrammingtips.com/java/find-smallest-number-in-an-array-using-java.html#comments</comments>
		<pubDate>Thu, 17 May 2012 07:18:00 +0000</pubDate>
		<dc:creator>quick</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programs]]></category>

		<guid isPermaLink="false">http://www.quickprogrammingtips.com/?p=109</guid>
		<description><![CDATA[The following Java program prints the smallest number in a given array. This example uses an inline array, however it can be easily changed to a method taking an array as parameter. We loop through the array comparing whether the current smallest number is bigger than the array value. If yes, we replace the current [...]]]></description>
				<content:encoded><![CDATA[<p>The following Java program prints the smallest number in a given array. This example uses an inline array, however it can be easily changed to a method taking an array as parameter. We loop through the array comparing whether the current smallest number is bigger than the array value. If yes, we replace the current smallest number with the array value. The initial value of the smallest number is set as Integer.MAX_VALUE which is the largest value an integer variable can have!</p>
<h2>Find Smallest Number in an Array Using Java</h2>
<pre class="brush: java;">// Java program to find smallest number in an array
public class FindSmallest {
    
    public static void main(String[] args) {
        int[] numbers = {88,33,55,23,64,123};
        int smallest = Integer.MAX_VALUE;
        
        for(int i =0;i&lt;numbers.length;i++) {
            if(smallest &gt; numbers[i]) {
                smallest = numbers[i];
            }
        }
        
        System.out.println(&quot;Smallest number in array is : &quot; +smallest);
    }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.quickprogrammingtips.com/java/find-smallest-number-in-an-array-using-java.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss><!-- Dynamic page generated in 0.699 seconds. --><!-- Cached page generated by WP-Super-Cache on 2013-06-17 19:02:04 -->
