java jdk1.7新特性 二进制面值 数字变量对下划线 try-with-resourc 捕获多种异常并用改进后的类型 创建泛型时类型推断 环境变量 安全加减

二进制面值
为了开发更加简单,发明了二进制数字
例如:

int a=0b00000001;

一般在前面加上0b,表示二进制数据

数字变量对下划线

long l=133_1232_2435l;

一般用于财务

switch对String的支持
在jdk1.7之后,switch里面的变量可以存放String类型

try-with-resource
用try()把代码块包起来
可以使资源管理自动完成
将一些涉及到资源管理的对象放在try()中,不需要再使用i.close()关闭资源

try(InputStream in=new FileInputStream(new File("d:\\hello.jpeg"))){
        }catch (Exception e) {	
		}

捕获多种异常并用改进后的类型
在处理异常时点击 Add exception to exiting catch clause

public static void main(String[] args)  {
		try {
			InputStream in=new FileInputStream(new File("d:\\hello.jpeg"));
		    byte[] b=new byte[in.available()];
		    in.read(b);    
		} catch (NullPointerException |IOException | ArrayIndexOutOfBoundsException  e ) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
	}

创建泛型时类型推断

List<String> sList=new ArrayList<>();

环境变量
Properties 类主要用来和我们外部的properties文件交互
Properties是map的子类,用来存放 key 和 value
和一个文件 .properties 属性文件配合使用
xml 用来存放不规则的数据,Properties存放一些有规则、不变的数据
存放规则 key=value
将属性文件的数据 一次性写入到properties类中:

Properties prop=new Properties();
InputStream in= PropertiesStudy.class.getClassLoader().getResourceAsStream("jdbc.properties");
//InputStream in=new FileInputStream(new File(System.getProperties().get("java.class.path")+"\\jdbc.properties"));
try {
	 //加载属性文件
	prop.load(in);  
	System.out.println(prop.get("driver"));
	System.out.println(prop.getProperty("url"));
} catch (IOException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();

Jdk1.7 新增了一个全局变量的方法
可以输出有关我们JDK的一切信息:

Properties properties = System.getProperties();
Set<Entry<Object, Object>> entrySet = properties.entrySet();
Iterator<Entry<Object, Object>> iterator = entrySet.iterator();
while(iterator.hasNext())
{
	Entry<Object, Object> next = iterator.next();
	System.out.println(next.getKey()+"="+next.getValue());
}
}

安全加减

int Math.safeAdd(int value1,int value2)
long Math.safeMutiply(long value1,long value2)
long Math.safeNegate(long value1,long value2)
int Math.safeSbstract(int value1,int value2)

Boooleans

Boolean.logicalAnd(true, true);
Boolean.logicalOr(false, true);
Boolean.logicalXor(true, false);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值