java 框架基础
-------------------
框架这个词算是 比较 贴切的,就像房子的骨架
门和窗让用户自己安装,他们喜欢什么样式款式用户定
★框架和工具类的区别:
工具类被 用户写的类 调用
框架是 调用 用户写的类
那写大师们写框架时,我们可能还在上幼儿园,
大师们也不会知道我们到时候会写出什么样的类来
所以,框架里不可能说用 new来弄一些类的实例,
只能让我们告诉框架 我们写的类叫什么,让框架反射吧!
大师们也不知道我们写出的类会是怎么样的五花八门,
所以,JAVABEAN规范 规定了我们 有默认的无参数构造函数啊.
get set 方法啊.......等等
---------------------
用反射有很大的好处,
对于用户,他们很可能没有javac ,有了也不会用,
但是他们有notepad吧,修改XML properties文件可以吧..
--------------------
config.properties
#className=java.util.ArrayList
className=java.util.HashSet
-----------------------
package com.ncs;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Properties;
public class ReadProperties {
//介绍反射的好处
//比方说我不写死,写一个 米你 框架,接受用户在配置文件里写的类
//配置文件写在 工程目录底下,不是src下 和src兄弟级
public static void main(String[] args) throws Exception {
//load properties file
InputStream is = new FileInputStream("config.properties");
//Properties在java.util.Properties;下,
//这个类有个功能,可以把里面的 键值对 存到硬盘上
//也可以把disk上的很多东西读进来
Properties properties = new Properties();
properties.load(is); //加载了
is.close(); //好习惯
String className = properties.getProperty("className");//良好的命名习惯
//Collection collection = new ArrayList(); 现在不用写死了
Collection collection = (Collection)Class.forName(className).newInstance();
String test = "hubin";
collection.add(test);
collection.add(test);
collection.add(test);
System.out.println(collection.size()); //3 因为在培植文件里是ArrayList
//System.out.println(collection.size()); //1 因为在培植文件里是java.util.HashSet
}
}
分享到:
相关推荐
introduce in english
Java Programming for the Absolute Beginner.pdf
Java A Beginner's Guide(6th) 英文无水印pdf 第6版 pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系...
Fully updated to cover Java Platform, Standard Edition 7 (Java SE 7), Java: A Beginner's Guide, Fifth Edition starts with the basics, such as how to compile and run a Java program, and then discusses...
This book is for anyone who wants to learn computer programming and knows absolutely nothing about it. If you are wondering whether this book is going to teach you how to create amazing applets or ...
Java Programming for the Absolute Beginner
Pentaho 8 Reporting for Java Developers 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Java For Absolute Beginner
java beginner guide,
Java A Beginner’s Guide(7th) 英文epub 第7版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Java A Beginner's Guide(6th) 英文epub 第6版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
黑皮书 Learn Java 8 In a Week_ A Beginner's Guide to Java Programming,新手一个星期学好JAVA,推荐
Java A Beginner's Guide(6th) 英文mobi 第6版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Java A Beginner’s Guide(7th) 英文azw3 第7版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Learn to design and create video games using the Java programming language and the LibGDX software library. Working through the examples in this book, you will create 12 game prototypes in a variety ...
一本适用于java初学者的英文版教材,很全面的介绍了Java的初阶内容。
Java and Algorithmic Thinking for the Complete Beginner 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自...
Java A Programming's guide by Herbert Schildt, 6th edition. The pdf is converted from epub
Python Programming for the Absolute Beginner
Welcome to C# and the world of Windows, Internet and World-Wide-Web programming with Visual Studio and the .NET platform! This book is the second in our new .NET How to Program series, which presents ...