Java笔试题

本文介绍了Java的基本数据类型及其占用字节数,展示了如何通过不同方式创建字符串实例的区别,并提供了理解静态代码块执行时机的示例。同时,文章还探讨了接口的修饰符限制以及字节流到字符流转换的方法。

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

1 java中:
byte 1(字节)
short 2
int 4
long 8
float 4
double 8
char 2

2 System.out.println(3+5+"a"+6+7);输出:8a67

3 开发与运行Java程序需要经过的三个主要步骤为 编辑源程序、编译生成字节码 和 解释运行字节码。

4 interface只能用public修饰。

5 字节流转换成字符流可以用InputStream和OutputStream来转换。

6 移位操作符只可用来处理整数类型,左移操作符(>)则按照右侧自定的位数将操作符左边的操作数右移(有符号数按符号扩展)

7 Java中增加了一种“无符号”右移操作符(>>>)它使用0扩展。无论正负。高位补0。

8 String s1=new String("a");
String s2=new String("a");
String s3="a";
String s4="a";

System.out.println(s1==s2);
System.out.println(s1.equals(s2));
System.out.println(s4==s3);
System.out.println(s4.equals(s3));


输出结果:false
true
true
true


9 static域的执行时间(第一次用类的时候执行一次,以后就不执行了)

public class Test1 {

/**
* @param args
*/
static{
System.out.println("Test1 is loading");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("main method is executing");
new StaticCode();
new StaticCode();
}

}

class StaticCode{
static String country;
static{
country="china";
System.out.println("StaticCode is loading");
}

}
输出结果是:Test1 is loading
main method is executing
StaticCode is loading
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值