java学习

本文深入探讨了Java中的关键概念和技术,包括Class.forName的功能、RuntimeException与其他异常的区别、String转换为int的方法、String.equals与==的区别,以及抽象类与接口的重要差异。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1,Class.forName做什么

A call to Class.forName("X") causes the class named X to be dynamically loaded (at runtime).A call to forName("X") causes the class named X to be initialized.Class.forName("X") loads the class if it not already loaded. The JVM keeps track of all the classes that have been previously loaded. This method uses the classloader of the class that invokes it. The "X" is the fully qualified name of the desired class.

 

2,java.lang.RuntimeException和一般异常有什么不同?

Java中有两种异常: checked exceptions and un-checked exceptions. A checked exception must be handled explicitly by the code. you either have to put a try/catch block around the code that could potentially throw the exception, or add a "throws" clause to the method, to indicate that the method might throw this type of exception.RuntimeException is un-checked. RuntimeExceptions do not need to be explicitly handled by the calling code.

 

3,String转为int的方法。

Integer x = Integer.valueOf(str);
int y = Integer.parseInt(str);

 

4,比较String.equals(String other)和==

String.equals(String other)比较两个字符串的值是否相同

==标记String的引用是否相同


5,Java中抽象类和接口的区别。

an interface is a reference type can contain only constants, method signatures, and nested types.
接口不能包含instance fields,可以包含用static或final来修饰的field。抽象类可以申明和使用fields。

接口不能包含构造函数。抽象类可以。

类可以实现多个接口,但只能继承一个抽象类。

接口包含的方法申明等都是隐式public的,抽象类包含的方法可以是public,private,protected或者默认的package。

接口中的方法都是抽象的,抽象类中可以包含具体的方法。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值