隐式Intent

相比于显示Intent,隐式Intent则含蓄了很多,它并不明确指出要启动哪一个活动,而是指定了一系列更为抽象的 action 和 category 等信息,然后交由系统去分析这个Intent,并帮我们找出合适的 组件 去启动。

通过<activity>标签下配置<intent-filter>的内容,可以指定activity能够响应的action和category。

<activity android:name=".SecondActivity">
    <intent-filter>
        <action android:name="com.shijiusui.ACTION_START" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

在<action>标签中我们指明了当前activity可以响应com.shijiusui.ACTION_START这个açtion,而<category>标签则包含了一些附加信息,更精确地指明了当前的activity能够响应的Intent中还可能带有的category。

只有<action>和<category>中的内容同时匹配上的Intent,才能启动这个activity。

btn.setOnClickListener(new View.OnClickListener(){
    @Override
    public void onClick(View v){
        Intent intent = new Intent("com.shijiusui.ACTION_START");
        startActivity(intent);
    }
});

可以看到,我们使用了Intent的构造函数,直接将action的字符串传了进去,表明我们想要启动能够响应 com.shijiusui.ACTION_START 这个action的activity。

但前面不是说要<action>和<category>同时匹配上才能响应吗?怎么没看到category呢?

这是因为android.intent.category.DEFAULT是一种默认的category,在调用startActivity()方法的时候会自动将这个category添加到Intent中。


每个Intent中只能指定一个action,却能指定多个category。目前我们的Intent中只有一个默认的category,那么现在再来增加一个吧。

btn.setOnClickListener(new View.OnClickListener(){
    @Override
    public void onClick(View v){
        Intent intent = new Intent("com.shijiusui.ACTION_START");
        intent.addCategory("com.shijiusui.MY_CATEGORY");
        startActivity(intent);
    }
});

可以调用Intent中的addCategory()方法来添加一个category,对应的AndroidMenifest.xml中Activity的<intent-filter>需要添加一个category的声明。

<activity android:name=".SecondActivity">
    <intent-filter>
        <action android:name="com.shijiusui.ACTION_START" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="com.shijiusui.MY_CATEGORY" />
    </intent-filter>
</activity>

:经测试,必须加上android.intent.category.DEFAULT。

使用隐式Intent,我们不仅可以启动自己的程序内的组件,还可以启动其他程序的组件,这使得Android多个应用程序之间的可以共享功能。

事实上,Intent还可以传递Uri对象,通过setData()方法。通过Uri.parse()方法将一个字符串解析为一个Uri对象。

与此对应,我们还可以再<intent-filter>标签中再配置一个<data>标签,用于更精确地指定当前活动能够响应什么类型的数据。<data>标签中主要可以配置以下内容。

  • android:scheme。用于指定数据的协议部分。如http。
  • android:host。用于指定数据的主机名部分。如www.baidu.com。
  • android:port。用于知道你个数据的端口部分,一般紧随主机名之后。
  • android:path。
  • android.mimeType。用于指定可以处理的数据类型,允许使用通配符的方式进行指定。

只有<data>标签中指定的内容和Intent中携带的Data完全一致时,当前组件才能够响应该Intent。
不过一般在<data>标签中都不会指定过多的内容,一般其实只需要指定android:scheme。如指定http,就可以响应所有的http协议的Intent了。

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.baidu.com");
startActivity(intent);
<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="http" />
</intent-filter>

除了http协议外,我们还可以指定很多其他协议,比如geo表示显示地理位置、tel表示拨打电话。

Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:10086");
startActivity(intent);

自定义标签

1). HelloWorld

①. 创建一个标签处理器类: 实现 SimpleTag 接口.
②. 在 WEB-INF 文件夹下新建一个 .tld(标签库描述文件) 为扩展名的 xml 文件. 并拷入固定的部分: 并对
description, display-name, tlib-version, short-name, uri 做出修改

<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
    version="2.0">

  <description>JSTL 1.1 core library</description>
  <display-name>JSTL core</display-name>
  <tlib-version>1.1</tlib-version>
  <short-name>c</short-name>
  <uri>http://java.sun.com/jsp/jstl/core</uri>

</taglib>

③. 在 tld 文件中描述自定义的标签:

<!-- 描述自定义的 HelloSimpleTag 标签 -->
  <tag>
    <!-- 标签的名字: 在 JSP 页面上使用标签时的名字 -->
    <name>hello</name>

    <!-- 标签所在的全类名 -->
    <tag-class>com.atguigu.javaweb.tag.HelloSimpleTag</tag-class>
    <!-- 标签体的类型 -->
    <body-content>empty</body-content>
  </tag>

④. 在 JSP 页面上使用自定义标签:

> 使用 taglib 指令导入标签库描述文件: <%@taglib uri="http://www.atguigu.com/mytag/core" prefix="atguigu" %>

> 使用自定义的标签: <atguigu:hello/> 

2). setJspContext: 一定会被 JSP 引擎所调用, 先于 doTag, 把代表 JSP 引擎的 pageContext 传给标签处理器类.

private PageContext pageContext;

@Override
public void setJspContext(JspContext arg0) {
    System.out.println(arg0 instanceof PageContext);  
    this.pageContext = (PageContext) arg0;
}   

3). 带属性的自定义标签:

①. 先在标签处理器类中定义 setter 方法. 建议把所有的属性类型都设置为 String 类型.

private String value;
private String count;

public void setValue(String value) {
    this.value = value;
}

public void setCount(String count) {
    this.count = count;
}

②. 在 tld 描述文件中来描述属性:

<!-- 描述当前标签的属性 -->
<attribute>
    <!-- 属性名, 需和标签处理器类的 setter 方法定义的属性相同 -->
    <name>value</name>
    <!-- 该属性是否被必须 -->
    <required>true</required>
    <!-- rtexprvalue: runtime expression value 
        当前属性是否可以接受运行时表达式的动态值 -->
    <rtexprvalue>true</rtexprvalue>
</attribute>

③. 在页面中使用属性, 属性名同 tld 文件中定义的名字.

<atguigu:hello value="${param.name }" count="10"/>

4). 通常情况下开发简单标签直接继承 SimpleTagSupport 就可以了. 可以直接调用其对应的 getter 方法得到对应的 API

public class SimpleTagSupport implements SimpleTag{

    public void doTag() 
        throws JspException, IOException{}

    private JspTag parentTag;

    public void setParent( JspTag parent ) {
        this.parentTag = parent;
    }

    public JspTag getParent() {
        return this.parentTag;
    }

    private JspContext jspContext;

    public void setJspContext( JspContext pc ) {
        this.jspContext = pc;
    }

    protected JspContext getJspContext() {
        return this.jspContext;
    }

    private JspFragment jspBody;

    public void setJspBody( JspFragment jspBody ) {
        this.jspBody = jspBody;
    }

    protected JspFragment getJspBody() {
        return this.jspBody;
    }   
}

相对路径和绝对路径

1). 为什么要解决相对路径的问题: 在有一个 Servlet 转发页面的情况下, 会导致相对路径的混乱.

a.jsp: <a href="ToBServlet">To B Page2</a>
ToBServlet: request.getRequestDispatcher(“/dir/b.jsp”).forward(request, response);

注意, 此时点击 To B Page2 超链接后的浏览器的地址栏的值: http://localhost:8989/day_36/ToBServlet, 实际显示的是
dir 路径下的 b.jsp

而 b.jsp 页面有一个超链接: <a href="c.jsp">TO C Page</a>. 默认情况下, c.jsp 应该和 b.jsp 在同一路径下. 此时点击超链接
将在浏览器地址栏显示: http://localhost:8989/day_36/c.jsp. 但在根目录下并没有 c.jsp, 所以会出现路径混乱的问题.

2). 使用绝对路径会解决以上的问题:

绝对路径: 相对于当前 WEB 站点根目录的路径.

http://localhost:8989/day_36/c.jsp: http://localhost:8989/ 是 WEB 站点的根目录, /day_36 是 contextPath,
/c.jsp 是相对于当前 WEB 应用的一个文件路径. 我们需要在当前 WEB 应用的任何的路径下都添加上 contextPath, 即可.

比如:
<a href="ToBServlet">To B Page2</a> 需改为: <a href="<%= request.getContextPath() %>/ToBServlet">To B Page2</a>
response.sendRedirect("a.jsp"); 需改为: response.sendRedirect(request.getContextPath() + "/a.jsp");
<form action="AddServlet"></form> 需改为: <form action="<%= request.getContextPath() %>/AddServlet"></form>

3). 在 JavaWEB 应用中 / 代表的是: 有时代表当前 WEB 应用的根目录, 有时代表的是站点的根目录.

/ 代表的是当前 WEB 应用的根路径: 若 / 所在的命令或方法需被 WEB 服务器解析, 而不是直接打给浏览器, 则 / 代表 WEB 应用的根路径. 此时编写
绝对路径就不需要在添加 contextPath 了.
在 web.xml 文件中做 Serlvet 映射路径时,
在请求转发: request.getRequestDispatcher(“/dir/b.jsp”).forward(request, response);

/ 代表的是站点的根目录: 若 / 直接交由浏览器解析, / 代表的就是站点的根路径, 此时必须加上 contextPath
<form action="/AddServlet"></form>
response.sendRedirect("/a.jsp");

4). 如何获取 contextPath:
ServletContext: getContextPath()
HttpServletRequest: getContextPath()

Session

1. Session 的创建和销毁

page 指定的 session 属性:

1). 默认情况下, 第一次访问一个 WEB 应用的一个 JSP 页面时, 该页面都必须有一个和这个请求相关联的 Session 对象.
因为 page 指定的 session 属性默认为 true

2). 若把 session 属性改为 false, JSP 页面不会要求一定有一个 Session 对象和当前的 JSP 页面相关联
所以若第一次访问当前 WEB 应用的 JSP 页面时, 就不会创建一个 Session 对象.

3). 创建一个 Session 对象: 若 page 指定的 session 设置为 false 或 在 Servlet 中可以通过以下 API 获取 Session 对象.

request.getSession(flag): 若 flag 为 true, 则一定会返回一个 HttpSession 对象, 如果已经有和当前 JSP 页面关联的 HttpSession
对象, 直接返回; 如果没有, 则创建一个新的返回. flag 为 false: 若有关联的, 则返回; 若没有, 则返回 null

request.getSession(): 相当于 request.getSession(true);

4). Session 对象的销毁:

①. 直接调用 HttpSession 的 invalidate()
②. HttpSession 超过过期时间.

> 返回最大时效: getMaxInactiveInterval() 单位是秒
> 设置最大时效: setMaxInactiveInterval(int interval)
> 可以在 web.xml 文件中配置 Session 的最大时效, 单位是分钟. 

<session-config>
    <session-timeout>30</session-timeout>
</session-config>

③. 卸载当前 WEB 应用.
注意: 关闭浏览器不会销毁 Session!


1. HttpSession 的生命周期:

1). 什么时候创建 HttpSession 对象
①. 对于 JSP: 是否浏览器访问服务端的任何一个 JSP, 服务器都会立即创建一个 HttpSession 对象呢?
不一定。

> 若当前的 JSP 是客户端访问的当前 WEB 应用的第一个资源,且 JSP 的 page 指定的 session 属性值为 false, 

则服务器就不会为 JSP 创建一个 HttpSession 对象;

> 若当前 JSP 不是客户端访问的当前 WEB 应用的第一个资源,且其他页面已经创建一个 HttpSession 对象,

则服务器也不会为当前 JSP 页面创建一个 HttpSession 对象,而回会把和当前会话关联的那个 HttpSession 对象返回给当前的 JSP 页面.

②. 对于 Serlvet: 若 Serlvet 是客户端访问的第一个 WEB 应用的资源,
则只有调用了 request.getSession() 或 request.getSession(true) 才会创建 HttpSession 对象

2). page 指令的 session=“false“ 到底表示什么意思?

> 当前 JSP 页面禁用 session 隐含变量!但可以使用其他的显式的 HttpSession 对象

3). 在 Serlvet 中如何获取 HttpSession 对象?

> request.getSession(boolean create): 
create 为 false, 若没有和当前 JSP 页面关联的 HttpSession 对象, 则返回 null; 若有, 则返回 true 
create 为 true, 一定返回一个 HttpSession 对象. 若没有和当前 JSP 页面关联的 HttpSession 对象, 则服务器创建一个新的
HttpSession 对象返回, 若有, 直接返回关联的. 

> request.getSession(): 等同于 request.getSession(true)

4). 什么时候销毁 HttpSession 对象:

①. 直接调用 HttpSession 的 invalidate() 方法: 该方法使 HttpSession 失效

②. 服务器卸载了当前 WEB 应用.

③. 超出 HttpSession 的过期时间.

> 设置 HttpSession 的过期时间: session.setMaxInactiveInterval(5); 单位为秒

> 在 web.xml 文件中设置 HttpSession 的过期时间: 单位为 分钟. 

<session-config>
    <session-timeout>30</session-timeout>
</session-config>

④. 并不是关闭了浏览器就销毁了 HttpSession.

2. 使用绝对路径:使用相对路径可能会有问题, 但使用绝对路径肯定没有问题.

1). 绝对路径: 相对于当前 WEB 应用的路径. 在当前 WEB 应用的所有的路径前都添加 contextPath 即可.

2). / 什么时候代表站点的根目录, 什么时候代表当前 WEB 应用的根目录

若 / 需要服务器进行内部解析, 则代表的就是 WEB 应用的根目录. 若是交给浏览器了, 则 / 代表的就是站点的根目录
若 / 代表的是 WEB 应用的根目录, 就不需要加上 contextPath 了.

3. 表单的重复提交

1). 重复提交的情况:
①. 在表单提交到一个 Servlet, 而 Servlet 又通过请求转发的方式响应一个 JSP(HTML) 页面,
此时地址栏还保留着 Serlvet 的那个路径, 在响应页面点击 “刷新”
②. 在响应页面没有到达时重复点击 “提交按钮”.
③. 点击 “返回”, 再点击 “提交”

2). 不是重复提交的情况: 点击 “返回”, “刷新” 原表单页面, 再 “提交”。

3). 如何避免表单的重复提交: 在表单中做一个标记, 提交到 Servlet 时, 检查标记是否存在且是否和预定义的标记一致, 若一致, 则受理请求,
并销毁标记, 若不一致或没有标记, 则直接响应提示信息: “重复提交”

①. 仅提供一个隐藏域: <input type="hidden" name="token" value="atguigu"/>. 行不通: 没有方法清除固定的请求参数.
②. 把标记放在 request 中. 行不通, 因为表单页面刷新后, request 已经被销毁, 再提交表单是一个新的 request.
③. 把标记放在 session 中. 可以!

> 在原表单页面, 生成一个随机值 token
> 在原表单页面, 把 token 值放入 session 属性中
> 在原表单页面, 把 token 值放入到 隐藏域 中.

> 在目标的 Servlet 中: 获取 session 和 隐藏域 中的 token 值
> 比较两个值是否一致: 若一致, 受理请求, 且把 session 域中的 token 属性清除
> 若不一致, 则直接响应提示页面: "重复提交"

4. 使用 HttpSession 实现验证码

1). 基本原理: 和表单重复提交一致:

> 在原表单页面, 生成一个验证码的图片, 生成图片的同时, 需要把该图片中的字符串放入到 session 中. 
> 在原表单页面, 定义一个文本域, 用于输入验证码. 

> 在目标的 Servlet 中: 获取 session 和 表单域 中的 验证码的 值
> 比较两个值是否一致: 若一致, 受理请求, 且把 session 域中的 验证码 属性清除
> 若不一致, 则直接通过重定向的方式返回原表单页面, 并提示用户 "验证码错误"

JSP

1. JSP 指令: JSP指令(directive)是为JSP引擎而设计的,

它们并不直接产生任何可见输出, 而只是告诉引擎如何处理JSP页面中的其余部分。

2. 在目前的JSP 2.0中,定义了page、include 和 taglib这三种指令

3. page 指令:

1). page指令用于定义JSP页面的各种属性, 无论page指令出现在JSP页面中的什么地方,
它作用的都是整个JSP页面, 为了保持程序的可读性和遵循良好的编程习惯, page指令最好是放在整个JSP页面的起始位置。

2). page 指令常用的属性:

①. import 属性: 指定当前 JSP 页面对应的 Servlet 需要导入的类.
<%@page import=”java.text.DateFormat”%>

②. session 属性: 取值为 true 或 false, 指定当前页面的 session 隐藏变量是否可用, 也可以说访问当前页面时是否一定要生成 HttpSession
对象.
<%@ page session=”false” %>

③. errorPage 和 isErrorPage:

> errorPage 指定若当前页面出现错误的实际响应页面时什么. 其中 / 表示的是当前 WEB 应用的根目录. 
<%@ page errorPage="/error.jsp" %> 

> 在响应 error.jsp 时, JSP 引擎使用的请求转发的方式. 

> isErrorPage 指定当前页面是否为错误处理页面, 可以说明当前页面是否可以使用 exception 隐藏变量. 需要注意的是: 若指定 
isErrorPage="true", 并使用 exception 的方法了, 一般不建议能够直接访问该页面. 

> 如何使客户不能直接访问某一个页面呢 ? 对于 Tomcat 服务器而言, WEB-INF 下的文件是不能通过在浏览器中直接输入地址的方式
来访问的. 但通过请求的转发是可以的!

> 还可以在 web.xml 文件中配置错误页面: 
    <error-page>
    <!-- 指定出错的代码: 404 没有指定的资源, 500 内部错误. -->
        <error-code>404</error-code>
        <!-- 指定响应页面的位置 -->
        <location>/WEB-INF/error.jsp</location>
    </error-page>

    <error-page>
        <!-- 指定异常的类型 -->
        <exception-type>java.lang.ArithmeticException</exception-type>
        <location>/WEB-INF/error.jsp</location>
    </error-page>

④. contentType: 指定当前 JSP 页面的响应类型. 实际调用的是 response.setContentType(“text/html; charset=UTF-8”);
通常情况下, 对于 JSP 页面而言其取值均为 text/html; charset=UTF-8. charset 指定返回的页面的字符编码是什么. 通常取值为 UTF-8

⑤. pageEncoding: 指定当前 JSP 页面的字符编码. 通常情况下该值和 contentType 中的 charset 一致.

⑥. isELIgnored: 指定当前 JSP 页面是否可以使用 EL 表达式. 通常取值为 false.

3. include 指令: <%@ include file=”b.jsp” %>

1). include 指令用于通知 JSP 引擎在翻译当前 JSP 页面时将其他文件中的内容合并进当前 JSP 页面转换成的 Servlet 源文件中,
这种在源文件级别进行引入的方式称之为静态引入, 当前JSP页面与静态引入的页面紧密结合为一个Servlet。

2). file属性的设置值必须使用相对路径

3). 如果以 / 开头,表示相对于当前WEB应用程序的根目录(注意不是站点根目录),否则,表示相对于当前文件。

4. jsp:incluce 标签:

1). <jsp:include page=”b.jsp”></jsp:include>

2). 动态引入: 并不是像 include 指令生成一个 Servlet 源文件, 而是生成两个 Servlet 源文件, 然后通过一个方法的方式把目标页面包含
进来.

org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, “b.jsp”, out, false);

5. jsp:forward:

1).

<jsp:forward page="/include/b.jsp"></jsp:forward>      

相当于.

<% 
    request.getRequestDispatcher("/include/b.jsp").forward(request, response);
%>

2). 但使用 jsp:forward 可以使用 jsp:param 子标签向 b.jsp 传入一些参数. 同样 jsp:include 也可以使用 jsp:param 子标签.

<jsp:forward page="/include/b.jsp">
    <jsp:param value="abcd" name="username"/>
</jsp:forward>  

OR

<jsp:include page="/include/b.jsp">
    <jsp:param value="abcd" name="username"/>
</jsp:include>

在 b.jsp 页面可以通过 request.getParameter(“username”) 获取到传入的请求参数.

6. 关于中文乱码:

1). 在 JSP 页面上输入中文, 请求页面后不出现乱码: 保证 contentType=”text/html; charset=UTF-8″,
pageEncoding=”UTF-8″ charset 和 pageEncoding 的编码一致, 且都支持中文. 通常建议取值为UTF-8

    还需保证浏览器的显示的字符编码也和请求的 JSP 页面的编码一致. 

2). 获取中文参数值: 默认参数在传输过程中使用的编码为 ISO-8859-1

①. 对于 POST 请求: 只要在获取请求信息之前(在调用 request.getParameter 或者是 request.getReader 等),
调用 request.setCharacterEncoding(“UTF-8″) 即可.

②. 对于 GET 请求: 前面的方式对于 GET 无效. 可以通过修改 Tomcat 的 server.xml 文件的方式.

参照 http://localhost:8989/docs/config/index.html 文档的 useBodyEncodingForURI 属性.
为 Connector 节点添加 useBodyEncodingForURI=”true” 属性即可.

<Connector connectionTimeout="20000" port="8989" protocol="HTTP/1.1" redirectPort="8443" useBodyEncodingForURI="true"/>

位掩码 BitMask

public class Permission {  
    // 是否允许查询,二进制第1位,0表示否,1表示是  
    public static final int ALLOW_SELECT = 1 << 0; // 0001  

    // 是否允许新增,二进制第2位,0表示否,1表示是  
    public static final int ALLOW_INSERT = 1 << 1; // 0010  

    // 是否允许修改,二进制第3位,0表示否,1表示是  
    public static final int ALLOW_UPDATE = 1 << 2; // 0100  

    // 是否允许删除,二进制第4位,0表示否,1表示是  
    public static final int ALLOW_DELETE = 1 << 3; // 1000  

    // 存储目前的权限状态  
    private int flag;  

    /** 重新设置权限 */  
    public void setPermission(int permission) {  
        flag = permission;  
    }  

    /** 添加一项或多项权限 */  
    public void enable(int permission) {  
        flag |= permission;  
    }  

    /** 删除一项或多项权限 */  
    public void disable(int permission) {  
        flag &= ~permission;  
    }  

    /** 是否拥某些权限 */  
    public boolean isAllow(int permission) {  
        return (flag & permission) == permission;  
    }  

    /** 是否禁用了某些权限 */  
    public boolean isNotAllow(int permission) {  
        return (flag & permission) == 0;  
    }  

    /** 是否仅仅拥有某些权限 */  
    public boolean isOnlyAllow(int permission) {  
        return flag == permission;  
    }  
}
// 设置
permission.setPermission(Permission.ALLOW_SELECT | Permission.ALLOW_INSERT);

// 判断
permission. isAllow(Permission.ALLOW_SELECT | Permission.ALLOW_INSERT | Permission.ALLOW_UPDATE)
permission. isOnlyAllow(Permission.ALLOW_SELECT | Permission.ALLOW_INSERT)

Java 反射Api

Annotation:表示注解


AnnotatedElement:表示被注解的元素,所以不是注解。如Class、Constructor、Field、Method、Package。
GenericArrayType:表示数组类型
GenericDeclaration:声明类型变量的所有实体的公共接口
InvocationHandler:是代理实例的调用处理程序实现的接口。(真难理解/(ㄒoㄒ)/~~)
Member:成员(包括字段,方法和构造方法)
ParameterizedType:表示参数化类型
Type:是所有类型的公共接口
TypeVariable:各种类型变量的公共高级接口
WildcardType:表示通配符类型表达式,如?、?extends Number或? super Integer。

AccessibleObject:是Field、Method和Constructor对象的基类
Array:是一个工具类,提供了动态创建和访问Java数组的方法
Constructor: 提供了关于类的单个构造方法的信息以及对它的访问权限
Field
Method
Modifier
Proxy:提供用于创建动态代理类和实例的静态方法,它还是由这些方法创建的所有动态代理类的超类。
ReflectPermission:反射操作的Permission



AnnotatedElement接口是所有程序元素的父接口,所以程序通过反射获取了某个类的AnnotatedElement对象后,程序就可以调用该对象的方法来访问Annotation信息。

getAnnotation(Class): 返回程序元素上存在的、指定类型的注解。
getAnnotations():所有注解
getDeclaredAnnotations():返回自己的所有注解,不包括继承过来的。

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface FruitName {
    String value() default "";
}

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface FruitColor {
    public enum Color{ BULE,RED,GREEN};

    Color fruitColor() default Color.GREEN;
}

Modifier:

native transient volatile synchronized final static protected private public
0 0 0 0 0 0 0 0 0 0
public class MyTest {
    public int a;
    public static int b;
    public static final int c = 0;
    private int d;
}


///////////////////////////////
    public static void main(String[] args) {

        Class<?> clazz = MyTest.class;
        Field[] fields = clazz.getDeclaredFields();

        for (Field field : fields) {

            String name = field.getName();
            int modifierValue = field.getModifiers();
            String modifierStr = Modifier.toString(field.getModifiers());

            String msg = String.format("%s: 0x%08x -> %s", name, modifierValue, modifierStr);

            System.out.println(msg);
        }
    }
a: 0x00000001 -> public
b: 0x00000009 -> public static
c: 0x00000019 -> public static final
d: 0x00000002 -> private

Modifier.isPublic(field.getModifiers());
Modifier.isAbstract(field.getModifiers());

Releasing the Results Publicly

A: Thank you for attending this news press. We’ll communicate with you with the sincere and open attitude. We require your close cooperation to avoid adverse information and consensus.
B: Could you explain the reason for this drug intoxication affair about your product?
A: This is the first time we have experienced this kind of affair. We have established the crisis management team and appointed professionals to investigate this affair. I take this opportunity to pledge that we will find out the cause and give you a satisfied answer.
B: How do you plan to deal with these drugs?
A: We are retracting all the products on a nation wide scale, and informing the hospitals, clinics, drugstores and doctors to stop selling through various channels. Then we’ll cooperate with the investigation of Drug Administration actively to carry out a random inspection within five days and release the results to the public.


A: Nice to meet you, Mr. Guo. I’m the Public Relation Manager of Yangyu Company, and I’m sorry for bothering you for a few minutes.
B: OK, come in please. Have a seat.
A: I’d like to express our sincerely regret for the poisoning event, of which I know you are one of the victims.
B: Oh, that have been done, because this event has been solved quickly and relevant compensation has been issued.
A: It’s a good class for us, from which we knew the quality is the foundation. And after one year’s effort, advanced packing technology has been absorbed, and it is impossible for this kind of thing. So, we’d like to hold a press conference and our board chairman will preside the meeting and notary will participate to this meeting.
B: But what can I do?
A: We’d like you to participate as our eyewitness.

Protesting the Media

A: Excuse me, I demand to meet your editor in chief.
B: That’s me. What can I do for you?
A: I am Su Yu from Future Company. There was a news report about the quality of our products published in your newspaper last Friday. It is unreal, and we protest it.
B: Really? Could you provide some proofs?
A: Sure. Our products have been strictly inspected. And we have the quality report the Inspection Bureau produced.
B: If in that case, I’m sorry for our carelessness. What can we do to redeem your loss?
A: I demand a retraction and an apology in tomorrow’s newspaper.


A: Recently there is much adverse news against our company. So we are here to give this press conference to make a reaction in a sense of responsibility.
B: Recently you have marked the price down by 30%. Does that mean the reduction of the quality of products?
A: It’s not on the map. The reason is that the assets reorganization of company has brought about a reduction in the cost of production, so as to fetch down the price. On the contrary, the quality improves as we import advanced technology. This data may prove what I said.
B: It is said that your company is laying off people. May I doubt it’s due to a crisis in your finance?
A: It is unavoidable to terminate the contract ahead of time with the employees on the basis of the company strategic development. However, it doesn’t mean that we abandon them. In fact, we are organizing these employees to attend training with new skills for reemployment.

Apologizing and Compensating

A: We’d like to have you help straighten out the trouble concerning the goods.
B: OK, can you give me the facts?
A: We have here a copy of the inspection certificate issued by the Commodity Inspection Bureau and a set of photos. The inspection certificate states that the products were found damaged when they were unpacked and the photos taken on the spot back up the findings.
B: Is it due to dampness at sea?
A: Our experts are of the opinion that the damage is not due to the dampness but to poor workmanship. It’s obvious that the manufacturers didn’t strictly observe the proceeding requirements as stipulated in our contract.
B: I’m very sorry for this. I apologize for the mistake we made. It seems that manufacturers have not lived up to the standard in this case. We’ll compensate your loss and replace the defective products with new ones.
A: Thank you for sorting out the matter for us.
B: Thank you for your understanding. We assure you it won’t happen again.


A: Mr. Dyer, our investigation results tell us that the factory party is responsible for the cargo damage. We are so sorry for the inconvenience we brought to you in this matter.
B: In that case, now we can get down to talking about the compensation. We trust you can understand that we expect the compensation for our damaged goods.
A: Certainly. What’s your suggestion?
B: For our losses you should compensate us by 5%, plus the inspection fee. On the basis of the survey report, we register our claim with you for 30,000 dollars.
A: We should be responsible for that. But this is a big number, I have to report this back to the head office. Then we’ll inform you of the result. We’ll solve this as soon as possible and I hope this event won’t affect our relationship.
B: I hope so. We expect to cooperate with you further.

Explaining Cause

A: The October shipment of goods arrived in a worst state. 40% of the goods have become deteriorated. We have to lodge a claim against you for this accident.
B: I’m sorry to hear that, but please listen to our explanation.
A: OK.
B: You see, the damage may be caused by a variety of factors. Our goods are well examined before shipment. We hold the inspection certificate from our Commodity Inspection Bureau which states the consignment was up to the standard for export.
A: How do you explain these damages?
B: The accident bears many explanations, such as the rough handling during the course of transit or unloading, storage in the warehouse, etc.
A: If that’s really the case, whom do you think we must turn to for our claim?
B: The goods were bought on FOB basis. And it was you who booked the shipping space and had the goods insured. So we suggest you approach the shipping company or the insurance company for compensation.


A: Miss Alan, we have found out the reason for the accident after investigation.
B: So, can you tell me what exactly the matter is?
A: I was informed just now that someone in our company has made a mistake in filling your order. Therefore we sent the double amount of man’s shoe beyond expectation. I would apologize to your company on behalf of our company.
B: Can you do anything about the goods mistakenly shipped?
A: We’ll manage to send you the correct goods as quickly as possible. We’ll try our best to make sure that we ship the goods by the end of this month.

Expressing Attitude

A: This is my list of complaints I would appreciate it if you would look over them and solve the problems.
B: Certainly, sir. Thank you for coming directly to me. You can count on me to act on these.
A: Well, I’ve cooperated with your company for many years and I’ve generally been pleased. It’s just the last few months that I’ve had problems.
B: Well, I will definitely do what I can to solve these problems, and improve our service. I’m sure you’ll be satisfied with us.
A: I also hope that we can continue to cooperate.


A: I’m sorry to inform you of this, but we found that there are some faulty materials in the consignment which you have recently shipped to us; And most of the goods were underweight.
B: That’s quite unusual for our company. Maybe there is something wrong.
A: This kind of thing can only happen if the exporting company did not do its job, or was trying to cheat us. I demand a full refund of the amount paid.
B: Please don’t be imprudent. We can find a better way to deal with it. You know that we always do a good job and we never try to cheat our clients. We’ll make a thorough investigation to find out where the responsibility lies.
A: How about our loss?
B: Before the investigation finishes, we can’t promise anything. But if it lies on us, we will compensate your loss according to the contract.

Settling Complaints

A: Customer Service, Joy speaking, may I help you?
B: Yes, I have a complaint to make.
A: Could you tell me what’s the matter?
B: I purchased a computer from your company last week. Unfortunately, I’m not satisfied with it. It has a lot of problems.
A: Would you like to detail the problems?
B: It goes wrong with my Internet connection. I have read the instructions that comes with the computer; but the troubleshooting section was no help. That causes a lot of trouble for me.
A: Take it easy. Is there any way you could bring it in to be checked? If not, our repairman can come to you.
B: OK, the latter will be more convenient for me.
A: OK, could you tell me where you are living?


A: Good morning, madam. I’m the manager of Heng Xin Electronics Corporation. I heard that you are not happy with our products.
B: Yes. The case is too serious to be overlooked; so I decided to come and have a face-to-face talk with you.
A: Just be patient, please. Any criticism on our products is sincerely invited. But how about sitting down and telling me the whole thing first?
B: I must express our disappointment with the quality of the laptops.
A: Quality? Our laptops have been strictly inspected; and we have sent you the samples.
B: They certainly to not match the samples you sent us.
A: Really? In that case, there must be some mistake. Take it easy. I’ll report to the senior and send some professional to check it for you.
B: OK. We’ll wait for you.

Interior Meeting

A: Miss Piao, I want to arrange a meeting of the management team next Wednesday. Can you draft a notice and make some preparations for the meeting?
B: Sure. Can you tell me what the purpose of the meeting is?
A: This meeting is to fix the details for the new product press. Basically we’ll get three issues to decide: firstly the date, secondly the location and finally the conference facilities.
B: I see.
A: The agenda should be prepared before the meeting; and then you should ensure that those entitled to be present are properly informed.
B: OK, how about the documents and the information?
A: All the necessary documents and the information relevant to the meeting should be available, preferably printed and distributed before the meeting.
B: OK, I hope you’ll check it over after I’ve finished the notice.


A: Good morning, let’s call the meeting to order. I’m Su Yu, the dean of the Secretary Department, I’m very glad to hold the meeting.
B: Good morning.
A: We’re here today to discuss the details about the new product press. Any questions?
B: No, go ahead please.
A: I’ve asked Miss Piao to lay out the main points of the agenda. Here’re the handouts.
B: Very good. We can know the process clearly.
A: Then let’s discuss about it, and finally invite the general manager to make a conclusion. Please join me in welcoming the general manager.
C: Good morning, everyone. Please speak plainly.
A: If nobody has anything to add, we can close the meeting.

Senior and Subordinate

A: Miss Li, it has been one month since you came here, what’s your feeling about our company?
B: The colleagues and the uppers are easy-going and we get along well.
A: Do you think what’s the difference between your present job and the former one?
B: What impresses me most here is that everyone is very industrious and friendly, responsible and enterprising.
A: Indeed, that’s why our company is developing fast.
B: Yes, I share the same feeling. That’s why I enjoy working here.
A: On the other hand, it’s only one month, but you are familiar with all the business in our company. Well done.
B: Thank you very much, Mr. Smith. I shall work harder.


A: Have you read my work plan about the new project, sir?
B: Yes, I read it yesterday.
A: Is it what you hoped?
B: Excellent!
A: I hope I’ve mentioned the key points and the possible solutions.
B: I think so. You seem to have covered all the major points. I’ve talked to the general manager about your suggestions. He is very satisfied. You will foot the bill. We’ve decided to have another meeting and you get ready to expound your ideas.
A: OK, I will.

Education in Work

A: Recently you’ve done a very good job.
B: Thank you, I’ll keep on. In fact, I still have much to learn.
A: That’s good. The company is discussing an agenda of developing aboard market. You’d better pay attention to the international trend from now on.
B: Yes, sir.
A: You need to improve your English. It’s important in our field.
B: I’ll keep it in my mind.


A: Excuse me, Mr. Smith, have you read the report I gave you? Would you give some directions about the plan of developing the new product in our firm?
B: I have talked over the plan with the assistant managers. In my opinion, developing the new product is potential and will produce great economic benefit. However, the management strategy and the fund accumulation are not very concrete. In addition, something should be done carefully about the market investigation and the sale forecasting.
A: I see. Thank you. Mr. Smith, we’ll correct and prefect the report according to your advice. By the way, Mr. Smith, I’d like to make a suggestion.
B: Please.
A: I have been thinking about this problem for a long time. You know the domestic market is saturated for our products. I’m wondering why not develop a foreign market.
B: I appreciate your talking to me. You know it’s a little difficult to open aboard market for us at this stage. But I’ll give some thought to it. You could collect the information about the development of the product in other companies abroad.
A: Yes.

Designating Work

A: Good morning, Miss Li. This is the first day for you to work here. I hope you’ll like this job.
B: Good morning, Miss Mary. This is the first time for me to do this kind of work. I’ve got a lot to learn from you.
A: Take it easy. I will give you a brief introduction to the office work. The main task is to handle routine business, such as arranging meetings, meeting visitors, seeing visitors off, assigning work, making plans, sorting out the data, collecting information, and so on. All these affairs are very important. I’m sure you’ll adapt quickly to the work here.
B: I hope so. By the way, Miss Mary, could you please tell me what the specific work is for me?
A: Sorry, I can’t tell you now. After you are familiar with all these jobs, we will discuss the problem.
B: That’s OK.
A: If you have something to say about your work while working, please come out. The people here are very kind.
B: All right, thank you.


A: Come here please, Lisa. I’d like to explain the filing system to you.
B: All right, I’m coming.
A: This is your filing cabinet and all the documents must be filed alphabetically.
B: Yes, I understand.
A: And this is a safe. The confidential files are kept in it. You’ll have the key to it. Please keep in mind that you must be very careful with it.
B: Yes, I will.
A: And one more thing, our boss makes a point of keeping everything in order. So you’d better be careful about this and don’t throw things about. Otherwise, he’ll be mad at you.
B: OK, I’ll bear that in mind. Thanks a lot for what you have told me.

Welcoming New Comer

A: Welcome to our company! You will be a big asset for our company.
B: Thank you. I have been looking forward to meeting you, Mr. Smith.
A: I would like you to call me George, would you? Everybody calls me George in this company. It makes me feel more comfortable.
B: OK, George. It is my first day at work, and I guess I am a little anxious.
A: Don’t worry. I will give you an orientation.
B: Thank you. I am looking forward to starting work and getting to know each of you.
A: No problem. Now, I will show you to your office and then introduce you to everybody.


A: Hello, everybody, may I have your attention, please? I would like to introduce a new colleague, Miss Li.
B: Good morning. My name is Li Shan. I was hired by the Personnel Department and told to report here to work as a secretary.
A: Miss Li graduated from a famous college and has worked for a few years, she is an experienced secretary. Let’s greet with warm applause.
P: Welcome to our group. We hope you will enjoy working here with us.
B: Thank you. I feel so happy to work here. I hope we’ll get along well.

Signing a Contract

A: This is the draft of the sales contract for the watches you are going to buy. Please go over it and see if everything is in order.

B: I have read the draft contract carefully. There is something I want to revise about Clause 8.
A: OK?
B: It’s concerning the payment. Your draft contract says that payment is to be made by D/P. We prefer to have the payment made by L/C through a negotiating bank in France.
A: We’ll take up the matter. OK?
B: OK. What’s the term of this contract?
A: This contract is valid for three years and would run for one year of the trial period. If everything is satisfactory, it could be renewed and extended two years. The contract will become void automatically, if both sides do not agree to renew it when time comes.
B: I understand. There is no question about that.


A: The contract contains basically all we have agreed upon during our negotiations. Anything else you want to bring up for discussion, Mr. Karl?
B: We don’t have any different opinions about the contractual obligations of both parties.
A: I hope this will lead to further business between us.
B: We also hope to further expanding our business with you.
A: Here are the two originals of the contract we prepared.
B: I am already to sign the agreement.
A: Let us sign the contract now. Please sign your name here.
B: I’m glad our negotiation has come to a successful conclusion.
A: We are sure both of us will have a brighter future.

Agency

A: Mr. Allen, we are willing to be your agent in Canada for air conditioners. What’s your opinion?
B: It coincides with our desire.
A: Then, what’s your usual commission rate for your agents?
B: Usually, we give a commission of 6% to our agents.
A: 6% is too low, I think. You see, we have a lot of work to do in promoting the sales, such as advertising on radio or TV, printing booklets, leaflets, catalogues and so on.
B: Don’t worry. We’ll allow you a higher commission rate if your sales score a substantial increase. If you sell 5 million worth of hand-tools annually, we can only allow 6% commission. If the annual turnover exceeds 8 million, you can get 8% commission. What do you think of that?
A: I sounds reasonable. Then how do you pay the commission?
B: We may deduct the commission from the invoice value directly or remit it to you after payment.
A: All right. If it is OK, we would like to sign an agency agreement with you immediately.


A: Thanks for coming. Perhaps you should start by telling us what we are looking for, OK?
B: Yes, what we are looking for mainly is an agent in China to represent us, who can help us with marketing, dealing with any queries from customers, taking customer orders and dealing with any problems.
A: Fine, I see no problem with that. We represent other companies in exactly the same way.
B: Well, I would like to know your market connections, the effectiveness of your sales organization and your technical ability to handle the goods to be marketed.
A: We have more than twenty sales representatives, who are on the road all year around, covering the whole country.
B: Do you have any middlemen or sell direct to the retailers?
A: Through years of effort, we have set up effective channels of distribution and we canvass the retailers directly without any middlemen.
B: To tell you the truth, you’re not the only one who applies for the agent for us in your country. Perhaps you would like to give us some ideas of the terms on which you would be willing to operate as our agent.
A: No problem, We can send you the details in written next week.
B: Very well then. We’ll make our decision and let you know it as soon as possible.