An overview of Java arrays and object-oriented knowledge points
1. java array
1) Declaration format:
type[] arrayName; Recommended method
type arrayName[];
2) 初始化: 方式一: type[] arrayName; arrayName = new type[] {element1, element2, element3, ...} 方式二: type[] arrayName = {element1, element2, element3, ...} 方式三:报错 type[] arrayName; arrayName = {element1, element2, element3, ...} 方式四: type[] arrayName = new type[length]; 说明: 方式四中,系统为数组元素分配初始值,如byte,int long - > 0, float,double -> 0.0, boolean -> false, 引用类型 -> null。 不要在进行数组初始化时,即指定数组长度,有为每个元素分配初始值。 数组长度是数组的属性,arrayName.length,即可访问。 foreach循环方法: for ( type var : array | collection ) { ... } 注:这种方法中var只是原集合中的一个副本,对var进行修改,不会改变原集合的内容。 3) 多维数组 type[][] arrName = new type[length][]; // 可以仅指定高维 type[][] arrName = new type[length2][length3]; String[][] str1 = new String[][] {new String[3], new String[] {"hello"}} // 可见低维长度可以不等 4) 操作数组工具类Arrays binarySearch, copyOf, sort, toString等 (补充用例)
2. Object-oriented
1. The only way to pass parameters in java is by value
2. 形参长度可变的方法: void test(int a, String... books){ for(String t : books){...} } test(5, "book1", "book2") 变长形参被作为数组参数 3. override v.s. overload override: 子类重写父类方法,签名一致 overload: 同一个类中,同名不同参的方法(返回值不能作为区分) https://www.runoob.com/java/java-override-overload.html 4. 成员(属性、方法)访问权限 default:同一个包中任意类访问】 protected: 同一个包中任意类访问 或 其他包中子类访问 5. 成员初始化顺序 因素:静态成员/初始化块、普通成员/初始化块、构造函数、父类子类、分配对象(容易被忽略) https://www.zhihu.com/question/49196023 http://jm.taobao.org/2010/07/21/331/ 需注意的是:为对象分配内存,而后会初始化为默认值(int->0, boolean->false, ref -> null...) 6. 调用父类构造器 super显示调用父类构造器时,必须放在子类构造器的第一行(this也有这个要求)。 如果子类构造器中调用this(...),即其他构造器,则会在其他构造器中调用父类构造器。 如果子类中无super 和 this,则会隐式调用无参构造器。
3. Object-oriented
1. Basic data type packaging class
Before automatic packing and unboxing:
Wrapping: new WrapperClass(primitive)
Unboxing: WrapperInstance.xxxValue()
基本数据类型 -> 字符串:String.valueOf() 字符串 -> 基本数据类型:Integer.parseInt() 2. 类的组成 类包括属性、方法、初始化代码块、构造器、内部类、枚举类等。 静态成员不能访问实例成员。 单例对象多种方法 3. final final修饰变量 无论是类成员属性,还是局部变量,都不能重新赋值。 如果是引用类型,仅能确保引用指向同一对象,对象的内容依然可变。 final修饰方法 不能被override final修饰类 不可有子类 4. abstract 一个类有抽象方法(a. 直接定义了抽象方法; b. 继承了抽象父类的抽象方法未实现;c. 接口的抽象方法未实现?),则必须被标识为抽象类。 不包含抽象方法的类,也可以标识成抽象方法。 抽象类的作用?模板模式意义大于实际意义。 5. interface 接口修饰符可以是public或default 接口里可包含常量、抽象实例方法、内部类/接口、枚举类 (新版本可以有普通函数了),他们都是public访问权限,即使省略 接口里的属性默认采用public static final,接口里的方法默认采用public abstract,接口里的内部类和枚举类默认采用public static。 6. 内部类 是封装的强化,仅在外部类中使用,不会在其他地方使用,那么放到外部类里面。 成员内部类、局部内部类、匿名内部类 7. 枚举类 略
The above is the detailed content of An overview of Java arrays and object-oriented knowledge points. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

Guide to TimeStamp to Date in Java. Here we also discuss the introduction and how to convert timestamp to date in java along with examples.

Capsules are three-dimensional geometric figures, composed of a cylinder and a hemisphere at both ends. The volume of the capsule can be calculated by adding the volume of the cylinder and the volume of the hemisphere at both ends. This tutorial will discuss how to calculate the volume of a given capsule in Java using different methods. Capsule volume formula The formula for capsule volume is as follows: Capsule volume = Cylindrical volume Volume Two hemisphere volume in, r: The radius of the hemisphere. h: The height of the cylinder (excluding the hemisphere). Example 1 enter Radius = 5 units Height = 10 units Output Volume = 1570.8 cubic units explain Calculate volume using formula: Volume = π × r2 × h (4

Spring Boot simplifies the creation of robust, scalable, and production-ready Java applications, revolutionizing Java development. Its "convention over configuration" approach, inherent to the Spring ecosystem, minimizes manual setup, allo
