目前分類:Java (59)

瀏覽方式: 標題列表 簡短摘要

在c/c++中, 我們可以藉由system()執行ㄧ些作業系統上的指令 , 

同樣地 , 在Java中也有屬於自己的方式來進行操作 , 那就是藉由Process與Runtime.exec().

JerryCheng 發表在 痞客邦 留言(1) 人氣()

有時在編譯java program時 , 會產生xxx$1.class這樣的檔案 , 

這主要是在該class中含有inner class , 而該inner class被編譯後便會產生xxx$1.class的檔案,

JerryCheng 發表在 痞客邦 留言(0) 人氣()

在Java中 , 我們如果想要使用Thread , 

可以藉由anonymous inner class的方式 , 

JerryCheng 發表在 痞客邦 留言(0) 人氣()

JNA就是Java Native Access , 是為了解決JNI的不便利性所發展出來的

一個 java library , 透過JNA我們可以很簡單的便可以連結到Native shared Library (c/c++的Library).

JerryCheng 發表在 痞客邦 留言(0) 人氣()

在Java中 , 要分割String通常我們會用String Class中的split method , 

不過其實還有另外一個class可以幫我們達到這樣的目的 , 那就是StringTokenizer Class.

JerryCheng 發表在 痞客邦 留言(0) 人氣()

在Java中,  若我們想要設定小數的輸出位數 , 

可以藉由NumberFormat來完成這樣的需求 , 

JerryCheng 發表在 痞客邦 留言(0) 人氣()

有時我們會想判斷一個string是否包含一些特定的名詞 , 

通常要達到這樣的目的 , 最直覺的 , 我們可以用Pattern and Matcher , 

JerryCheng 發表在 痞客邦 留言(0) 人氣()

在Java中 , 除了primitive data type 之外 , 對於所有的物件都是用reference來指向他.

所以當我們宣告一個Object o1時 , 我們等於是宣告一個reference , 而後面我們便可以將o1 reference到任何的compatible type.

JerryCheng 發表在 痞客邦 留言(0) 人氣()

We know that we can split the string by the method , split(String regex);

Besides , there is a another overloading function , split(String regex , int limit) , to achieve this purpose.

JerryCheng 發表在 痞客邦 留言(0) 人氣()

@法國人 Bioderma 貝德瑪淨妍/新舒妍TS 高效潔膚液500ml ~**2000免郵**超取/黑貓宅配 2011-05-27

☆巴黎草莓☆ NATURACTOR 娜拉兒 遮瑕膏 另有 歐達兒 蓋斑膏/資生堂遮瑕蜜 S100 超商取貨 2012-01-12

JerryCheng 發表在 痞客邦 留言(0) 人氣()

SimpleDataFormat是一種可以用來幫助我們描述時間的一種類別 , 

藉由SiimpleDataFormat , 我們可以定義出一個關於時間的pattern , 

JerryCheng 發表在 痞客邦 留言(0) 人氣()

一般我們在設計程式時 , 當然主要是希望這個程式可以較為general的適用在各地區.

但有時狀況卻並不一定允許我們這樣做 , 因此在Java中 , 

JerryCheng 發表在 痞客邦 留言(0) 人氣()

Most operating systems provide program interfaces for performing operations involving the sending and receiving of data over sockets. Most operating systems also provide administrative capabilities to control the amount of memory allocated per socket that is used as data buffers.

ref : http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=%2Fcom.ibm.websphere.nd.doc%2Finfo%2Fae%2Fae%2Ftrun_ha_cfg_socket.html

JerryCheng 發表在 痞客邦 留言(0) 人氣()

We also can insert records to the database by JDBC API.

For example : 

JerryCheng 發表在 痞客邦 留言(0) 人氣()

How to create a table in the database by JDBC API?

The example is as below : 

JerryCheng 發表在 痞客邦 留言(0) 人氣()

We should send a SQL command if we want the database do some operation.
For example :
//STEP 1. Import required packages
import java.sql.*;

public class JDBCExample {
   // JDBC driver name and database URL
   static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
   static final String DB_URL = "jdbc:mysql://localhost/";

   //  Database credentials
   static final String USER = "username";
   static final String PASS = "password";
   
   public static void main(String[] args) {
   Connection conn = null;
   Statement stmt = null;
   try{
      //STEP 2: Register JDBC driver
      Class.forName("com.mysql.jdbc.Driver");

      //STEP 3: Open a connection
      System.out.println("Connecting to database...");
      conn = DriverManager.getConnection(DB_URL, USER, PASS);

      //STEP 4: Execute a query
      System.out.println("Creating database...");
      stmt = conn.createStatement();
      
      String sql = "CREATE DATABASE STUDENTS";
      stmt.executeUpdate(sql);
      System.out.println("Database created successfully...");
   }catch(SQLException se){
      //Handle errors for JDBC
      se.printStackTrace();
   }catch(Exception e){
      //Handle errors for Class.forName
      e.printStackTrace();
   }finally{
      //finally block used to close resources
      try{
         if(stmt!=null)
            stmt.close();
      }catch(SQLException se2){
      }// nothing we can do
      try{
         if(conn!=null)
            conn.close();
      }catch(SQLException se){
         se.printStackTrace();
      }//end finally try
   }//end try
   System.out.println("Goodbye!");
}//end main
}//end JDBCExample

 

ref : http://www.tutorialspoint.com/jdbc/jdbc-create-database.htm

JerryCheng 發表在 痞客邦 留言(0) 人氣()

Before we do any operation for database , we should know how to connect the Mysql database 

throuth JDBC.

JerryCheng 發表在 痞客邦 留言(0) 人氣()

JDBC stands for Java DataBase Connectivity ,  it is a standard Java API (Application Programming Interface)

for database-independent connectivity between the Java programming language and a wide range of databases.

JerryCheng 發表在 痞客邦 留言(0) 人氣()

When we use vector class , we can use for-each to iterate all elements in the vector container.

import java.util.*; 

JerryCheng 發表在 痞客邦 留言(0) 人氣()

We can Enumeration class to iterate the element of Hashtable.

 

JerryCheng 發表在 痞客邦 留言(0) 人氣()

1 23