Welcome to our "JAVA Basic Introductory Video Tutorial" Java language has become the mainstream development language in the current software development industry. This course will lead you to learn our JAVA in a simple and easy-to-understand way, and take you into the wonderful world of JAVA
Course playback address: http://www. php.cn/course/286.html
The teacher’s teaching style:
The teacher’s lectures are simple, clear, layer-by-layer analysis, and comprehensive. Interlocking, rigorous argumentation, rigorous structure, using the logical power of thinking to attract students' attention, and using reason to control the classroom teaching process. By listening to the teacher's lectures, students not only learn knowledge, but also receive training in thinking, and are also influenced and influenced by the teacher's rigorous academic attitude
The more difficult point in this video is JAVA object-oriented:
Object? Everything in the universe is an object, and every individual in the universe, such as plants, animals, and humans, performs his or her own duties and performs his/her ability. This requires objects with high cohesion and low coupling (a simple understanding is the human brain, which is responsible for thinking, imagining, and memory, but cannot breathe, detoxify, or digest food, thus ensuring that it is independent and efficient). The object has two things: state (property) and behavior (method), please see the following code:
Student.java
public class Student { String name; //姓名 int age; //年龄 String classNo; //班级 String hobby; //爱好 //输出信息方法 public void show(){ System.out.println(name + "\n年龄:" + age + "\n就读于:" + classNo + "\n爱好:" + hobby); } }
InitialStudent.java
public class InitialStudent { public static void main(String args[]){ Student student = new Student(); //建立对象 student.name = "张浩"; //给对象赋值 student.age = 10; student.classNo = "S1班"; student.hobby = "篮球"; student.show(); //调用方法 } }
2. Encapsulation, Inheritance, polymorphism
Encapsulation? To give a crude metaphor, my mobile hard drive stores a lot of various data, but my roommate often borrows it and uses it from time to time (formatting? Installing the system? Storing movies?), so I am the owner. It was a huge inconvenience, so I made it clear to him that this hard drive is private to me and you cannot use it in the way I allow! The same is true for objects. You cannot access internal data at will, otherwise it will cause "cross-infection." So we need to encapsulate: privatize properties and provide public methods to access private properties.
Adult.java
public class Adult { private int age; public int getAge() { return age; } public void setAge(int age) { if (age < 18) { System.out.println("错误!最小年龄应为18岁!"); this.age = 18; // 如果不符合年龄要求,则赋予默认值 } else{ this.age = age; } } public String toString() { return " [age=" + age + "]"; } }
TestAdult.java
public class TestAdult { public static void main(String[] args) { Adult p1 = new Adult(); p1.setAge(20); //通过seter、geter、toString来对Adult类的私有属性访问 System.out.println(p1.toString()); //增加了数据访问限制,保证可维护性 } }
Inheritance? The manager thinks that the car design drawings designed by Xiao Li are very good, but now that new energy is promoted, the engine needs to be changed to an electric engine. So Xiao Chen easily changed the gasoline engine part in the drawing to an engine, and then remade the relationship to complete the new drawing! This is the role of inheritance: it uses the definition of an existing class as a basis to create a new class. The new class can have the characteristics of the parent class, and can also derive more characteristics. This makes it very easy to reuse previous code and can significantly reduce development time.
Person.java
class Person { // 定义人类 public String mName; // 姓名 public int mAge; // 年龄 public void dining() { System.out.println("吃饱了..."); } // 吃饭的方法 } class Student extends Person { // 学生类继承于人类 public float mGrade; // 成绩 public void examination() { System.out.println("考试及格了..."); } // 考试的方法 } class Teacher extends Person { // 教师类继承于人类 public float mSalary; // 薪水 public void prelection() { System.out.println("上课很累..."); } // 上课的方法 }
TestPerson.java
public class TestPerson { public static void main(String[] args) { Student std = new Student(); // 实例化学生对象 std.mName = "李东"; std.mAge = 18; // 为姓名和年龄赋值,访问的是父类中的成员 std.dining(); // 调用吃饭的方法,访问的是父类中的成员 std.examination(); // 调用考试方法,访问的是子类中的成员 Teacher teacher = new Teacher(); // 实例化教师对象 teacher.mName = "赵忠祥"; teacher.mAge = 72;// 为姓名和年龄赋值,访问的是父类中的成员 teacher.dining();// 调用吃饭的方法,访问的是父类中的成员 teacher.prelection();// 调用考试方法,访问的是子类中的成员 } }
Polymorphism? The specific type pointed to by the reference variable defined in the program and the method call issued through the reference variable are not determined during programming, but are determined during the running of the program, that is, which class instance object a reference variable will point to. The method call issued by the reference variable is a method implemented in which class, which must be determined during the running of the program. Because the specific class is determined only when the program is running, the reference variable can be bound to various class implementations without modifying the source program code, causing the specific method called by the reference to change accordingly, that is, it does not need to be modified. The program code can change the specific code bound to the program when it is running, allowing the program to select multiple running states. This is polymorphism. Polymorphism enhances software flexibility and scalability. Xiao Li likes to listen to birds singing {sparrows, cuckoos, parrots}
小李:窗外的鸟儿,给我唱首歌。 1.(鸟 bird = new 麻雀 )? 2.(鸟 bird = new 杜鹃 )? 3.(鸟 bird = new 鹦鹉 )? 鸟儿:bird.sing()~~~~~ 小李:鸟儿唱的不错,你是哪种鸟? 鸟儿: bird.shape() 小李:(---如果上面蓝字定义的是3,是鹦鹉)哈哈!原来你是鹦鹉!
Therefore, the polymorphic process is essentially an abstract instruction that allows a group of individuals with the same behavior but different content to work together. a process.
The above is the detailed content of Recommended resources for beginners' introductory JAVA video tutorials. For more information, please follow other related articles on the PHP Chinese website!