java中的小问号
if (a == b) {
do(a);
} else {
do(b);
}
相当于
(a == b) ? do(a) : do(b);
关系
- Inheritance 继承
- Aggregation 聚集
聚合是一种特殊的关联(Association)形式,表示两个对象之间的所属(has-a)关系。所有者对象称为聚合对象,它的类称为聚合类;从属对象称为被聚合对象,它的类称为被聚合类。例如,一个公司有很多员工就是公司类Company和员工类Employee之间的一种聚合关系。被聚合对象和聚合对象有着各自的生命周期,即如果公司倒闭并不影响员工的存在。 - Composition 合成
聚合是一种较弱形式的对象包含(一个对象包含另一个对象)关系。较强形式是组合(Composition). 在组合关系中包含对象负责被包含对象的创建以及生命周期,即当包含对象被销毁时被包含对象也会不复存在。例如一辆汽车拥有一个引擎是汽车类Car与引擎类Engine的组合关系。下面是组合的一些例子。
Wireframe
- 是一種低保真度的設計原型,
- 在去除所有視覺設計細節之下,
- 進行頁面結構、功能、內容規劃。
Program 组成
- Instruction
- method
computer history
- 1G machine language
- 2G Assembly language
- 3G Procedural language
- 4G Non-procedural language
- 5G intelligent language
Paradigm
- Procedural(How)
– C - Declarative(What)
- Functional
– Lisp, Haskell - Rule based(Role->action)逻辑编程
– Prolog - Query based
– DB language - Event driven
– Html, Java AWT(Abstract Window Toolkit) - Object oriented
– Name
– Properties(attribute)
– Operations(behavior, methods)
Primitive Data Types
Bit 计算机最小单位
- Integers
– Byte:8bits
– Short:16bits
– Int:32bits = 4byte
– Long:64bits
- Decimals
– Float: 32bits– Double: 64bits
- Character–
– Char: 16bits
- Boolean
命名规则
- 开头小写
– Variable: 开头小写,后边大写
– Method:同variable - 开头大写
– Class:每个单词开头大
– Interface:同Class - 全部小写
– Package: 全部小写 - 全部大写
– Constants:全部大写
Variable
- Global variable: in the class, out of method
Operations
- Arithmetic
– 8%2 equals 0
– Increment: ++ : a =a+1
– Decrement:– : a=a-1 - Comparison
– &&是相乘,全对才是对
– ||是相加,一个对就是对– &,,^二进制运算符 - Logical
- Concatenation
++a 先自加1,再计算 a++先计算,再自加1
Switch
- 如果case内没有break,会一直执行下去
Looping
While
– Initialization
– Condition
– Increment/decrementDo while:和while的区别,即使没有判断,也会先执行一次
- for
array的写法
- blocks of memory
- int[] mark = {1,2,3,4,5};
- int[] mark = new int[5];
class
- user defined data type
- new: dynamic memory location
Constructor
- Used for Initial class
Value
- Class value: has “static”, outside of method
- Instance value: has no “static”, outside of method
- Local: inside the method, destroyed after finish the method
- Block
Program segment
- Static
″ Local variables, block - Static
– Static variables - Heap: Dynamic
– Everything created by using the word “new”
AAA a = new AAA0;
- A is local viable
- New AAA() is in heap
- C obj = new C();
– obj: Reference Variable
– new C(): object
Variables should be private
- Data should be private; public is simple, but public is dangerous
- Method can be public
This
- Current object
Block
- Static block will runs before “main”
Heap and stack
- If I want to find something in heap,
I must search in stack for its address.
java的基本概念
- Encapsulation:封装
- abstraction :抽象
- inheritance:继承: is-a父子继承关系
– single level
– multi-level
– hierarchical: several children - polymorphism :多型
– compile time:overloading
– method overloading - public void sum(int i){}
- public void sum(){}
– constructor overloading - public sum(){}
- public sum(int i){}
– runtime
– Parent obj = new C1;// obj can store any child of parent; 工厂模式的一种
符号
- -:private
- +:public
- #:protected
– 只有继承的子class才可以访问
Stack 表现
- Compile,从子类到父类,执行,从父类到子类
Super(i)
- 可以调用parent class的properties
- 如果父类和子类有相同方法或是属性,父类被覆写
Overridden
- 方法入力相同,出力相同
Final
- Final variable: unable to change
- Final method: unable to override
- Final class: unable to inherit
Abstract
- May have variable
- May have abstract method and normal method
Interface
- Pure abstract class
- Variables: static, final
- Method: abstract method
Composition
- Car <- engine
关系
- is a,是这个类的一种,继承
– implement, abstract class - has a, 含有这个类,包含
– public e
collection
- arrarylist: 效率低
- linkedlist: 效率高
- Collection是一个接口
- List和Set都是接口,它们继承于Collection。
– List是有序的队列,List中可以有重复的元素;
– 而Set是数学概念中的集合,Set中没有重复元素! - List和Set都有它们各自的实现类。
List arraylist = new ArrayList(5);
- List : interface
– ArrayList
– LinkedList
Collection
- Set
– HashSet
– LinkedSet - List
– Arraylist
– Linkedlist
Map
- HashMap
– Map
Ensure
- testing
assure
- exception
Throwable
- Error
– Stack over follow - Exception
– Checked exception
– Unchecked exception
–Finally: release memory
Checked & unchecked
- RuntimeException和他的子类都是unchecked异常。
- 其他的都是checked异常。
– 在编译阶段,编译器会检查每一个方法,看是否方法里面抛出了checked异常。
– 假设抛出了checked异常,那个方法里必须加catch,或者加throws语句(下一节讲解),否则的话编译器会报错。
– unchecked异常就没这规矩。
Throwable类是所有异常的始祖,它有两个直接子类Error / Exception:
- Error
– 仅在Java虚拟机中发生动态连接失败或其它的定位失败的时候抛出一个Error对象。一般程序不用捕捉或抛出Error对象。
Exception
- Unchecked Exception:
– a. 指的是程序的瑕疵或逻辑错误,并且在运行时无法恢复。
– b. 包括Error与runtime Exception及其子类,如:OutOfMemoryError, UndeclaredThrowableException, IllegalArgumentException, IllegalMonitorStateException, NullPointerException, IllegalStateException, IndexOutOfBoundsException, Arithmetic Exception.
– c. 语法上不需要声明抛出异常。 - Checked Exception:
– a. 代表程序不能直接控制的无效外界情况(如用户输入,数据库问题,网络异常,文件丢失等)
– b. 除了Error和Runtime Exception及其子类之外,如:ClassNotFoundException, NamingException, ServletException, SQLException, IOException等。
– c. 需要try catch处理或throws声明抛出异常。
测试
SME
- Plan -> analysis -> design -> build -> test -> deploy
Tests
- Unit testing (developer)
- Integration/ assembly testing
- Performance testing
- Product testing
- User acceptance testing
- Operational readies testing( deploy team)
Junit
Database
- RDBMS: Relational database management system
- DBMS: DataBase Management System
Query language
- DDL: data definition language
″ Create, drop, truncate - DML: Data Manipulation language
″ Insert, update, delete - TCL: transaction control language
″ Rollback, commit - Data retrieval
″ select
datatype for DB
- NUMBER(n,[d])
- Date: 24-Mar-2009
- TIME: 11:20:23
- TIMESTAMP: YYYY-MM-DD HH:MM:SS
- BLOB: binary
ACID事物的特性
事务是指对系统进行的一组操作,为了保证系统的完整性,事务需要具有ACID特性,具体如下:
- 是指数据库管理系统(DBMS)在写入/更新资料的过程中,为保证事务(transaction)是正确可靠的,所必须具备的四个特性:
″ 原子性(atomicity,或称不可分割性)、
″ 一致性(consistency)
″ 隔离性(isolation,又称独立性)、
″ 持久性(durability)。
- 原子性:一个事务(transaction)中的所有操作,要么全部完成,要么全部不完成,不会结束在中间某个环节。事务在执行过程中发生错误,会被回滚(Rollback)到事务开始前的状态,就像这个事务从来没有执行过一样。
- 一致性:在事务开始之前和事务结束以后,数据库的完整性没有被破坏。这表示写入的资料必须完全符合所有的预设规则,这包含资料的精确度、串联性以及后续数据库可以自发性地完成预定的工作。
- 隔离性:当两个或者多个事务并发访问(此处访问指查询和修改的操作)数据库的同一数据时所表现出的相互关系。事务隔离分为不同级别,包括读未提交(Read uncommitted)、读提交(read committed)、可重复读(repeatable read)和串行化(Serializable)。
- 持久性:在事务完成以后,该事务对数据库所作的更改便持久地保存在数据库之中,并且是完全的。
Primary key
- 不能重复
- 不能为空
- 只能有一个primary key
Alias
- Employee e
- e.userId = ..
Statement stmt = conn.createStatement();
- stmt.execute
″ Excute: true/false
″ ExcuteUpdate: int of line
″ ExcuteQuery: ResultSet only for SELECT
prepareStatement
Html
Html: static web page
JavaScript: Dynamic web page
CSS: 层叠样式表Cascading Style Sheets
Get method will go through URL, post method will not
Html table
- Tr: table row
- Th: table header
- Td: table data
JavaScript
Datatype: Only var in JavaScript
CSS
CSS must be in head section
Enterprise Architecture
One class has only one responsibility
Ties: different locations
- Layers: logical separation
XSLT
- 可扩展样式表转换语言(英语:Extensible Stylesheet Language Transformations,缩写XSLT)是一种对XML文档进行转化的语言,
- XSLT中的T代表英语中的“转换”(transformation)。它是XSL(Extensible stylesheet language)规范的一部分。XSL规范的另外一部分
Servlet
Apache tomcat
Servlet engine
Life cycle
- Instantiation: object creation
- Initialization: init()
– Only one time - Service: service()
– Can many times - Destroy: destroy()
– Only one time
Copy connecter to WebContent->Web –inf->lib
Out.print 可以打印到html
JSP
Java code in web page
<%-- This is JSP comment --%>
<%! Declaration %>
<%= expansion %>
<% Java Code %>
java bean
A class with var, constructor, get/do
Spring
DI: dependency injection
- Setter: setter injection
- 或者是构造体: constructor injection
Spring MVC
- Model: communicate with DB
- View: JSP
- controller
- MVC is middleware connecting frontend and backend