原文来自http://www.allapplabs.com/interview_questions/java_interview_questions.htm

翻译:Zeng Yuetian

转载请注明出处。

Q021:

How can one prove that the array is not null but empty using one line of code?
如何能够用一行代码证明该array不是null而是空值?(接上问)

A:

Print args.length. It will print 0. That means it is empty. But if it would have been null then it would have thrown a NullPointerException on attempting to print args.length.
打印args.length, 它将打印0。这意味着它是空的。如果它是空的话,该行代码将会抛出NullPointerException

Q022:

What environment variables do I need to set on my machine in order to be able to run Java programs?
为了能够运行Java程序,我需要设置哪些环境变量?

A:

CLASSPATH and PATH are the two variables.
需要设置的两个环境变量是CLASSPATH和PATH

Q023:

Can an application have multiple classes having main method?
同一个应用中可以允许多个类都有main方法么?

A:

Yes it is possible. While starting the application we mention the class name to be run. The JVM will look for the Main method only in the class whose name you have mentioned. Hence there is not conflict amongst the multiple classes having main method.
这有可能。当我们用指定的类名来运行程序的时候,JVM将只在该类中寻找main方法来运行。因此,多个类都含有的main方法不会相互冲突。

Q024:

Can I have multiple main methods in the same class?
在同个类中指定多个main方法可以么?

A:

No the program fails to compile. The compiler says that the main method is already defined in the class.
不行,程序将编译失败。编译器会报main方法已经在类中定义过了。

Q025:

Do I need to import java.lang package any time? Why ?
我需要在什么时候import java.lang包么,为什么?

A:

No. It is by default loaded internally by the JVM.
不,该包会被JVM默认装载进来。

Q026:

Can I import same package/class twice? Will the JVM load the package twice at runtime?
我可以把一个包或者类import两次么?JVM会在运行时装载它两次么?

A:

One can import the same package or same class multiple times. Neither compiler nor JVM complains abt it. And the JVM will internally load the class only once no matter how many times you import the same class.
我们可以多次import同一个包或者同一个类。编译器和JVM都不会报错。但是,在内部JVM只会将其导入一次。

Q027:

What are Checked and UnChecked Exception?
什么查核的异常和未查核的异常?

A:

A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses.
一个查核的异常是Exception的子类或者是Exception,不过不包括类RuntimeException和它的子类。
Making an exception checked forces client programmers to deal with the possibility that the exception will be thrown. eg, IOException thrown by java.io.FileInputStream's read() method·

查核异常要求客户端程序员处理异常将被抛出的可能性。例如:IOException可能会被java.io.FileInputStream中的read()方法抛出
Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked. With an unchecked exception, however, the compiler doesn't force client programmers either to catch the
exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. eg, StringIndexOutOfBoundsException thrown by String's charAt() method· Checked exceptions must be caught at compile time. Runtime exceptions do not need to be. Errors often cannot be.
未查核的异常是RuntimeException和它的任何子类。Error类和它的子类也是未查核的。对于未查核的异常,编译器并不要求程序员catch它或是在throws语言中声明它。实际上,客户端程序员可能根本不知道有异常会被抛出。例如: StringIndexOutOfBoundsException被String的charAt()方法抛出。查核的异常必须在编译期被捕获。运行时异常不需要在编译器被捕获,而Error往往也不能在编译器被捕获。

Q028:

What is Overriding?
什么是覆盖?

A:

When a class defines a method using the same name, return type, and arguments as a method in its superclass, the method in the class overrides the method in the superclass.
When the method is invoked for an object of the class, it is the new definition of the method that is called, and not the method definition from superclass. Methods may be overridden to be more public, not more private.

当一个类定义了一个方法,该方法和它的父类中的同名方法有着相同的返回类型和相同的参数,那么该类的这个方法覆盖了它父类中的那个同名方法。
当这个方法被该类的对象所调用的时候,这个新定义的方法会被调用,而不是其父类定义的那个方法。方法的覆盖必须是更public的,而不能更private。

Q029:

Are the imports checked for validity at compile time? e.g. will the code containing an import such as java.lang.ABCD compile?
import
会在编译期进行有效性检查么?例如,包含import java.lang.ABCD语句的代码能编译么?

A:

Yes the imports are checked for the semantic validity at compile time. The code containing above line of import will not compile. It will throw an error saying,can not resolve symbol
symbol : class ABCD
location: package io
import java.io.ABCD;
是的,import将会在编译期进行语义检查。上面的代码将无法通过编译。它将会抛出如下的错误报告无法解析符号

symbol : class ABCD
location: package io
import java.io.ABCD;

Q030:

Does importing a package imports the subpackages as well? e.g. Does importing com.MyTest.* also import com.MyTest.UnitTests.*?
import某个包的时候会自动import它的子包么?例如,import com.MyTest.*会同时import com.MyTest.UnitTests.*么?

A:

No you will have to import the subpackages explicitly. Importing com.MyTest.* will import classes in the package MyTest only. It will not import any class in any of it's subpackage.
不,你必须显式地import子包。import com.MyTest.*只会导入MyTest中的类,它不会导入任何子类中的包。

转载于:https://www.cnblogs.com/yuetiantian/archive/2010/02/03/1663016.html

Java面试问题 021-030相关推荐

  1. java面试常见问题之Hibernate总结

    1  Hibernate的检索方式 Ø  导航对象图检索(根据已经加载的对象,导航到其他对象.) Ø  OID检索(按照对象的OID来检索对象.) Ø  HQL检索(使用面向对象的HQL查询语言.) ...

  2. 2021年Java面试题目最新总结【90%面试会踩的坑】

    学会java技术之后大家面临的最多的问题就是面试这关,求职面试java岗位是否能够成功是直接影响我们的工作机会的,所以对于Java程序员面试你准备好了吗?今天小编汇总了一下关于Java程序员面试,90 ...

  3. Github 一夜爆火:这份金九银十 Java 面试手册我给跪了

    这几天给筒子们整理了一份<Java面试手册>,106页,目前大约6万字左右,初衷也很简单,就是希望在面试的时候能够帮助到大家,减轻大家的负担和节省时间. 废话不多说,本手册目前为第一版,后 ...

  4. Java面试参考指南(二)

    2019独角兽企业重金招聘Python工程师标准>>> 访问修饰符 对于基本的OOPS(面向对象)概念,请看Java面试参考指南的第一部分.访问修饰符规定了一个类如何访问另一个类及它 ...

  5. 卧槽,又一个Java面试神器!!!

    临近秋招,又到了"金九银十"面试求职高峰期,在金三银四时也参与过不少面试,2020都说工作不好找,也是对开发人员的要求变高.前段时间自己有整理了一些Java后端开发面试常问的高频考 ...

  6. 200 道 Java 面试题解!某阿里 P7 只答上来 70%!

    最近,经常有读者朋友们在后台给我留言,问我有没有什么面试资料可以分享的,因为之前一直比较忙,所以没有时间整理. 最近终于抽出一些时间,整理了一下,一发不可收拾了,一口气整理出好几本电子书出来.其中有一 ...

  7. 美团架构师开源5万字的《Java面试手册》PDF免费下载!

    美团一位架构师利用空余时间在github整理了一份<Java面试手册>,现整理成PDF,初衷也很简单,就是希望在面试的时候能够帮助到大家,减轻大家的负担和节省时间. 前两天,朋友圈分享了这 ...

  8. 5万字的《Java面试手册》V1.0版本,高清PDF免费获取

    利用空余时间整理了一份<Java面试手册>,初衷也很简单,就是希望在面试的时候能够帮助到大家,减轻大家的负担和节省时间. 前两天,朋友圈分享了这份这份面试手册的初稿,再几位同学的提议下,对 ...

  9. JAVA面试解析(有赞二面)

    作者:孤独烟 来自:打杂的ZRJ 本文的题目出自博客 http://www.54tianzhisheng.cn/2018/07/12/youzan/ 但是作者没有给出答案,博主斗胆来制作答案版. 也是 ...

  10. Java 面试,这样拿 Offer!

    (含答案) 所有面试资料及技术好文精选文档都整理到网盘了. Java面试官手册需要加微信免费领取 长按扫码或搜索微信号:gupao666666,免费领取

最新文章

  1. oracle导入索引b报错,impdp导入索引很慢
  2. eclipse常用快捷键Get;set;
  3. zookeeper 伪分布式安装
  4. Expert 诊断优化系列------------------透过等待看系统
  5. SQL编程:模糊表关联不求人 --- concat + like就能行
  6. RTC_WaitForSynchro()
  7. 运行时异常与一般异常有何异同_Java修行第015天,异常机制和常用类
  8. 【C++】考虑virtual函数以外的其他选择
  9. 萤火虫小程序_9.9元起!萤火虫中秋文化节来了!特价门票限量秒杀,手慢无!...
  10. android tcpdump log分析,android 系统启动过程中加入tcpdump和logcat
  11. 这份 Pandas 学习教程很不错,可在线运行
  12. 算法题3 二分查找法
  13. 学习面试题(day01)
  14. TCP/IP之封装,分用,server模型
  15. Windows Phone 7, Hammock, OAuth and Sina Weibo’s API
  16. 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_01 File类_4_File类的构造方法...
  17. 亿欧:深耕开放银行,Temenos产品创新和并购战略双轮驱动
  18. Python基于OpenCV的人脸集合相似度检测系统(源码&UI&教程)
  19. chrome禁止广告
  20. 一款强大的网站在线客服聊天系统:whisper搭建教程

热门文章

  1. caffe测试单张图片
  2. 查找python关键字
  3. 新版微信不停跳转到小程序_微信又有大动作,小程序跳转功能将受限?
  4. 2021-07-07 分类页面结构
  5. 为什么天才容易患阅读障碍症_王俊凯因“耳石症”缺席跨年晚会,这种病与熬夜玩手机有关?...
  6. 联想提取exe文件中的bios文件_3900不带X能干过99K吗?品牌机做视频渲染可以?联想刃7000P评测...
  7. kubernetes service的作用、类型、关系和工作原理ClusterIp、NodePort、LoadBalance、ExternalName
  8. 基于springboot+vue的二手商城(闲置物品交易)(前后端分离)
  9. MRTK 当进入某个物体时调用的函数
  10. Leetcode994腐烂的橘子(宽搜)