JAVA 的基础类的应用

类型和区别

//String 不可变字符串

// stringBuffer  StringBuilder可变长度 字符串


  stringBuffer  和 StringBuilder区别
  stringBuffer:线程安全
 StringBuilder:非线程安全

常用 方法掌握

String对象

          length()     equals()     toLowerCase()//转为小写     toUpperCase()//转为大写

        

charAt(int index)//返回字符串指定索引处的字符
indexOf(int ch)//返回指定字符串在字符串中第一次出现的位置
lastIndexOf()
substring(int beginIndex)//从  处返回一个新的字符串
substring(int  beginIndex,int  endIndex)
concat(String str)//将指定的字符串连接到末尾
repalce(char old ,char new)
split(String str)//根据指定的字符串来拆分字符串
trim()//返回一个前后不含任何空格的字符串副本
compareTo(String str)//按字母顺序比较两个字符串 相等返回0 

    stringBuffer对象   

    

insert()//在指定位子插入字符
reverse()//反序
delete(int star,int end)
deleteCharAt(int index)
append("")//追加内容

 需要注意的三类 方法:
         *         XXXValue:将包装类型转化 为 基本数据类型
         *         valueOf:将基本数据类型 为 包装类型转化
         *         parseXXX:转换为对应的基本数据类型 

 

 

  math对象

math.abs()
.cbrt()//立方根
.ceil()//返回大于或等于参数的最小值
.floor()//返回最大值
.pow//次幂
random//0.1~1.0之间
sqrt//开方

RunTime对象

//获得一个RunTime实例对象并调用方法

Process  process = RunTime.getRuntime().exec(".txt");

process.destroy//销毁


时间日期日历类

//创建时间对象
		Date nowTime = new Date();
long times = nowTime.getTime();  //毫秒数

//转换为指定的时间格式 yyyy  或者 yy 年
		SimpleDateFormat sdf = new SimpleDateFormat("yy年MM月dd日 HH时mm分ss秒S毫秒")

		//创建 日历对象
		Calendar cl = Calendar.getInstance();
		
		//常用的 方法 + 属性
		System.out.println(cl.get(Calendar.YEAR));	
		System.out.println(cl.get(Calendar.MONTH)+1);
		
		System.out.println(cl.get(Calendar.DAY_OF_MONTH));
		System.out.println(cl.get(Calendar.HOUR));
		System.out.println(cl.get(Calendar.HOUR_OF_DAY));
		System.out.println(cl.get(Calendar.MINUTE));
		System.out.println(cl.get(Calendar.SECOND));
		System.out.println(cl.get(Calendar.MILLISECOND));
		
		//星期的第几天
		System.out.println(cl.get(Calendar.DAY_OF_WEEK));
		System.out.println(cl.get(Calendar.DAY_OF_YEAR));
		
		
		//判断 指定月份的天数
		Calendar cl1 = Calendar.getInstance();
		cl1.set(Calendar.YEAR,2019);
		
		//设置月份(0-11)
		cl1.set(Calendar.MONTH,1); //七月
		
		//获取 当前月份的实际天数
		int maxDayNum = cl1.getActualMaximum(Calendar.DATE);
		System.out.println("maxDayNum==>"+maxDayNum);
		
		
		//获取 指定月份第一天是 星期几
		int firstDayOfWeek = cl1.get(Calendar.DAY_OF_MONTH);
		System.out.println("2019年2月1日是星期:"+(firstDayOfWeek-1));
/
public static <MM月> void main(String[] args) throws ParseException {
		// TODO Auto-generated method stub

		int num1 = 100;

		Integer num2 = new Integer(200);
		Integer num3 = new Integer(100);

		System.out.println("num1,num2    " + (num1 == num2));
		System.out.println("num1,num3    " + (num1 == num3));

		System.out.println(num3.doubleValue());
		System.out.println(Integer.toBinaryString(num1));

		System.out.println("=========================");
		System.out.println(Byte.MAX_VALUE);
		System.out.println(Byte.MIN_VALUE);

		System.out.println(Short.MAX_VALUE);
		System.out.println(Short.MIN_VALUE);

		System.out.println(Integer.MAX_VALUE);
		System.out.println(Integer.MIN_VALUE);

		System.out.println("=========================");

		Date nowTime = new Date();

		System.out.println("Data获取当前日期" + nowTime);

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy年 MM月 dd日 HH小时mm分ss秒");
		SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String nowTimeStr = sdf.format(nowTime);
		System.out.println("nowTimeStr==>" + nowTimeStr);

		Date time1 = sdf1.parse("2019-1-10 5:20:26");
		sdf.format(time1);
		time1.getTime();
		System.out.println("time1==>" + time1);
		System.out.println(sdf.format(time1));
		System.out.println(time1.getTime());

		System.out.println("=========================");

		Calendar catime = Calendar.getInstance();

		System.out.println(catime.get(Calendar.YEAR));
		System.out.println(catime.get(Calendar.MONTH) + 1);
		System.out.println(catime.get(Calendar.DAY_OF_MONTH));

		System.out.println(catime.get(Calendar.HOUR_OF_DAY));
		System.out.println(catime.get(Calendar.MINUTE));
		System.out.println(catime.get(Calendar.SECOND));

		System.out.println(catime.get(Calendar.DAY_OF_WEEK) - 1);
		System.out.println(catime.get(Calendar.DAY_OF_YEAR));

		System.out.println("=========================");

		//
		catime.getTime();
		System.out.println("calendar获取当前日期==>" + catime.getTime());
		String catime1 = sdf1.format(catime.getTime());
		System.out.println("calendar获取当前日期转换后==>  " + catime1);

		Calendar time2 = Calendar.getInstance();
		Calendar time3 = Calendar.getInstance();
		time3.set(2017, 10, 21, 22, 30, 51);
		time3.getTime();
		String Strtime3 = sdf1.format(time3.getTime());

		time2.set(Calendar.YEAR, 2016);
		time2.get(Calendar.YEAR);
		System.out.println("calendar手动设置time2==> " + time2.get(Calendar.YEAR));
		System.out.println("calendar手动设置time3==> " + time3.getTime());
		System.out.println("calendar手动设置time3==> " + Strtime3);

		System.out.println("=========================");
		Calendar nowtime = Calendar.getInstance();
		boolean flag = true;
		do {
			try {
				Thread.sleep(1000);
				nowtime.getTime();
			long timeCha = nowtime.getTimeInMillis() - time3.getTimeInMillis();
			long dsDay = timeCha / (24 * 60 * 60 * 1000);
			long dsHour = timeCha / (60 * 60 * 1000) - dsDay * 24;
			long dsMinute = timeCha / (60 * 1000) - dsDay * 24 * 60 - dsHour * 60;
			long dsSecond = timeCha / 1000 - dsDay * 24 * 60 * 60 - dsHour * 60 * 60 - dsMinute * 60;

			System.out.println("已过了==> " + dsDay + "天" + dsHour + "小时" + dsMinute + "分" + dsSecond + "秒");
            System.out.println(nowtime.getTime());
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} while (flag == false);

	}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值