今天分享 Java 高频面试题英语版。音频文件放在下方,点击获取。
【Java】Java 高频面试题英语版(1)
【Java】Java 高频面试题英语版(2)
【Java】Java 高频面试题英语版(3)
【Java】Java 高频面试题英语版(4)
【Java】Java 高频面试题英语版(5)
Java language was developed in such a way that it does not depend on any hardware or software due to the fact that the compiler compiles the code and then converts it to platform-independent byte code which can be run on multiple systems.
Java 语言的开发方式使其不依赖于任何硬件或软件,因为编译器会编译代码,然后将其转换为可以在多个系统上运行的与平台无关的字节码。
Java supports primitive data types - byte, boolean, char, short, int, float, long, and double and hence it is not a pure object oriented language.
Java 支持原始数据类型 - byte、boolean、char、short、int、float、long 和 double,因此它不是纯面向对象的语言。
Stack memory is the portion of memory that was assigned to every individual program. And it was fixed. On the other hand, Heap memory is the portion that was not allocated to the java program but it will be available for use by the java program when it is required, mostly during the runtime of the program.
堆栈内存是分配给每个单独程序的内存部分。它是固定的。另一方面,堆内存是未分配给 java 程序的部分,但在需要时可供 java 程序使用,主要是在程序运行时。
Java Utilizes this memory as:
Java 将此内存用作:
Example- Consider the below java program:
class Main {
public void printArray(int[] array){
for(int i : array)
System.out.println(i);
}
public static void main(String[] args) {
int[] array = new int[10];
printArray(array);
}
}
For this java program. The stack and heap memory occupied by java is:
Main and PrintArray is the method that will be available in the stack area and as well as the variables declared that will also be in the stack area.
And the Object (Integer Array of size 10) we have created, will be available in the Heap area because that space will be allocated to the program during runtime.
Main 和 PrintArray 是堆栈区域中可用的方法,以及声明的变量也将在堆栈区域中。
我们创建的对象(大小为 10 的整数数组)将在堆区域中可用,因为该空间将在运行时分配给程序。
It is not wrong if we claim that java is the complete object-oriented programming language. Because Everything in Java is under the classes. And we can access that by creating the objects.
But also if we say that java is not a completely object-oriented programming language because it has the support of primitive data types like int, float, char, boolean, double, etc.
Now for the question: Is java a completely object-oriented programming language? We can say that - Java is not a pure object-oriented programming language, because it has direct access to primitive data types. And these primitive data types don’t directly belong to the Integer classes.
如果我们声称 java 是完整的面向对象的编程语言,那并没有错。因为 Java 中的一切都在类之下。我们可以通过创建对象来访问它。
但是,如果我们说 java 不是一种完全面向对象的编程语言,因为它支持原始数据类型,如 int、float、char、boolean、double 等。
现在的问题是:**Java 是完全面向对象的编程语言吗?**我们可以说——Java 不是一种纯粹的面向对象的编程语言,因为它可以直接访问原始数据类型。而且这些原始数据类型不直接属于 Integer 类。
Pointers are quite complicated and unsafe to use by beginner programmers. Java focuses on code simplicity, and the usage of pointers can make it challenging. Pointer utilization can also cause potential errors. Moreover, security is also compromised if pointers are used because the users can directly access memory with the help of pointers.
Thus, a certain level of abstraction is furnished by not including pointers in Java. Moreover, the usage of pointers can make the procedure of garbage collection quite slow and erroneous. Java makes use of references as these cannot be manipulated, unlike pointers.
指针对于初学者来说非常复杂且不安全。Java 专注于代码的简单性,而指针的使用可能使其具有挑战性。指针的使用也可能导致潜在的错误。此外,如果使用指针,安全性也会受到影响,因为用户可以在指针的帮助下直接访问内存。
因此,通过在 Java 中不包括指针来提供一定程度的抽象。此外,指针的使用会使垃圾收集过程变得非常缓慢和错误。Java 使用引用,因为这些不能被操纵,不像指针。
Instance variables are those variables that are accessible by all the methods in the class. They are declared outside the methods and inside the class. These variables describe the properties of an object and remain bound to it at any cost.
All the objects of the class will have their copy of the variables for utilization. If any modification is done on these variables, then only that instance will be impacted by it, and all other class instances continue to remain unaffected.
Example:
class Athlete {
public String athleteName;
public double athleteSpeed;
public int athleteAge;
}
实例变量是类中所有方法都可以访问的变量。它们在方法外部和类内部声明。这些变量描述了一个对象的属性,并且不惜一切代价保持与它的绑定。
该类的所有对象都将拥有它们的变量副本以供使用。如果对这些变量进行任何修改,那么只有该实例会受到影响,所有其他类实例继续保持不受影响。
Local variables are those variables present within a block, function, or constructor and can be accessed only inside them. The utilization of the variable is restricted to the block scope. Whenever a local variable is declared inside a method, the other class methods don’t have any knowledge about the local variable.
Example:
public void athlete() {
String athleteName;
double athleteSpeed;
int athleteAge;
}
局部变量是存在于块、函数或构造函数中的那些变量,并且只能在它们内部访问。变量的使用仅限于块范围。每当在方法中声明局部变量时,其他类方法对局部变量一无所知。
例子:
public void athlete() {
String athleteName;
double athleteSpeed;
int athleteAge;
}
equals() | == |
---|---|
This is a method defined in the Object class. | It is a binary operator in Java. |
This method is used for checking the equality of contents between two objects as per the specified business logic. | This operator is used for comparing addresses (or references), i.e checks if both the objects are pointing to the same memory location. |
Note:
equals() | == |
---|---|
这是在 Object 类中定义的方法。 | 它是 Java 中的二元运算符。 |
此方法用于根据指定的业务逻辑检查两个对象之间的内容是否相等。 | 该运算符用于比较地址(或引用),即检查两个对象是否指向相同的内存位置。 |
笔记:
Infinite loops are those loops that run infinitely without any breaking conditions. Some examples of consciously declaring infinite loop is:
无限循环是那些在没有任何中断条件的情况下无限运行的循环。有意识地声明无限循环的一些例子是:
for (;;)
{
// Business logic
// Any break logic
}
while(true){
// Business logic
// Any break logic
}
do{
// Business logic
// Any break logic
}while(true);
Constructor overloading is the process of creating multiple constructors in the class consisting of the same name with a difference in the constructor parameters. Depending upon the number of parameters and their corresponding types, distinguishing of the different types of constructors is done by the compiler.
构造函数重载是在类中创建多个同名但构造函数参数不同的构造函数的过程。根据参数的数量及其对应的类型,不同类型的构造函数的区分由编译器完成。
class Hospital {
int variable1, variable2;
double variable3;
public Hospital(int doctors, int nurses) {
variable1 = doctors;
variable2 = nurses;
}
public Hospital(int doctors) {
variable1 = doctors;
}
public Hospital(double salaries) {
variable3 = salaries
}
}
Copy Constructor is the constructor used when we want to initialize the value to the new object from the old object of the same class.
Copy Constructor 是当我们想将值从同一个类的旧对象初始化到新对象时使用的构造函数。
class InterviewBit{
String department;
String service;
InterviewBit(InterviewBit ib){
this.departments = ib.departments;
this.services = ib.services;
}
}
Here we are initializing the new object value from the old object value in the constructor. Although, this can also be achieved with the help of object cloning.
在这里,我们从构造函数中的旧对象值初始化新对象值。虽然,这也可以在对象克隆的帮助下实现。
Yes, It is possible to overload the main method. We can create as many overloaded main methods we want. However, JVM has a predefined calling method that JVM will only call the main method with the definition of -
是的,可以重载 main 方法。我们可以创建任意数量的重载 main 方法。但是,JVM 有一个预定义的调用方法,JVM 只会调用具有以下定义的 main 方法 -
public static void main(string[] args)
Consider the below code snippets:
考虑以下代码片段:
class Main {
public static void main(String args[]) {
System.out.println(" Main Method");
}
public static void main(int[] args){
System.out.println("Overloaded Integer array Main Method");
}
public static void main(char[] args){
System.out.println("Overloaded Character array Main Method");
}
public static int main(double[] args){
System.out.println("Overloaded Double array Main Method");
}
public static void main(float args){
System.out.println("Overloaded float Main Method");
}
}