Quiz:
One of the components of a computer is its CPU. What is a CPU and what role does it play in a computer?
Central process Unit, a component of computer, the job of CPU is to excute programs
Explain what is meant by an “asynchronous event.” Give some examples.
event happen at unpredictable time. when CPU needs data in disk, CPU will send signal to disk ask for preparing, disk has releative low speed compare to CPU, so data preparing as an unpredictable event can be seen as asynchronous event.
What is the difference between a “compiler” and an “interpreter”?
compiler trans high-level lang to machine code, compiler will trans program all at once java’s machine code is run for an machine that not exists. JVM interpreter act like cpu, it trans instruction-by-instrction, as necessay, interpreter decide what is necessary and carry out that instruction java has both compiler and interpreter, interpreter is relativly small and simple. so it’s easy to wirte for an new type of computer. what’s more interpreter is user-friendly, user don’t have to understood complex java language, just handle class file to interpreter and the program can run on JVM
Explain the difference between high-level languages and machine language.
ML is simple and can be execute by mechine, however programming is difficut.
Java is an object-oriented programming language. What is an object? The central concept of object-oriented programming is the object, which is a kind of module containing data and subroutines.
review of Java, will introduce in Java topic
-
In Java, inheritance is an is-a relationship (Car is a Vehicle, Apple is a Fruit, Dog is an animal)
-
aggregation, is an has-a relationship
@Override is a non-functional aggression, we can delete that
what’s method body?
why we need polmophism? it does not make sense. we can not have a non-perdictive program.
Interface basicly a set of standers. Interface attributes are by default public, static and final. Interface methods are by default abstract and public.
Collection Framework
Variables, or data is valuable and complexty. But we can not just store them in an entire place randomly. That will cost a lot time in serching and getting
we need different strucher in different situation.
The Collection interface includes various methods that can be used to perform different operations on objects, They provided almost all atom scence in developing.
Collections work only with Reference types(objects) and not with primitive data types.
==OK, but why?==
order collection like an array allow to add or remove member
set like set in math, can not have duplicate elements
Queue FIFO manner
Map store value in key-value elements
arrayList
linkedlist is also arrayList.
we need to declare the size of an array before we can use it. What if we need resize it? like we need store more element, or reduce capicy for saving space
To handle this issue, we can use the ArrayList class. ArrayList implement all methods form list, upon that, It allows us to create resizable arrays.
Unlike arrays, Arraylists can automatically adjust its capacity when we add or remove elements from it. Hence, Arraylists are also known as dynamic arrays.
===clone and deep clone===
Exception Handling
vital to robustness
Sometimes, we hate unpredicet action from normal process, to indicate the problem as well as make an declearation to users, we introduce EH
Exceptioon Handling is an design pattern in program, it contain 2 basic aspects
- Error that occurs during runtime
- Cause normal program flow to be disrupted
Exception Handlling is methology with try-catch block and finally part
Lamda expression
noname subroutain
used in interfaces only have one abstract method.
Anonymous Inner Class
which means you can directly instance an Object without giving the name. Like instant interface, though it’s impossibale.
Thread
2 way to define multi Thread
extend Thread. and you have to implement Run(). call thread.start() will auto call start()
==but why we have to override run method in Thread?==
Or we can use Runnable interface, as well as override run().