传智博客课堂学习笔记3.26
2009-04-16 21:34
405 查看
192.168.0.200
传智博客课堂学习笔记3.26
JAVA基础
1、注解
2、反射(读写field和属性,调用method,获取泛型和注解,构建对象)
Employee emp = new Employee();//正向调用
Class cs = Class.forName("cn.itcast.Servlet");
Servlet s =(Servlet)cs.newInstance();//调用默认构造器
s.delete();//反向调用
通过反射技术获取构造器
import java.lang.reflect.Constructor;
Class cs = Class.forName("cn.itcast.Servlet");
Constructor con = cs.getConstructor(String.class,Integer.class);//只能获取public的构造函数(getDeclaredConstructor:可以得到private,protected,public,friendly的构造函数)
//.class用来取得类型
constructor.setAccessible(true);//允许访问private的构造方法
Servlet b=(Servlet)con.newInstance(参数);
b.delete();//反向调用
public class PersonServiceBean {
public Integer id;
}
public class Tu {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
PersonServiceBean personServiceBean1 = new PersonServiceBean();
PersonServiceBean personServiceBean2 = new PersonServiceBean();
personServiceBean1.id=23;
personServiceBean2.id=22;
try {
Class clazz = Class.forName("cn.itcast.PersonServiceBean");
//Class clazz = personServiceBean1.getClass();
Field field = clazz.getField("id");
System.out.println(field.get(personServiceBean1));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
3、泛型
4、可变参数
Integer... ids
5、增强for循环 迭代数组、集合
String[] ids =new String[]{"first","second"};
for(Integer s : ids)
6、代理(设计模式),classLoader
7、静态引入
import static java.lang.System.out;
public static void main(String[] args){
out.println("xx");
}
System.out.println = out.println;
Eclipse,ctrl+单击out,即可查看out具体内容
8、枚举
装箱、拆箱(JDK1.5以上)
?具体作用?
基本类型到对象类型 装箱
对象类型到基本类型,拆箱
Integer [] s2 = new Integer[]{1,2};
int a = new Integer(5);
讲解:
Integer b = new Integer(9);
int i = b;//拆箱
Integer b;
int i=5;
b=i;//装箱
数组定义:
Integer[] array = new Integer[]{1,2,3};
Integer[] array = new Integer[2];
array[0]=4;
array[1]=5;
class首字母大写
9、内省(Introspector)
内省的方式得到JAVABEAN的属性,并通过反射的方法修改??
import java.beans.Introspector;
import java.beans.BeanInfo;
属性,大小写问题
字段和属性
public static void main(String[] args) {
PersonServiceBean ss1 = new PersonServiceBean();
PersonServiceBean ss2 = new PersonServiceBean();
try {
Class clazz = Class.forName("cn.itcast.PersonServiceBean");
BeanInfo beanInfo = Introspector.getBeanInfo(clazz);//得到javabean的内部结构信息
PropertyDescriptor[] ps = beanInfo.getPropertyDescriptors();//得到所有的属性描述
for(PropertyDescriptor p : ps){
if("ID".equals(p.getName())){
System.out.println(p.getPropertyType());//获取属性的类型
Method setter = p.getWriteMethod();
if(setter!=null) setter.invoke(ss1, 4);
Method getter = p.getReadMethod();
if(getter!=null) {
Object value = getter.invoke(ss1);
System.out.println(value);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Method ??
第一天上课。感觉黎老师的讲课深入浅出,同时很有耐心。
一天下来收获不小,参加培训的好处就是在遇到问题时能够及时询问。
传智博客课堂学习笔记3.26
JAVA基础
1、注解
2、反射(读写field和属性,调用method,获取泛型和注解,构建对象)
Employee emp = new Employee();//正向调用
Class cs = Class.forName("cn.itcast.Servlet");
Servlet s =(Servlet)cs.newInstance();//调用默认构造器
s.delete();//反向调用
通过反射技术获取构造器
import java.lang.reflect.Constructor;
Class cs = Class.forName("cn.itcast.Servlet");
Constructor con = cs.getConstructor(String.class,Integer.class);//只能获取public的构造函数(getDeclaredConstructor:可以得到private,protected,public,friendly的构造函数)
//.class用来取得类型
constructor.setAccessible(true);//允许访问private的构造方法
Servlet b=(Servlet)con.newInstance(参数);
b.delete();//反向调用
public class PersonServiceBean {
public Integer id;
}
public class Tu {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
PersonServiceBean personServiceBean1 = new PersonServiceBean();
PersonServiceBean personServiceBean2 = new PersonServiceBean();
personServiceBean1.id=23;
personServiceBean2.id=22;
try {
Class clazz = Class.forName("cn.itcast.PersonServiceBean");
//Class clazz = personServiceBean1.getClass();
Field field = clazz.getField("id");
System.out.println(field.get(personServiceBean1));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
3、泛型
4、可变参数
Integer... ids
5、增强for循环 迭代数组、集合
String[] ids =new String[]{"first","second"};
for(Integer s : ids)
6、代理(设计模式),classLoader
7、静态引入
import static java.lang.System.out;
public static void main(String[] args){
out.println("xx");
}
System.out.println = out.println;
Eclipse,ctrl+单击out,即可查看out具体内容
8、枚举
装箱、拆箱(JDK1.5以上)
?具体作用?
基本类型到对象类型 装箱
对象类型到基本类型,拆箱
Integer [] s2 = new Integer[]{1,2};
int a = new Integer(5);
讲解:
Integer b = new Integer(9);
int i = b;//拆箱
Integer b;
int i=5;
b=i;//装箱
数组定义:
Integer[] array = new Integer[]{1,2,3};
Integer[] array = new Integer[2];
array[0]=4;
array[1]=5;
class首字母大写
9、内省(Introspector)
内省的方式得到JAVABEAN的属性,并通过反射的方法修改??
import java.beans.Introspector;
import java.beans.BeanInfo;
属性,大小写问题
字段和属性
public static void main(String[] args) {
PersonServiceBean ss1 = new PersonServiceBean();
PersonServiceBean ss2 = new PersonServiceBean();
try {
Class clazz = Class.forName("cn.itcast.PersonServiceBean");
BeanInfo beanInfo = Introspector.getBeanInfo(clazz);//得到javabean的内部结构信息
PropertyDescriptor[] ps = beanInfo.getPropertyDescriptors();//得到所有的属性描述
for(PropertyDescriptor p : ps){
if("ID".equals(p.getName())){
System.out.println(p.getPropertyType());//获取属性的类型
Method setter = p.getWriteMethod();
if(setter!=null) setter.invoke(ss1, 4);
Method getter = p.getReadMethod();
if(getter!=null) {
Object value = getter.invoke(ss1);
System.out.println(value);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Method ??
第一天上课。感觉黎老师的讲课深入浅出,同时很有耐心。
一天下来收获不小,参加培训的好处就是在遇到问题时能够及时询问。
相关文章推荐
- 传智博客课堂学习笔记3.30
- 传智博客课堂学习笔记3.27
- 传智博客课堂学习笔记3.29
- 第十三周学习笔记(编辑器选错了重发了这一个 原博客的确周天晚上提交了orz)
- 菜鸟必读:RHCE课堂学习笔记(1)
- 我的第一篇博客,记录学习jQuery的笔记
- Bootstrap学习笔记-css布局 Hello_yihao的博客
- 传智博客学习笔记5--JAVA编程基础2.TXT
- 传智博客学习笔记13--JAVA GUI
- 【Lua学习笔记】 Lua中实现面向对象,转自云风的博客
- JAVA学习之-数据库设计及优化_课堂笔记
- ≪统计学习精要(The Elements of Statistical Learning)≫课堂笔记(三)
- Spark MLlib 课堂学习笔记 - 逻辑回归
- 12.14课堂笔记、课后作业、学习心得
- Android 高仿 QQ5.0 侧滑菜单效果 自定义控件来袭【学习鸿洋_视频博客笔记总结】
- Django学习笔记之博客开发(二)
- ≪统计学习精要(The Elements of Statistical Learning)≫课堂笔记(五)
- ≪统计学习精要(The Elements of Statistical Learning)≫课堂笔记(十二)
- ≪统计学习精要(The Elements of Statistical Learning)≫课堂笔记(十九):SVM
- 传智博客佟老师jqurey学习笔记,以及例子代码详细注释。