Categories
Muslim matrimonial
International islamic marriage site online

Polling

Getting poll results. Please wait...
You are here > Home > Programming > Java
Results 1 - 5 of total 11 Page 1 of total 3
Results per-page: 5 | 10 | 20 | 50
SQLite JDBC

JDBC driver for SQLite. It comes in two flavours, a 100% Pure Java driver based on NestedVM or a native JNI library. The pure java driver is compatible, you can follow the Java dream and use it anywhere with no worries. The native driver is fast, and I recommend it wherever possible. Binaries are provided for Windows and Mac OS X.

 

import java.sql.*;
 
public class Test {
    public static void main(String[] args) throws Exception {
        Class.forName("org.sqlite.JDBC");
        Connection conn = DriverManager.getConnection("jdbc:sqlite:test.db");
        Statement stat = conn.createStatement();
        stat.executeUpdate("drop table if exists people;");
        stat.executeUpdate("create table people (name, occupation);");
        PreparedStatement prep = conn.prepareStatement(
            "insert into people values (?, ?);");
 
        prep.setString(1, "Gandhi");
        prep.setString(2, "politics");
        prep.addBatch();
        prep.setString(1, "Turing");
        prep.setString(2, "computers");
        prep.addBatch();
        prep.setString(1, "Wittgenstein");
        prep.setString(2, "smartypants");
        prep.addBatch();
 
        conn.setAutoCommit(false);
        prep.executeBatch();
        conn.setAutoCommit(true);
 
        ResultSet rs = stat.executeQuery("select * from people;");
        while (rs.next()) {
            System.out.println("name = " + rs.getString("name"));
            System.out.println("job = " + rs.getString("occupation"));
        }
        rs.close();
        conn.close();
    }
} 

Run with:

java -cp .:sqlitejdbc-v044-native.jar -Djava.library.path=. Test

Posted On: 27 April, 2009 Author: mojtaba Continue...
Hello World Example
/*
Java Hello World example.
*/
  public class HelloWorldExample{   public static void main(String args[]){   /*
Use System.out.println() to print on console.
*/
System.out.println("Hello World !");   }   }   /*
 
OUTPUT of the above given Java Hello World Example would be :
 
Hello Wolrd !
 
*/
 
Posted On: 27 April, 2009 Author: mojtaba Continue...
Java Class Example
/*
Java Class example.
This Java class example describes how class is defined and being used in Java language.
 
Syntax of defining java class is,
<modifier> class <class-name>{
// members and methods
}
*/
  public class JavaClassExample{ /*
Syntax of defining memebers of the java class is,
<modifier> type <name>;
*/
private String name; /*
Syntax of defining methods of the java class is,
<modifier> <return-type> methodName(<optional-parameter-list>) <exception-list>{
...
}
*/
public void setName(String n){ //set passed parameter as name name = n; } public String getName(){ //return the set name return name; } //main method will be called first when program is executed public static void main(String args[]){ /*
Syntax of java object creation is,
<class-name> object-name = new <class-constructor>;
*/
JavaClassExample javaClassExample = new JavaClassExample(); //set name member of this object javaClassExample.setName("Visitor"); // print the name System.out.println("Hello " + javaClassExample.getName()); } }   /*
OUTPUT of the above given Java Class Example would be :
Hello Visitor
*/
Posted On: 27 April, 2009 Author: mojtaba Continue...
Java Interface Example
/*
Java Interface example.
This Java Interface example describes how interface is defined and being used in Java language.
 
Syntax of defining java interface is,
<modifier> interface <interface-name>{
//members and methods()
}
*/
  //declare an interface interface IntExample{   /*
Syntax to declare method in java interface is,
<modifier> <return-type> methodName(<optional-parameters>);
IMPORTANT : Methods declared in the interface are implicitly public and abstract.
*/
  public void sayHello(); } } /*
Classes are extended while interfaces are implemented.
To implement an interface use implements keyword.
IMPORTANT : A class can extend only one other class, while it can implement n number of interfaces.
*/
  public class JavaInterfaceExample implements IntExample{ /*
We have to define the method declared in implemented interface,
or else we have to declare the implementing class as abstract class.
*/
  public void sayHello(){ System.out.println("Hello Visitor !"); }   public static void main(String args[]){ //create object of the class JavaInterfaceExample javaInterfaceExample = new JavaInterfaceExample(); //invoke sayHello(), declared in IntExample interface. javaInterfaceExample.sayHello(); } }   /*
OUTPUT of the above given Java Interface example would be :
Hello Visitor !
*/
Posted On: 27 April, 2009 Author: mojtaba Continue...
Do While Loop

Do while loop executes group of Java statements as long as the boolean condition evaluates to true.

It is possible that the statement block associated with While loop never get executed because While loop tests the boolean condition before executing the block of statements associated with it.

In Java programming, sometime it's necessary to execute the block of statements at least once before evaluating the boolean condition. Do while loop is similar to the While loop, but it evaluates the boolean condition after executing the block of the statement.

Do While loop syntax

Do{

<Block of statements>;

}while();

Block of statements is any valid Java code. Boolean condition is any valid Java expression that evaluates to boolean value. Braces are options if there is only one statement to be executed.

Posted On: 27 April, 2009 Author: mojtaba Continue...
1 2 3 Next Page >