【注意】读取文件为流文件可用用new FileInputStream("product.xml"), 而不用new FileInputStream(new File("product.xml"), 文件必须放在classpath下面才能找到
- Locale defaultLocale = Locale.getDefault();
- //Locale defaultLocale = new Locale("en","US");
- ResourceBundle rb = ResourceBundle.getBundle("res/MessagesBundle", defaultLocale);
- //ResourceBundle rb = ResourceBundle.getBundle("res.MessagesBundle", defaultLocale);
- System.out.println(rb.getString("msg0"));
- boolean[] flags = { true, true, true, true, false };
- boolean result = true;
- for (int i = 0; i < flags.length; i++) {
- result &= flags[i];
- }
- System.out.println(result);
- (版本1)
- public static int getIntervalDays(Date fDate, Date oDate) {
- if (null == fDate || null == oDate) {
- return -1;
- }
- long intervalMilli = oDate.getTime() – fDate.getTime();
- return (int) (intervalMilli / (24 * 60 * 60 * 1000));
- }
- (版本2)
- public static int daysOfTwo(Date fDate, Date oDate) {
- Calendar aCalendar = Calendar.getInstance();
- aCalendar.setTime(fDate);
- int day1 = aCalendar.get(Calendar.DAY_OF_YEAR);
- aCalendar.setTime(oDate);
- int day2 = aCalendar.get(Calendar.DAY_OF_YEAR);
- return day2 – day1;
- }
- class aa{
- class kk{
- class gg{
- int tt=100;
- public void a(){
- System.out.println("a");
- }
- }
- }
- public static void main(String[] args){
- kk k = new aa().new kk();
- kk.gg g = new aa().new kk().new gg();
- }
- }
- class Person implements Cloneable{ // 实现Cloneable接口表示可以被克隆
- private String name ;
- public Person(String name){
- this.name = name ;
- }
- public void setName(String name){
- this.name = name ;
- }
- public String getName(){
- return this.name ;
- }
- public String toString(){
- return "姓名:" + this.name ;
- }
- public Object clone()
- throws CloneNotSupportedException
- {
- return super.clone() ; // 具体的克隆操作由父类完成
- }
- };
- public class CloneDemo01{
- public static void main(String args[]) throws Exception{
- Person p1 = new Person("张三") ;
- Person p2 = (Person)p1.clone() ;
- p2.setName("李四") ;
- System.out.println("原始对象:" + p1) ;
- System.out.println("克隆之后的对象:" + p2) ;
- }
- };
- import java.util.* ;
- public class ArraysDemo{
- public static void main(String arg[]){
- int temp[] = {3,4,5,7,9,1,2,6,8} ; // 声明一个整型数组
- Arrays.sort(temp) ; // 进行排序的操作
- System.out.print("排序后的数组:") ;
- System.out.println(Arrays.toString(temp)) ; // 以字符串输出数组
- // 如果要想使用二分法查询的话,则必须是排序之后的数组
- int point = Arrays.binarySearch(temp,3) ; // 检索位置
- System.out.println("元素‘3’的位置在:" + point) ;
- Arrays.fill(temp,3) ;// 填充数组
- System.out.print("数组填充:") ;
- System.out.println(Arrays.toString(temp)) ;
- }
- };
- import java.util.* ;
- class House extends Observable{ // 表示房子可以被观察
- private float price ;// 价钱
- public House(float price){
- this.price = price ;
- }
- public float getPrice(){
- return this.price ;
- }
- public void setPrice(float price){
- // 每一次修改的时候都应该引起观察者的注意
- super.setChanged() ; // 设置变化点
- super.notifyObservers(price) ;// 价格被改变
- this.price = price ;
- }
- public String toString(){
- return "房子价格为:" + this.price ;
- }
- };
- class HousePriceObserver implements Observer{
- private String name ;
- public HousePriceObserver(String name){ // 设置每一个购房者的名字
- this.name = name ;
- }
- public void update(Observable o,Object arg){
- if(arg instanceof Float){
- System.out.print(this.name + "观察到价格更改为:") ;
- System.out.println(((Float)arg).floatValue()) ;
- }
- }
- };
- public class ObserDemo01{
- public static void main(String args[]){
- House h = new House(1000000) ;
- HousePriceObserver hpo1 = new HousePriceObserver("购房者A") ;
- HousePriceObserver hpo2 = new HousePriceObserver("购房者B") ;
- HousePriceObserver hpo3 = new HousePriceObserver("购房者C") ;
- h.addObserver(hpo1) ;
- h.addObserver(hpo2) ;
- h.addObserver(hpo3) ;
- System.out.println(h) ; // 输出房子价格
- h.setPrice(666666) ; // 修改房子价格
- System.out.println(h) ; // 输出房子价格
- }
- };
- // 完成具体的任务操作
- import java.util.TimerTask ;
- import java.util.Date ;
- import java.text.SimpleDateFormat ;
- class MyTask extends TimerTask{ // 任务调度类都要继承TimerTask
- public void run(){
- SimpleDateFormat sdf = null ;
- sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS") ;
- System.out.println("当前系统时间为:" + sdf.format(new Date())) ;
- }
- };
- import java.util.Timer ;
- public class TestTask{
- public static void main(String args[]){
- Timer t = new Timer() ; // 建立Timer类对象
- MyTask mytask = new MyTask() ; // 定义任务
- t.schedule(mytask,1000,2000) ; // 设置任务的执行,1秒后开始,每2秒重复
- }
- };
优先级
|
运算符
|
结合性
|
1
|
() [] .
|
从左到右
|
2
|
! +(正) -(负) ~ ++ --
|
从右向左
|
3
|
* / %
|
从左向右
|
4
|
+(加) -(减)
|
从左向右
|
5
|
<< >> >>>
|
从左向右
|
6
|
< <= > >=
instanceof
|
从左向右
|
7
|
==
!=
|
从左向右
|
8
|
&(按位与)
|
从左向右
|
9
|
^
|
从左向右
|
10
|
|
|
从左向右
|
11
|
&&
|
从左向右
|
12
|
||
|
从左向右
|
13
|
?:
|
从右向左
|
14
|
= += -= *= /= %= &= |= ^= ~= <<= >>=
>>>=
|
从右向左
|
- package com.alibaba.demo;
- public class Hello{
- public static void main(String[] args){
- System.out.println("hello");
- }
- }