国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

JavaAPI

Nov 19, 2016 am 10:21 AM
java

》JavaAPI

  文檔注釋可以在:類,常量,方法上聲明

  文檔注釋可以被javadoc命令所解析并且根據(jù)內(nèi)容生成手冊

package cn.fury.se_day01;
/**
 * 文檔注釋可以在:類,常量,方法上聲明
 * 文檔注釋可以被javadoc命令所解析并且根據(jù)內(nèi)容生成手冊
 * 這個類用來測試文檔注釋
 * @author soft01
 * @version 1.0
 * @see java.lang.String
 * @since jdk1.0
 *
 */
public class APIDemo {
    public static void main(String[] args){
        System.out.println(sayHello("fury"));
    }
    /**
     * 問候語,在sayHello中被使用
     */
    public static final String INFO = "你好!";
    /**
     * 將給定的用戶名上添加問候語
     * @param name 給定的用戶名
     * @return  帶有問候語的字符串
     */
    public static String sayHello(String name){
        return INFO+name;
    }
}

測試代碼

》字符串是不變對象:字符串對象一旦創(chuàng)建,內(nèi)容就不可更改

  》》字符串對象的重用

  **要想改變內(nèi)容一定會創(chuàng)建新對象**

  TIP: 字符串若使用字面量形式創(chuàng)建對象,會重用以前創(chuàng)建過的內(nèi)容相同的字符串對象。

  重用常量池中的字符串對象:就是在創(chuàng)建一個字符串對象前,先要到常量池中檢查是否這個字符串對象之前已經(jīng)創(chuàng)建過,如果是就會進(jìn)行重用,如果否就會重新創(chuàng)建

package cn.fury.test;

public class Test{
    public static void main(String[] args) {
        String s1 = "123fury"; //01
        String s2 = s1; //02
        String s3 = "123" + "fury"; //03
        String s4 = "warrior";
        System.out.println(s1 == s2);
        System.out.println(s3 == s1);
        System.out.println(s4 == s1);
    }
}

/**
 * 01 以字面量的形式創(chuàng)建對象:會重用常量池中的字符串對象
 * 02 賦值運(yùn)算:是進(jìn)行的地址操作,所以會重用常量池中的對象
 * 03 這條語句編譯后是:String s3 = "123fury";
 */

字符串對象的重用
package cn.fury.se_day01;
/**
 * 字符串是不變對象:字符串對象一旦創(chuàng)建,內(nèi)容是不可改變的,
 *         **要想改變內(nèi)容一定會創(chuàng)建新對象。**
 * 
 * 字符串若使用字面量形式創(chuàng)建對象,會重用以前創(chuàng)建過的內(nèi)容相同的字符串對象。
 * @author soft01
 *
 */
public class StringDemo01 {
    public static void main(String[] args) {
        String s1 = "fury123";
//        字面量賦值時會重用對象
        String s2 = "fury123";
//        new創(chuàng)建對象時則不會重用對象
        String s3 = new String("fury123");
        /*
         * java編譯器有一個優(yōu)化措施,就是:
         * 若計(jì)算表達(dá)式運(yùn)算符兩邊都是字面量,那么編譯器在生成class文件時
         * 就會將結(jié)果計(jì)算完畢并保存到編譯后的class文件中了。
         * 
         * 所以下面的代碼在class文件里面就是:
         * String s4 = "fury123";
         */
        String s4 = "fury" + "123"; //01
        String s5 = "fury";
        String s6 = s5 + "123"; //02
        String s7 = "fury"+123; //01
        String s8 = "fu"+"r"+"y"+12+"3";
        
        String s9 = "123fury";
        String s10 = 12+3+"fury";  //編譯后是String s10 = "15fury";
        String s11 = '1'+2+'3'+"fury"; //03
        String s12 = "1"+2+"3"+"fury";
        String s13 = 'a'+26+"fury"; //04
        
        System.out.println(s1 == s2); //true
        System.out.println(s1 == s3); //false
        System.out.println(s1 == s4); //true
        System.out.println(s1 == s6); //false
        System.out.println(s1 == s7); //true
        System.out.println(s1 == s8); //true
        System.out.println(s9 == s10); //false
        System.out.println(s9 == s11); //false
        System.out.println(s9 == s12); //true
        System.out.println(s9 == s13); //true
        /*
         * 用來驗(yàn)證03的算法
         */
        int x1 = '1';
        System.out.println(x1);
        System.out.println('1' + 1);
        /*
         * 用來驗(yàn)證04的算法
         */
        int x2 = 'a';
        System.out.println(x2);
        System.out.println('a' + 26);
//        System.out.println(s10);
    }
}

/*
 * 01 編譯完成后:String s4 = "fury123";  因此會重用對象
 * 02 不是利用字面量形式創(chuàng)建對象,所以不會進(jìn)行重用對象
 * 03 '1'+2  的結(jié)果不是字符串形式的12,而是字符1所對應(yīng)的編碼加上2后的值
 * 04 'a'+26 的結(jié)果是字符a所對應(yīng)的編碼值再加上26,即:123
 */

list

  》》字符串長度

    中文、英文字符都是按照一個長度進(jìn)行計(jì)算

package cn.fury.se_day01;
/**
 * int length()
 * 該方法用來獲取當(dāng)前字符串的字符數(shù)量,
 * 無論中文還是英文每個字符都是1個長度
 * @author soft01
 *
 */
public class StringDemo02 {
    public static void main(String[] args) {
        String str = "hello fury你好Java";
        System.out.println(str.length());
        
        int [] x = new int[3];
        System.out.println(x.length);
    }
}

字符串的長度

  》》子串出現(xiàn)的位置

public int indexOf(String str) {
        return indexOf(str, 0);
    }

    /**
     * Returns the index within this string of the first occurrence of the
     * specified substring, starting at the specified index.
     *
     * <p>The returned index is the smallest value <i>k</i> for which:
     * <blockquote><pre class="brush:php;toolbar:false">
     * <i>k</i> &gt;= fromIndex {@code &&} this.startsWith(str, <i>k</i>)
     * 
* If no such value of k exists, then {@code -1} is returned. * * @param str the substring to search for. * @param fromIndex the index from which to start the search. * @return the index of the first occurrence of the specified substring, * starting at the specified index, * or {@code -1} if there is no such occurrence. */ public int indexOf(String str, int fromIndex) { return indexOf(value, 0, value.length, str.value, 0, str.value.length, fromIndex); } 方法解釋
package cn.fury.se_day01;
/**
 * int indexOf(String str)
 * 查看給定字符串在當(dāng)前字符串中的位置
 * 首先該方法會使用給定的字符串與當(dāng)前字符串進(jìn)行全匹配
 * 當(dāng)找到位置后,會將給定字符串中第一個字符在當(dāng)前字符串中的位置返回;
 * 沒有找到就返回  **-1**
 * 常用來查找關(guān)鍵字使用
 * @author soft01
 *
 */
public class StringDemo03 {
    public static void main(String[] args) {
        /*
         * java編程思想:  Thinking in Java
         */
        String str = "thinking in java";
        int index = str.indexOf("java");
        System.out.println(index);
        index = str.indexOf("Java");
        System.out.println(index);
        /*
         * 重載方法:
         *         從給定位置開始尋找第一次出現(xiàn)給定字符串的位置
         */
        index = str.indexOf("in", 3);
        System.out.println(index);
        /*
         * int lastIndexOf(String str)
         * 返回給定的字符串在當(dāng)前字符串中最后一次出現(xiàn)的位置
         */
        int last = str.lastIndexOf("in");
        System.out.println(last);
    }
}

方法應(yīng)用

  》》截取部分字符串

    String substring(int start, int end)

Open Declaration   String java.lang.String.substring(int beginIndex, int endIndex)


Returns a string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex. 

Examples: 

 "hamburger".substring(4, 8) returns "urge"
 "smiles".substring(1, 5) returns "mile"
 
Parameters:beginIndex the beginning index, inclusive.endIndex the ending index, exclusive.Returns:the specified substring.Throws:IndexOutOfBoundsException - if the beginIndex is negative, or endIndex is larger than the length of this String object, or beginIndex is larger than endIndex.

方法解釋
package cn.fury.se_day01;
/**
 * String substring(int start, int end)
 * 截取當(dāng)前字符串的部分內(nèi)容
 * 從start處開始,截取到end(但是不含有end對應(yīng)的字符)
 * 
 * java API有個特點(diǎn),凡是使用兩個數(shù)字表示范圍時,通常都是“含頭不含尾”
 * @author soft01
 *
 */
public class StringDemo04 {
    public static void main(String[] args) {
        String str = "www.oracle.com";
        
        //截取oracle
        String sub = str.substring(4, 10);
        System.out.println(sub);
        
        /*
         * 重載方法,只需要傳入一個參數(shù),從給定的位置開始連續(xù)截取到字符串的末尾
         */
        sub = str.substring(4);
        System.out.println(sub);
    }
}

方法應(yīng)用
package cn.fury.test;

import java.util.Scanner;

/**
 * 網(wǎng)址域名截取
 * @author Administrator
 *
 */
public class Test{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("請輸入網(wǎng)址:");
        String s1 = sc.nextLine();
        int index1 = s1.indexOf(".");
        int index2 = s1.indexOf(".", index1 + 1);
        String s2 = s1.substring(index1 + 1, index2);
        System.out.println("你輸入的網(wǎng)址是:");
        System.out.println(s1);
        System.out.println("你輸入的網(wǎng)址的域名為:");
        System.out.println(s2);
    } 
}

實(shí)際應(yīng)用

  》》去除當(dāng)前字符串中兩邊的空白

    String trim()
    去除當(dāng)前字符串中兩邊的空白

Open Declaration   String java.lang.String.trim()


Returns a string whose value is this string, with any leading and trailing whitespace removed. 

If this String object represents an empty character sequence, or the first and last characters of character sequence represented by this String object both have codes greater than &#39;\u005Cu0020&#39; (the space character), then a reference to this String object is returned. 

Otherwise, if there is no character with a code greater than &#39;\u005Cu0020&#39; in the string, then a String object representing an empty string is returned. 

Otherwise, let k be the index of the first character in the string whose code is greater than &#39;\u005Cu0020&#39;, and let m be the index of the last character in the string whose code is greater than &#39;\u005Cu0020&#39;. A String object is returned, representing the substring of this string that begins with the character at index k and ends with the character at index m-that is, the result of this.substring(k, m + 1). 

This method may be used to trim whitespace (as defined above) from the beginning and end of a string.
Returns:A string whose value is this string, with any leading and trailing white space removed, or this string if it has no leading or trailing white space.

方法解釋
package cn.fury.se_day01;
/**
 * String trim()
 * 去除當(dāng)前字符串中兩邊的空白
 * @author soft01
 *
 */
public class StringDemo06 {
    public static void main(String[] args) {
        String str1 = "  Keep Calm and Carry on.        ";    
        System.out.println(str1);
        String str2 = str1.trim();  //01
        System.out.println(str2);
        System.out.println(str1 == str2);  //02
    }
}

/*
 * 01 改變了內(nèi)容,因此創(chuàng)建了新對象,所以02的輸出結(jié)果為false
 */

方法應(yīng)用

  》》查看指定位置的字符

    char charAt(int index)

    返回當(dāng)前字符串中給定位置處對應(yīng)的字符

Open Declaration   char java.lang.String.charAt(int index)


Returns the char value at the specified index. An index ranges from 0 to length() - 1. The first char value of the sequence is at index 0, the next at index 1, and so on, as for array indexing. 

If the char value specified by the index is a surrogate, the surrogate value is returned.

Specified by: charAt(...) in CharSequence
Parameters:index the index of the char value.Returns:the char value at the specified index of this string. The first char value is at index 0.Throws:IndexOutOfBoundsException - if the index argument is negative or not less than the length of this string.

方法解釋
package cn.fury.se_day01;
/**
 * char charAt(int index)
 *  返回當(dāng)前字符串中給定位置處對應(yīng)的字符
 * @author soft01
 *
 */
public class StringDemo07 {
    public static void main(String[] args) {
        String str = "Thinking in Java";
//        查看第10個字符是什么?
        char chr = str.charAt(9);
        System.out.println(chr);
        
        /*
         * 檢查一個字符串是否為回文?
         */
    }
}

方法應(yīng)用
package cn.fury.test;

import java.util.Scanner;

public class Test{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("請輸入一個字符串(第三個字符必須是字符W):");
        while(true){
            String s1 = sc.nextLine();
            if(s1.charAt(2) == &#39;W&#39;){
                System.out.println("輸入正確");
                break;
            }else{
                System.out.print("輸入錯誤,請重新輸入。");
            }
        }
    } 
}

實(shí)際應(yīng)用
package cn.fury.se_day01;
/*
 * 判斷一個字符串是否是回文數(shù):個人覺得利用StringBuilder類中的反轉(zhuǎn)方法reverse()更加簡單
 */
public class StringDemo08 {
    public static void main(String[] args) {
        /*
         * 上海的自來水來自海上
         * 思路:
         *         正數(shù)和倒數(shù)位置上的字符都是一致的,就是回文
         */
        String str = "上海自水來自海上";
        System.out.println(str);
//        myMethod(str);
        teacherMethod(str);
    }

    private static void teacherMethod(String str) {
        for(int i = 0; i < str.length() / 2; i++){
            if(str.charAt(i) != str.charAt(str.length() - 1 - i)){
                System.out.println("不是回文");
                /*
                 * 方法的返回值類型是void時,可以用return來結(jié)束函數(shù)
                 * return有兩個作用
                 *         1 結(jié)束方法
                 *         2 將結(jié)果返回
                 * 但是若方法返回值為void時,return也是可以單獨(dú)使用的,
                 * 用于結(jié)束方法
                 */
                return;
            }
        }
        System.out.println("是回文");
    }

    private static void myMethod(String str) {
        int j = str.length() - 1;
        boolean judge = false;
        for(int i = 0; i <= j; i++){
            if(str.charAt(i) == str.charAt(j)){
                judge = true;
                j--;
            }else{
                judge = false;
                break;
            }
        }
        if(judge){
            System.out.println("是回文");
        }else
        {
            System.out.println("不是回文");
        }
    }
}

實(shí)際應(yīng)用2_回文數(shù)的判斷

 》》開始、結(jié)束字符串判斷

    boolean startsWith(String star)

    boolean endsWith(String str)

    前者是用來判斷當(dāng)前字符串是否是以給定的字符串開始的,
    后者是用來判斷當(dāng)前字符串是否是以給定的字符串結(jié)尾的。

package cn.fury.se_day01;
/**
 * boolean startsWith(String star)
 * boolean endsWith(String str)
 * 前者是用來判斷當(dāng)前字符串是否是以給定的字符串開始的,
 * 后者是用來判斷當(dāng)前字符串是否是以給定的字符串結(jié)尾的。
 * @author soft01
 *
 */
public class StringDemo09 {
    public static void main(String[] args) {
        String str = "thinking in java";
        System.out.println(str.startsWith("th"));
        System.out.println(str.endsWith("va"));
    }
}

方法應(yīng)用

  》》大小寫轉(zhuǎn)換

    String toUpperCase()

    String toLowerCase()

    作用:忽略大小寫
    應(yīng)用:驗(yàn)證碼的輸入

package cn.fury.se_day01;
/**
 * 將一個字符串中的英文部分轉(zhuǎn)換為全大寫或者全小寫
 * 只對英文部分起作用
 * String toUpperCase()
 * String toLowerCase()
 * 
 * 作用:忽略大小寫
 * 應(yīng)用:驗(yàn)證碼的輸入
 * @author soft01
 *
 */
public class StringDemo10 {
    public static void main(String[] args) {
        String str = "Thinking in Java你好";
        System.out.println(str);
        System.out.println(str.toUpperCase());
        System.out.println(str.toLowerCase());
    }
}

方法應(yīng)用
package cn.fury.test;

import java.util.Scanner;

public class Test{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("請輸入驗(yàn)證碼(F1w3):");
        while(true){
            String s1 = sc.nextLine();
            if(s1.toLowerCase().equals("f1w3")){
                System.out.println("驗(yàn)證碼輸入正確");
                break;
            }else{
                System.out.print("驗(yàn)證碼碼輸入錯誤,請重新輸入:");
            }
        }
    }
}

實(shí)際應(yīng)用_驗(yàn)證碼判斷

 》》靜態(tài)方法valueOf()

    該方法有若干的重載,用來將其他類型數(shù)據(jù)轉(zhuǎn)換為字符串 ;常用的是將基本類型轉(zhuǎn)換為字符串

package cn.fury.test;

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        int x = 123;
        System.out.println(x);
        String s1 = "123";
        String s2 = String.valueOf(x);    //02
        String s3 = x + "";    //01
        System.out.println(s1 == s2);
        System.out.println(s1.equals(x));
        System.out.println("===========");
        System.out.println(s1.equals(s3));
        System.out.println(s1.equals(s2));
    }
}

/**
 * 01 02 的效果是一樣的,但是02的速度快
 */

方法應(yīng)用

》利用StringBuilder進(jìn)行字符串的修改

  StringBuilder內(nèi)部維護(hù)了一個可變的字符數(shù)組,從而保證了無論修改多少次字符串內(nèi)容,都是在這個數(shù)組中完成;當(dāng)然,若數(shù)組內(nèi)容被超出,會擴(kuò)容;但是與字符串的修改相比較,內(nèi)存上的消耗是明顯要少很多的。

package cn.fury.se_day01;
/**
 * StringBuilder內(nèi)部維護(hù)了一個可變的字符數(shù)組
 * 從而保證了無論修改多少次字符串內(nèi)容,都是在這個數(shù)組中完成
 * 當(dāng)然,若數(shù)組內(nèi)容被超出,會擴(kuò)容;但是與字符串的修改相比較,內(nèi)存上的消耗是明顯要少很多的
 * 其提供了用于修改字符串內(nèi)容的常用修改方法:
 *         增:append
 *         刪:delete
 *         改:replace
 *         插:insert
 * @author soft01
 *    
 */
public class StringBuilderDemo01 {
    public static void main(String[] args) {
        System.out.println("===start===");
        String str = "You are my type.";
        System.out.println(str);
        
        /*
         * 若想修改字符串,可以先將其變換為一個
         * StringBuilder類型,然后再改變內(nèi)容,就不會再創(chuàng)建新的對象啦
         */
        System.out.println("===one===");
        StringBuilder builder = new StringBuilder(str);
        //追加內(nèi)容
        builder.append("I must stdy hard so as to match you.");
        //獲取StringBuilder內(nèi)部表示的字符串
        System.out.println("===two===");
        str = builder.toString();
        System.out.println(str);
        //替換部分內(nèi)容
        System.out.println("===three===");
        builder.replace(16, builder.length(),"You are my goddness.");
        str = builder.toString();
        System.out.println(str);
        //刪除部分內(nèi)容
        System.out.println("===four===");
        builder.delete(0, 16);
        str = builder.toString();
        System.out.println(str);
        //插入部分內(nèi)容
        System.out.println("===five===");
        builder.insert(0, "To be living is to change world.");
        str = builder.toString();
        System.out.println(str);
        
        //翻轉(zhuǎn)字符串
        System.out.println("===six===");
        builder.reverse();
        System.out.println(builder.toString());
        //利用其來判斷回文
    }
}

常用方法應(yīng)用
package cn.fury.se_day01;

public class StringBuilderDemo02 {
    public static void main(String[] args) {
//        StringBuilder builder = new StringBuilder("a"); //高效率
//        for(int i = 0; i < 10000000; i++){
//            builder.append("a");
//        }
        String str = "a";  //低效率
        for(int i = 0; i < 10000000; i++){
            str += "a";
        }
    }
}

/*
 * 疑問:字符串變量沒改變一下值就會重新創(chuàng)建一個對象嗎??
 *             答案:是的,因?yàn)樽址畬ο笫遣蛔儗ο?
 */

與字符串連接符“+”的效率值對比

》作業(yè)

  生成一個包含所有漢字的字符串,即,編寫程序輸出所有漢字,每生成50個漢字進(jìn)行換行輸出。在課上案例“測試StringBuilder的append方法“的基礎(chǔ)上完成當(dāng)前案例。

package cn.fury.work.day01;
/**
 * 生成一個包含所有漢字的字符串,即,編寫程序輸出所有漢字,每生成50個漢字進(jìn)行換
 * 行輸出。在課上案例“測試StringBuilder的delete方法“的基礎(chǔ)上完成當(dāng)前案例。
 * @author soft01
 *
 */
public class Work03 {
    public static void main(String[] args) {
        StringBuilder builder = new StringBuilder();
        /*
         * 中文范圍(unicode編碼):
         * \u4e00 ------ \u9fa5
         */
        System.out.println(builder.toString());
        System.out.println("=======");
        char chr1 = &#39;\u4e00&#39;;
        System.out.println(chr1);
        String str = "\u4e00";
        System.out.println(str);
        
        for(char chr = &#39;\u4e00&#39;, i = 1; chr <= &#39;\u9fa5&#39;; chr++,i++){
            builder.append(chr);
            if(i % 50 == 0){
                builder.append("\n");
            }
        }
        
        System.out.println(builder.toString());
    }
}


Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn

Alat AI Hot

Undress AI Tool

Undress AI Tool

Gambar buka pakaian secara percuma

Undresser.AI Undress

Undresser.AI Undress

Apl berkuasa AI untuk mencipta foto bogel yang realistik

AI Clothes Remover

AI Clothes Remover

Alat AI dalam talian untuk mengeluarkan pakaian daripada foto.

Clothoff.io

Clothoff.io

Penyingkiran pakaian AI

Video Face Swap

Video Face Swap

Tukar muka dalam mana-mana video dengan mudah menggunakan alat tukar muka AI percuma kami!

Alat panas

Notepad++7.3.1

Notepad++7.3.1

Editor kod yang mudah digunakan dan percuma

SublimeText3 versi Cina

SublimeText3 versi Cina

Versi Cina, sangat mudah digunakan

Hantar Studio 13.0.1

Hantar Studio 13.0.1

Persekitaran pembangunan bersepadu PHP yang berkuasa

Dreamweaver CS6

Dreamweaver CS6

Alat pembangunan web visual

SublimeText3 versi Mac

SublimeText3 versi Mac

Perisian penyuntingan kod peringkat Tuhan (SublimeText3)

Topik panas

Tutorial PHP
1502
276
Bagaimana menangani transaksi di Java dengan JDBC? Bagaimana menangani transaksi di Java dengan JDBC? Aug 02, 2025 pm 12:29 PM

Untuk mengendalikan transaksi JDBC dengan betul, anda mesti terlebih dahulu mematikan mod komit automatik, kemudian melakukan pelbagai operasi, dan akhirnya melakukan atau mengembalikan semula hasilnya; 1. Panggil Conn.SetAutOcommit (palsu) untuk memulakan transaksi; 2. Melaksanakan pelbagai operasi SQL, seperti memasukkan dan mengemaskini; 3. Panggil Conn.Commit () jika semua operasi berjaya, dan hubungi conn.rollback () jika pengecualian berlaku untuk memastikan konsistensi data; Pada masa yang sama, cuba-dengan-sumber harus digunakan untuk menguruskan sumber, mengendalikan pengecualian dengan betul dan menutup sambungan untuk mengelakkan kebocoran sambungan; Di samping itu, adalah disyorkan untuk menggunakan kolam sambungan dan menetapkan mata simpan untuk mencapai rollback separa, dan menyimpan urus niaga sesingkat mungkin untuk meningkatkan prestasi.

Bagaimana untuk bekerja dengan kalendar di Jawa? Bagaimana untuk bekerja dengan kalendar di Jawa? Aug 02, 2025 am 02:38 AM

Gunakan kelas dalam pakej Java.Time untuk menggantikan kelas lama dan kelas kalendar; 2. Dapatkan tarikh dan masa semasa melalui LocalDate, LocalDateTime dan Tempatan Tempatan; 3. Buat tarikh dan masa tertentu menggunakan kaedah (); 4. Gunakan kaedah tambah/tolak untuk meningkatkan dan mengurangkan masa; 5. Gunakan zoneddatetime dan zonid untuk memproses zon waktu; 6. Format dan parse date string melalui DateTimeFormatter; 7. Gunakan segera untuk bersesuaian dengan jenis tarikh lama apabila perlu; pemprosesan tarikh di java moden harus memberi keutamaan untuk menggunakan java.timeapi, yang memberikan jelas, tidak berubah dan linear

Membandingkan kerangka Java: Spring Boot vs Quarkus vs Micronaut Membandingkan kerangka Java: Spring Boot vs Quarkus vs Micronaut Aug 04, 2025 pm 12:48 PM

Pra-formancetartuptimemoryusage, quarkusandmicronautleadduetocompile-timeprocessingandgraalvsupport, withquarkusoftenperforminglightbetterine serverless scenarios.tyvelopecosyste,

Pergi dengan contoh contoh pembalakan middleware http Pergi dengan contoh contoh pembalakan middleware http Aug 03, 2025 am 11:35 AM

HTTP Log Middleware di GO boleh merakam kaedah permintaan, laluan, IP klien dan memakan masa. 1. Gunakan http.handlerfunc untuk membungkus pemproses, 2. Rekod waktu mula dan masa akhir sebelum dan selepas memanggil next.servehttp, 3. Dapatkan IP pelanggan sebenar melalui r.remoteaddr dan X-forward-for headers, 4. Gunakan log.printf untuk mengeluarkan log permintaan, 5. Kod sampel lengkap telah disahkan untuk dijalankan dan sesuai untuk memulakan projek kecil dan sederhana. Cadangan lanjutan termasuk menangkap kod status, menyokong log JSON dan meminta penjejakan ID.

Bagaimana pengumpulan sampah berfungsi di java? Bagaimana pengumpulan sampah berfungsi di java? Aug 02, 2025 pm 01:55 PM

Koleksi Sampah Java (GC) adalah mekanisme yang secara automatik menguruskan ingatan, yang mengurangkan risiko kebocoran ingatan dengan menuntut semula objek yang tidak dapat dicapai. 1.GC menghakimi kebolehcapaian objek dari objek akar (seperti pembolehubah stack, benang aktif, medan statik, dan lain -lain), dan objek yang tidak dapat dicapai ditandakan sebagai sampah. 2. Berdasarkan algoritma penandaan tanda, tandakan semua objek yang dapat dicapai dan objek yang tidak ditandai. 3. Mengamalkan strategi pengumpulan generasi: Generasi Baru (Eden, S0, S1) sering melaksanakan MinorGC; Orang tua melakukan kurang tetapi mengambil masa lebih lama untuk melakukan MajorGC; Metaspace Stores Metadata kelas. 4. JVM menyediakan pelbagai peranti GC: SerialGC sesuai untuk aplikasi kecil; ParallelGC meningkatkan throughput; CMS mengurangkan

Menggunakan jenis html `input` untuk data pengguna Menggunakan jenis html `input` untuk data pengguna Aug 03, 2025 am 11:07 AM

Memilih jenis htmlinput yang betul dapat meningkatkan ketepatan data, meningkatkan pengalaman pengguna, dan meningkatkan kebolehgunaan. 1. Pilih jenis input yang sepadan mengikut jenis data, seperti teks, e -mel, tel, nombor dan tarikh, yang secara automatik boleh menyemak dan menyesuaikan diri dengan papan kekunci; 2. Gunakan HTML5 untuk menambah jenis baru seperti URL, Warna, Julat dan Carian, yang dapat memberikan kaedah interaksi yang lebih intuitif; 3. Gunakan pemegang tempat dan sifat -sifat yang diperlukan untuk meningkatkan kecekapan dan ketepatan pengisian bentuk, tetapi harus diperhatikan bahawa pemegang tempat tidak dapat menggantikan label.

Membandingkan Java Build Tools: Maven vs Gradle Membandingkan Java Build Tools: Maven vs Gradle Aug 03, 2025 pm 01:36 PM

GradleisthebetterChoiceFormostNewProjectSduetoitSsuperiorflexibility, Prestasi, danModernToolingSupport.1.Gradle'sGroovy/KOT lindslismoreconciseandexpressivethanmaven'sverbosexml.2.GradleOutPerformsMaveninBuildSpeedWithIncrementalcompilation, BuildCac

Pergi dengan contoh penangguhan yang dijelaskan Pergi dengan contoh penangguhan yang dijelaskan Aug 02, 2025 am 06:26 AM

Defer digunakan untuk melaksanakan operasi tertentu sebelum fungsi pulangan, seperti sumber pembersihan; Parameter dinilai dengan serta-merta apabila menangguhkan, dan fungsi-fungsi dilaksanakan mengikut urutan terakhir (LIFO); 1. Pelbagai penahanan dilaksanakan dalam urutan terbalik pengisytiharan; 2. Biasanya digunakan untuk pembersihan yang selamat seperti penutupan fail; 3. Nilai pulangan yang dinamakan boleh diubah suai; 4. Ia akan dilaksanakan walaupun panik berlaku, sesuai untuk pemulihan; 5. Elakkan penyalahgunaan menangguhkan gelung untuk mengelakkan kebocoran sumber; Penggunaan yang betul boleh meningkatkan keselamatan kod dan kebolehbacaan.

See all articles