Time of Update: 2018-12-04
JDK1.5增加的新特性裡面有一個就是泛型。對於泛型的評價,褒貶不一,廢話不多說,先來看看他的原理。泛型是提供給javac編譯器使用的,可以限定集合中的輸入類型,讓編譯器攔截來源程式中的非法輸入,編譯器編譯帶類型說明的集合時會去掉類型資訊,對於參數化得泛型型別,getClass()方法的傳回值和原始類型完全一樣。對於下面這個來源程式: public class Oliver { public static void main(String[] args) {
Time of Update: 2018-12-04
看了一段北風網的視頻,總結幾個經典的java陷阱給大家。答案隱藏了,Ctrl+A顯示。建議先思考一下結果,然後運行代碼實驗。也許你會恍然大悟。1、找奇數:public static boolean isOdd(int i){ return i % 2 == 1;} 上面的方法真的能找到所有的奇數嗎?A:沒有考慮到負數問題,如果傳參是負數,那麼永遠不能得到結果!應該是:return i % 2 != 0;
Time of Update: 2018-12-04
package com.happy.url;import java.io.BufferedReader;import java.io.InputStreamReader;import java.net.URL;/** * Java read web resource * @author Happy * */public class GetWebContent { public static void main(String[] args)
Time of Update: 2018-12-04
package arrays.file;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.FileReader;import
Time of Update: 2018-12-04
package com.qiaole.conn;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;public class DB2 { public static void main(String[] args) { try
Time of Update: 2018-12-04
文法糖(Syntactic Sugar),也叫糖衣文法,是英國電腦科學家彼得·約翰·蘭達(Peter J. Landin)發明的一個術語。指的是,在電腦語言中添加某種文法,這種文法能使程式員更方便的使用語言開發程式,同時增強程式碼的可讀性,避免出錯的機會;但是這種文法對語言的功能並沒有影響。Java中的泛型,變長參數,自動拆箱/裝箱,條件編譯等都是,下面做簡單的介紹和分析。泛型
Time of Update: 2018-12-04
package arrays.compara;import java.util.Arrays;public class Student { public static void main(String[] args) { Stu[] stus = new Stu[]{ new Stu(156,34,"ad"), new Stu(153,24,"cc"), new Stu(126,37,"ab"), new Stu(176,45,"as"), new Stu(156
Time of Update: 2018-12-04
DK1.5引入了新的類型——枚舉。在Java中它雖然算個“小”功能,卻給我的開發帶來了“大”方便。用法一:常量 在JDK1.5之前,我們定義常量都是:public static fianl ....。現在好了,有了枚舉,可以把相關的常量分組到一個枚舉類型裡,而且枚舉提供了比常量更多的方法。public enum Color { RED, GREEN, BLANK, YELLOW}用法二:switch
Time of Update: 2018-12-04
package collection;import java.util.*;public class NewArrayList { public static void main(String[] args) { List<Student> students = new ArrayList<Student>(); for (int i = 0; i < 6; i++) { students.add(new
Time of Update: 2018-12-04
/** * Java拼接多張圖片 * * @param pics * @param type * @param dst_pic * @return */public static boolean merge(String[] pics, String type, String dst_pic) {int len = pics.length;if (len < 1) {System.out.println("pics len < 1");return false;}File[]
Time of Update: 2018-12-04
import java.awt.image.BufferedImage;import java.io.File;import javax.imageio.ImageIO;/** * @author happy * */public class SpellImg {public static void main(String[] args) {try {// 讀取第一張圖片File fileOne = new File("E:\\Test\\5.png");BufferedImage
Time of Update: 2018-12-04
import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import java.net.URL;import javax.imageio.ImageIO;public class WriteImage {public static void main(String[] args) {BufferedImage image = null;try {URL url = new
Time of Update: 2018-12-04
package com.happy.system;import java.io.IOException;public class CmdCommand { public static void main(String[] args) { try { // cmd /c dir 是執行完dir命令後關閉命令視窗。 // cmd /k dir 是執行完dir命令後不關閉命令視窗。 // cmd /c start dir 會開啟一個新視窗後執行dir指令,原視窗會關閉。 //
Time of Update: 2018-12-04
/** * @author happy * */public class MaxValue {public static void main(String[] args) {int[] arrInt = new int[] { 233, 5, 432, 5, 903, 56, 35, 23, 35 };String arrStr = "";int max = arrInt[0];int min = arrInt[0];for (int i = 0; i < arrInt.length;
Time of Update: 2018-12-04
在Java程式中截獲控制台輸出 內容: 一、Java管道流 1.1 注意事項一 1.2 注意事項二 1.3 注意事項三 1.4 解決問題 二、捕獲Java控制台輸出 三、捕獲其他程式的控制台輸出 參考資料 關於作者 俞良松 (javaman@163.net) 軟體工程師,獨立顧問和自由撰稿人 2001 年 10 月
Time of Update: 2018-12-04
package collection;import java.util.*;public class NewSet { public static void main(String[] args) { Set<Student> students = new HashSet<Student>(); for (int i = 0; i < 6; i++) { students.add(new Student("Happy"+i,"male"+i,20+i));
Time of Update: 2018-12-04
CSND下載頁面:http://download.csdn.net/source/357583151CTO下載頁面:http://down.51cto.com/data/245201主要功能包含:一、發布微博1、發布微博2、發布譯文微博3、發布反饋微博二、擷取使用者資訊及好友關係1、擷取使用者資訊2、擷取粉絲列表3、擷取粉絲列表三、微博相關1、自己發布的微博2、其他使用者的微博四、自己的收藏列表五、自己的黑名單列表六、話題類1、任意使用者的話題2、一小時內的熱點話題3、一天內的熱點話題4、一周內
Time of Update: 2018-12-04
有時候吧,一個項目不是由單一的某種語言構成的,所以避免不了語言與語言之間的協作關係。比如:這時你的項目部分是用JAVA編寫的,你需要對資料進行加密與解密的操作,一般來說你會用JAVA實現一個密碼編譯演算法。不過呢,現在你手頭上有個非JAVA的組件可以用,比如DLL,考慮到效率上的問題你使用這個DLL更好些。這時候你就得使用JNI(JAVA NATIVE INTERFACE)—JAVA 原生介面。 這樣我們從一個JAVA調用一個存在的DLL例子入手吧。
Time of Update: 2018-12-04
Java的資料轉換1 字串轉換成資料 字串轉換成整數: String MyNumber="1234"; int MyInt =Integer.parseInt(MyNumber); 字串轉換成byte, short, int,float, double, long等資料類型,可 以分別參考Byte, Short,Integer, Float, Double, Long類的parseXXX 方法。 2 資料轉換成字串 整數轉換成字串: int MyInt = 1234; String
Time of Update: 2018-12-04
Comparator和Comparable在排序中的應用當需要排序的集合或數組不是單純的數字型時,通常可以使用Comparator或Comparable,以簡單的方式實現對象排序或自訂排序。一、Comparator強行對某個對象collection進行整體排序的比較函數,可以將Comparator傳遞給Collections.sort或Arrays.sort。介面方法:/** * @return o1小於、等於或大於o2,分別返回負整數、零或正整數。 */ int