Java OOP-Cheat SheetĐược tải lên bởi
zanand
0 xếp hạng0% thấy tài liệu này hữu ích [0 phiếu bầu]
1 nghìn lượt xem1 trangthông tin tài liệu
nhấp để mở rộng thông tin tài liệuSự miêu tả
Bảng cheat cho Java
bản quyền
© © Tất cả các quyền
định dạng có sẵn
PDF, TXT hoặc đọc trực tuyến từ Scribd
Chia sẻ tài liệu này
Chia sẻ hoặc nhúng tài liệu
Chia sẻ lựa chọn
- Chia sẻ với Email, mở ứng dụng thư khách
E-mail
Bạn có thấy tài liệu này hữu ích không?
0%0% thấy tài liệu này hữu ích, Hãy đánh dấu tài liệu này là hữu ích
0%0% nhận thấy tài liệu này không hữu ích, Hãy đánh dấu tài liệu này là không hữu ích
Nội dung này có phù hợp không?
Tải ngay
LưuLưu Java OOP-Cheat Sheet để sử dụng sau này
0 xếp hạng0% thấy tài liệu này hữu ích [0 phiếu bầu]
Java OOP-Cheat Sheet
Được tải lên bởi
zanandSự miêu tả
Bảng cheat cho Java
LưuLưu Java OOP-Cheat Sheet để sử dụng sau này
0%0% thấy tài liệu này hữu ích, Hãy đánh dấu tài liệu này là hữu ích
0%0% nhận thấy tài liệu này không hữu ích, Hãy đánh dấu tài liệu này là không hữu ích
NhúngChia sẻ
Tải ngay
Chuyển đến trang
Bạn đang ở trang 1trong tổng số 1Tìm kiếm bên trong tài liệu
Thưởng cho sự tò mò của bạn
Mọi thứ bạn muốn đọc
Bất cứ lúc nào. bất cứ nơi nào. Bất kỳ thiết bị
Không cam kết. Hủy bỏ bất cứ lúc nào
Chia sẻ tài liệu này
Chia sẻ hoặc nhúng tài liệu
Chia sẻ lựa chọn
- Chia sẻ với Email, mở ứng dụng thư khách
Trang Chủ Sách sách nóiđiều hướng nhanh
Các tài liệu
, tích cựcJava OOP Cheatsheet được thiết kế theo luồng dễ hiểu với các ví dụ để tìm hiểu các khái niệm OOP [Lập trình hướng đối tượng] của Java. Nó cũng có thể được coi là một hướng dẫn để Bắt đầu với OOP trong Java. Nó giải thích cách sử dụng cơ bản của trừu tượng hóa, đóng gói, kế thừa và đa hình với các ví dụ. Cuối cùng, nó cung cấp liên kết để tải xuống bản PDF có tất cả các phần của Java OOP Cheat Sheet
0 - Trình cài đặt
Java 11 Trên macOS, Java 11 Trên Windows, Java 11 Trên Ubuntu, Java 8 Trên macOS, Java 8 Trên Windows, Java 8 Trên Ubuntu, IntelliJ IDEA trên Windows, IntelliJ IDEA trên Ubuntu, Visual Studio Code trên Windows, Visual Studio Code trên
1 - Khái niệm cơ bản
Bạn có thể theo dõi Java Basics Cheatsheet để tìm hiểu những kiến thức cơ bản về Java
2 - Công cụ sửa đổi
# Access Modifiers # There are three access modifiers in Java including public, private, and protected. # Apart from these three modifiers, a class or member can have default visibility without specifying any access modifier. # public Visible within the same or other packages. # protected Visible within the same package or child classes in same or other packages. # private Visible within the same class. # none Visible within the same package. # Non-Access Modifiers # Apart from the three access modifiers, there are non-access modifiers including abstract, final, strictfp, default, static, native, synchronized, transient, and volatile. # abstract Applicable on classes, interfaces, and methods. # final Applicable on classes, methods, instance variables, local variables, class variables, and interface variables. # strictfp Applicable on classes, and methods. The floating points in classes or methods marked as strictfp must adhere to IEEE 754 standard. # default Applicable on interface methods with body since Java 8. # static Applicable on nested classes, methods, class variables, and interface variables. Also, applicable on interface methods since Java 8. # native Applicable on methods to call platform dependent method. # synchronized Applicable on methods and method blocks. The synchronized methods and blocks can be accessed by one thread at a time. # transient The instance variables marked as transient won't be serialized. # volatile The instance variables marked as volatile will force threads to occupy their own copy of the variable with the master copy in memory.
Phạm vi công cụ sửa đổi truy cập
Phạm viPrivateDefaultProtectedPublicCùng một lớpCóCóCóCóCùng góiKhôngCóCóCóGói khácLớp phụKhôngKhôngCóCóCóGói khác
Lớp không phụKhôngKhôngKhôngCó
3 - Lớp học
# A Class can be declared using the keyword class. # A class can be considered as blueprint or prototype to create the instances of the class. # Instances of a class are also known as objects. # We can create multiple objects of the same class using the keyword new. # Every Object has it's own state and behavior in the form of instances fields and methods respectively. # The classes marked as public are visible within other packages. # The classes without any access modifier are visible within the same package. # The class declaration cannot use the private or protected access modifier. # The nested class declaration can use the public, private or protected access modifier. # The nested class declaration can use the static modifier. # The file name of the file having public class must be the same as that of the class. # The source code file can have any name in absence of public class. The name must not match any class name of the classes declared within the file. # A file can have only one public class. # A file can have multiple non-public classes. # If the class is part of a package, the package statement must be the first line. # If there are import statements, they must go between the package and first class in the same source code file. # In absence of package statement, import statement must be the first line. # In absence of package and import statements, class declaration must be the first line. # It's preferred to follow Camel Case naming convention while naming the method. The first letter can be capital and capital letter can be used for the inner words. # Class Examples // Package Level class Vehicle { } public class Vehicle { } public class Car { } public class Truck { } // Create Objects Car car = new Car[]; Truck truck = new Truck[];
4 - Nhà xây dựng
# The Java Compiler creates a default no-args constructor in case no constructor is defined for a class. # The default no-args constructor has the same access modifier as that of the class. # The default no-args constructor includes call to the superclass no-args constructor using super[]. # We can explicitly declare and define the no-args constructor. # The constructor name must be the same as that of the class. # The constructor must not be associated with return type. # A class can have multiple overloaded constructors. # The class objects can be created using the appropriate constructor. # Every constructor, as it's first statement, implicitly invokes no-args constructor of the superclass by calling super[]. # We can explicitly invokes no-args constructor or overloaded constructor with arguments of the same class by calling this[] or superclass by calling super[] as the first statement of the constructor. # In absence of no-args constructor and presence of constructor with arguments, the compiler won't create the default no-args constructor. # In absence of no-args constructor and presence of constructor with arguments in superclass, the constructor must explicitly invokes no-args or overloaded constructor of same class by calling this[] or overloaded constructor of superclass by calling super[]. # In absence of no-args constructor and presence of constructor with arguments, we cannot create an object without passing appropriate constructor arguments. # It's preferred to define a no-args constructor in presence of constructors with arguments. Though, in several scenarios we might not be required to define the no-args constructor. # Constructors can use any access modifiers including public, protected, private, or none. # A constructor cannot be invoked like a method. A constructor can be invoked within another constructor by calling this[] or super[] as the first statement. # Constructor Examples public class Car { private String color; // Constructor without any argument and without return type public Car[] { this.color = "White"; } // Constructor with argument and without return type public Car[ String color ] { this.color = color; } } // Create Objects Car whiteCar = new Car[]; Car redCar = new Car[ "Red" ];
5 - Phương pháp
# A Method is a block of code defining the behavior of the class. # A method must always specify the return type. # A class can have multiple methods with different names. # A class can have multiple overloaded methods having same name, but different parameters. # Though it's not preferred, the method name can be the same as that of the class with return type. # A method can be either instance method or class method. # The class methods must use the keyword static. # The static methods can be called without creating the object of the class. # The static methods can't be overridden. # The static methods can't call non-static method or use instance variables. # The static methods can call static methods or use static variables. # The methods without any access modifiers remains visible within the same package. # The methods with public access modifier remains visible within the same and other packages. # The methods with protected access modifier remains visible within the same package and child classes in the same package or other packages. # It's preferred to follow Camel Case naming convention while naming the method. The first letter can be small and capital letter can be used for the inner words. # Method Examples public class Car { private String color; public Car[] { this.color = "White"; } public String getColor[] { return color; } public void setColor[ String color ] { this.color = color; } } // Create Objects Car myCar = new Car[]; // Print Color System.out.println[ myCar.getColor[] ];
6 - Khối khởi tạo
# Apart from constructors and methods, a class can perform operations using initialization blocks. # The static initialization block runs only once when the class is loaded. # The instance initialization block runs when the instance is created. # The instance initialization block runs after the call to super[] is over. # A class can have multiple initialization blocks. # The initialization blocks runs in the same order as they appear in the source code file. # Initialization Block Examples public class Car { static int count; static { count = 1000; // Start counting from 1001 } public Car[] { count++; } } // Print Count System.out.println[ Car.count ]; // Output 1001
7 - Thừa kế
# A class can be sub-classed using the keyword extends. # A class cannot extend more than one class. # A class marked as final cannot be sub-classed. # We can test the object type using the keyword instanceof. # We can perform Is-A relationship test to identify the type of object. # A constructor cannot be inherited. # The child class inherits all the public and protected members of parent classes. # The child class can override parent class methods. # The child class can overload parent class methods. # Inheritance makes it possible to re-use the code by extending existing classes without re-implementing the same logic. # We can take advantage of polymorphism by using inheritance. # Inheritance Examples // Package Level public class Vehicle { } public class Car extends Vehicle { } public class Truck extends Vehicle { } // Create Objects Car car = new Car[]; Truck truck = new Truck[]; Vehicle myCar = new Car[]; # IS-A relationship tests // car Is-A Car // car Is-A Vehicle // truck Is-A Vehicle // myCar Is-A Car // myCar Is-A Vehicle
8 - Trừu tượng hóa
Trừu tượng hóa là quá trình ẩn các chi tiết triển khai và chỉ hiển thị thông tin cần thiết cho người dùng. Tính trừu tượng trong Java có thể đạt được bằng cách sử dụng các lớp và giao diện trừu tượng