Java培训

2-2-1

  1. pass-by-value,pass-by-reference

     public class Book {
    
         private String name;
    
         private int page;
    
         public String getName() {
             return name;
         }
    
         public void setName(String name) {
             this.name = name;
         }
    
         public int getPage() {
             return page;
         }
    
         public void setPage(int page) {
             this.page = page;
         }
    
     }
    
     public class Person {
    
         private String name;
    
         private String bookName;
    
         private Book book;
    
         public String getName() {
             return name;
         }
    
         public void setName(String name) {
             this.name = name;
         }
    
         public Book getBook() {
             return book;
         }
    
         public void setBook(Book book) {
             this.book = book;
         }
    
         public String getBookName() {
             return this.getBook().getName();
         }
     }
    
    
     public class Main {
    
         public static void main(String[] args) throws Exception {
             String test = "Hello";
             System.out.println(test);
             test = test.toUpperCase();
             System.out.println(test);
    
             Book book = new Book();
             book.setName("Thinking in Java");
             book.setPage(100);
    
             Person p = new Person();
             String bob = "Bob";
             p.setName(bob); // 传入bob变量
             System.out.println(p.getName()); // "Bob"
             bob = "Alice"; // bob改名为Alice
             System.out.println(p.getName()); // "Bob"还是"Alice"?
    
             p.setBook(book);
             System.out.println(p.getBookName());
             book.setName("Thinking in Java V2");
             System.out.println(p.getBookName());
         }
     }
    
  2. String value

    The Class String

    A String object has a constant (unchanging) value.

    jdk8 is char[]

    jdk9 is byte[]

    Primitive Types

    The integral types are byte, short, int, and long, whose values are 8-bit, 16-bit, 32-bit and 64-bit signed two's-complement integers, respectively, and char, whose values are 16-bit unsigned integers representing UTF-16 code units

  3. 编码

    unicode

    Unicode 是「字符集」 UTF-8 是「编码规则」