"黑马程序员"其它类
2013-07-05 13:13
176 查看
----- <a href="http://www.itheima.com" target="blank">android培训</a>、<a href="http://www.itheima.com" target="blank">java培训</a>、期待与您交流! ----------
1.日期时间类
package com.oxf.properties;
import java.text.SimpleDateFormat;
import java.util.*;
public class DateDemo {
/**
* @param args
*/
public static void main(String[] args) {
Date d=new Date();
System.out.println(d);//打印时间看不懂需要格式化
//调用format方法让模式格式化指定年月日Date对象
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
String time =sdf.format(d);
System.out.println("time="+time);
//获取单独的年月日
Calendar c=Calendar.getInstance();
System.out.println(c.get(Calendar.YEAR)+"年"+(c.get(Calendar.MONTH)+1)+"月"+c.get(Calendar.DAY_OF_MONTH)+"日");
String [] mons={"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
String[] weeks={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
int index=c.get(Calendar.MONTH);
int index2=c.get(Calendar.DAY_OF_WEEK);
System.out.println(c.get(Calendar.YEAR)+"年");
System.out.println(mons[index]);
System.out.println(weeks[index2-1]);
c.set(2012,2,23);//设置时间
c.add(Calendar.MONTH,2);//当前查找的月份加2可以进行运算
c.add(Calendar.MONTH,-2);
}
}
2.Math类and Random
package com.oxf.properties;
import java.util.Random;
public class MathDemo {
/**
* @param args
*/
public static void main(String[] args) {
//随机
Random r=new Random();
r.nextInt(10);
double d=Math.ceil(12.34);//ceil返回大于指定数据的最小整数
double d2=Math.floor(12.34);//跟ceil相反
long l=Math.round(12.23);//四舍五入
Math.pow(2, 3);//2为底数3为指数
//随机数
for (int i = 0; i < 10; i++) {
//1到10随机
int dr=(int)(Math.random()*10+1);
System.out.println(dr);
}
System.out.println("d:"+d);
System.out.println("d2:"+d2);
System.out.println("l:"+l);
}
}
3.runtime
package com.oxf.properties;
import java.io.IOException;
public class RuntimeDemo {
/**
* Runtime对象
* 该类中并没有提供构造函数
* 说明不可以new对象,那么可以直接想到该类中的方法都是静态的
* 发现该类中还有非静态方法
* 说明该类肯定会提供了方法获取本类对象,而且该方法是静态的并返回值类型是本类类型
* 该方式是static Runtime getRuntime();
* 想到单例模式
* @throws Exception
*/
public static void main(String[] args) throws Exception {
Runtime r=Runtime.getRuntime();
Process p=r.exec("notepad.exe SystemDemo.java");
//可以打开记事本,java文件等,,,
Thread.sleep(4000);
p.destroy();
}
}
4.System
package com.oxf.properties;
import java.util.Properties;
public class SystemDemo {
/**
* System
* 描叙系统一些信息
* 获取系统属性信息:Properties getProperties();
*/
public static void main(String[] args) {
Properties prop=System.getProperties();
//因为Perperties是Hashtable的子类,也就是Map集合的一个子类对象
//那么可以通过map的方法去除该集合中的元素
//该集合中存储都是字符串,没有泛型定义。
//如何在系统中自定义一些信息呢?
System.setProperty("mykey","myvalue");
//获取指定属性信息
String value=System.getProperty("os.name");
System.out.println("value="+value);
//可不可以在jvm启动时动态加载一些属性信息呢?
String v=System.getProperty("haha");
System.out.print("v="+v);
//获取所有属性信息
for(Object obj:prop.keySet()){
String value1=(String)prop.get(obj);
System.out.println(obj+"::"+value1);
}
}
}
5.Object类
toString()
equals();
hashCode()
6.字符串类
int length();//返回字符串长度
char charAt(int index)//返回指定索引处的char值
int compareTo(String another)//于0比较Unicode码值的大小
String concat(String str)
equals(Object obj)//判断字符串是否相等
int indexOf(int ch)返回字符串在第一次出现的位置
String toUpperCase()//将所有字符改为大小
String substring(int beginIndex)返回一个从指定索引处的字符开始直到此字符串的末尾的新字符串
String subString(int beginIndex,int endIndex)返回一个从beginIndex开始到endIndex-1处的字符串
Static String valueOf();把基本数据类型转换为String类型
String[] split(String regex)将一个字符串按照指定分割符分隔
trim()去掉两边的空格
----- <a href="http://www.itheima.com" target="blank">android培训</a>、<a href="http://www.itheima.com" target="blank">java培训</a>、期待与您交流! ----------
1.日期时间类
package com.oxf.properties;
import java.text.SimpleDateFormat;
import java.util.*;
public class DateDemo {
/**
* @param args
*/
public static void main(String[] args) {
Date d=new Date();
System.out.println(d);//打印时间看不懂需要格式化
//调用format方法让模式格式化指定年月日Date对象
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
String time =sdf.format(d);
System.out.println("time="+time);
//获取单独的年月日
Calendar c=Calendar.getInstance();
System.out.println(c.get(Calendar.YEAR)+"年"+(c.get(Calendar.MONTH)+1)+"月"+c.get(Calendar.DAY_OF_MONTH)+"日");
String [] mons={"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
String[] weeks={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
int index=c.get(Calendar.MONTH);
int index2=c.get(Calendar.DAY_OF_WEEK);
System.out.println(c.get(Calendar.YEAR)+"年");
System.out.println(mons[index]);
System.out.println(weeks[index2-1]);
c.set(2012,2,23);//设置时间
c.add(Calendar.MONTH,2);//当前查找的月份加2可以进行运算
c.add(Calendar.MONTH,-2);
}
}
2.Math类and Random
package com.oxf.properties;
import java.util.Random;
public class MathDemo {
/**
* @param args
*/
public static void main(String[] args) {
//随机
Random r=new Random();
r.nextInt(10);
double d=Math.ceil(12.34);//ceil返回大于指定数据的最小整数
double d2=Math.floor(12.34);//跟ceil相反
long l=Math.round(12.23);//四舍五入
Math.pow(2, 3);//2为底数3为指数
//随机数
for (int i = 0; i < 10; i++) {
//1到10随机
int dr=(int)(Math.random()*10+1);
System.out.println(dr);
}
System.out.println("d:"+d);
System.out.println("d2:"+d2);
System.out.println("l:"+l);
}
}
3.runtime
package com.oxf.properties;
import java.io.IOException;
public class RuntimeDemo {
/**
* Runtime对象
* 该类中并没有提供构造函数
* 说明不可以new对象,那么可以直接想到该类中的方法都是静态的
* 发现该类中还有非静态方法
* 说明该类肯定会提供了方法获取本类对象,而且该方法是静态的并返回值类型是本类类型
* 该方式是static Runtime getRuntime();
* 想到单例模式
* @throws Exception
*/
public static void main(String[] args) throws Exception {
Runtime r=Runtime.getRuntime();
Process p=r.exec("notepad.exe SystemDemo.java");
//可以打开记事本,java文件等,,,
Thread.sleep(4000);
p.destroy();
}
}
4.System
package com.oxf.properties;
import java.util.Properties;
public class SystemDemo {
/**
* System
* 描叙系统一些信息
* 获取系统属性信息:Properties getProperties();
*/
public static void main(String[] args) {
Properties prop=System.getProperties();
//因为Perperties是Hashtable的子类,也就是Map集合的一个子类对象
//那么可以通过map的方法去除该集合中的元素
//该集合中存储都是字符串,没有泛型定义。
//如何在系统中自定义一些信息呢?
System.setProperty("mykey","myvalue");
//获取指定属性信息
String value=System.getProperty("os.name");
System.out.println("value="+value);
//可不可以在jvm启动时动态加载一些属性信息呢?
String v=System.getProperty("haha");
System.out.print("v="+v);
//获取所有属性信息
for(Object obj:prop.keySet()){
String value1=(String)prop.get(obj);
System.out.println(obj+"::"+value1);
}
}
}
5.Object类
toString()
equals();
hashCode()
6.字符串类
int length();//返回字符串长度
char charAt(int index)//返回指定索引处的char值
int compareTo(String another)//于0比较Unicode码值的大小
String concat(String str)
equals(Object obj)//判断字符串是否相等
int indexOf(int ch)返回字符串在第一次出现的位置
String toUpperCase()//将所有字符改为大小
String substring(int beginIndex)返回一个从指定索引处的字符开始直到此字符串的末尾的新字符串
String subString(int beginIndex,int endIndex)返回一个从beginIndex开始到endIndex-1处的字符串
Static String valueOf();把基本数据类型转换为String类型
String[] split(String regex)将一个字符串按照指定分割符分隔
trim()去掉两边的空格
----- <a href="http://www.itheima.com" target="blank">android培训</a>、<a href="http://www.itheima.com" target="blank">java培训</a>、期待与您交流! ----------
相关文章推荐
- "黑马程序员" Eclipse的基本使用
- "黑马程序员"运算符的概述
- Dr. Com 用户认证程序 "其它程序占用控制端口, 请退出重新再试!(1)" 问题的一种解决方法
- 正则表达式:匹配字符串中除了"abc"以外的所有其它部分
- 黑马程序员 null 和""的区别
- "黑马程序员"代理的概念、作用
- 黑马程序员-----java基础01第一个应用程序 "HelloWorld"
- "黑马程序员"基础测试:创建ArrayList对象,添加五个元素,使用Iterator遍历输出
- 好几条记录只是仓位及数量不同,其它内容都一样,现在要显示出一条来,仓位及数量用"/"分开
- "黑马程序员"面向对象的初步了解
- "黑马程序员"交通灯笔记
- "黑马程序员"java增强笔记
- "黑马程序员"算法大全
- Firefox浏览器自带"阻止此页面创建其它对话框"设置为不显示
- "黑马程序员"银行调度系统
- "黑马程序员"类加载器及其委托机制
- 商刊:SAP反击,甲骨文夸大自己放"卫星"
- javascript 中 "!function(){}() " 是什么意思?
- SQL1117N 由于 ROLL-FORWARD PENDING,不能连接或激活数据库 "EBILL"。
- "" is not equal to '' in query