Android面试问题系列-第一部分-核心Java,多线程和Kotlin

I am sharing questions from my personal interview experiences for the Android dev role in this series.

我将分享有关本系列Android开发人员角色的个人采访经验中的问题。

Part II Link Android Interview Questions Series — Part II — Android, Dagger

第二部分链接 Android面试问题系列-第二部分-Android,Dagger

Java Basics + Oops

Java基础知识+糟糕

  1. What is object-oriented programming? : It is a computer programming model that organizes software design around data, or objects, rather than functions and logic.OOP concepts in Java are the main ideas behind Java’s oop. They are an abstraction, encapsulation, inheritance, and polymorphism.

    什么是 面向对象编程 一种计算机编程模型,围绕数据或对象而不是功能和逻辑来组织软件设计。Java中的OOP概念是Java oop背后的主要思想。 它们是抽象,封装,继承和多态。

  2. SOLID Principles

    SOLID 原则

  3. What is the purpose of the default constructor?: To initialize an object, The compiler implicitly adds a default constructor in the program if we have not declared or defined it.

    默认构造函数的目的是什么? :要初始化对象,如果我们尚未声明或定义对象,则编译器会在程序中隐式添加一个默认构造函数。

  4. Restrictions on static methods, can we override static methods? link

    对静态方法的限制,我们可以覆盖静态方法吗? 链接

  5. Static block vs init{} block (static, init & constructor calls order): The static block is only loaded when the class object is created by the JVM for the 1st time whereas init {} block is loaded every time class object is created. Also first the static block is loaded then the init block.

    静态块与init {}块(静态,init和构造函数调用顺序):仅在JVM第一次创建类对象时才加载静态块,而每次创建类对象时都会加载init {}块。 同样,首先加载静态块,然后再加载init块。

  6. Java Object class (Methods of Object class): Every class in Java is directly or indirectly derived from the Object class. If a class does not extend any other class then it is a direct child class of Object and if extends other class then it is indirectly derived.

    Java Object类(Object类的 方法 ) :Java中的每个类都直接或间接地从Object类派生。 如果一个类没有扩展任何其他类,则它是Object的直接子类,如果扩展了其他类,则它是间接派生的。

  7. This keyword in java, Uses of this keyword, constructor chaining be done using this keyword: It is a reference variable that refers to the current object

    java中 的this关键字 使用此关键字 ,使用此关键字完成构造函数链接 :它是引用当前对象的引用变量

  8. What is Inheritance and Why is multiple inheritance not supported in java? : Java supports multiple inheritance through interfaces only. A class can implement any number of interfaces but can extend only one class. Multiple inheritance is not supported because it leads to the deadly diamond problem

    什么是继承?为什么Java不支持多重继承? Java仅通过接口支持多重继承。 一个类可以实现任何数量的接口,但只能扩展一个类。 不支持多重继承,因为它会导致致命的钻石问题

  9. Runtime and Compile time polymorphism, method overloading vs method overriding

    运行时和编译时多态,方法重载与方法重载

  10. Static vs Dynamic Binding in java

    Java中的静态绑定与动态绑定

  11. Class variable vs object variables

    类变量与对象可 变性

  12. Association, Aggregation & Composition

    协会,聚集与组成

  13. Explain super in java and constructor chaining using super keyword

    使用super关键字解释Java和构造函数链接中的super

  14. this Vs super : super refers immediate parent class instance, this() — refers current class instance.

    这个vs超级:超级 引用直接父类实例,this()—引用当前类实例。

  15. Can we use this() and super() both in a constructor

    我们 可以在构造函数中同时使用this()和super() 吗?

  16. Final keyword and its restrictions (final variable cannot be overridden, final class cannot be inherited ): final variable — to create a constant variable, final method — to prevent override, final class to prevent inheritance

    final关键字及其限制 (final 关键字 不能被覆盖,final类不能被继承) final变量-创建一个常量变量,final方法-防止覆盖,final类防止继承

  17. Abstract class vs Interface in Java

    Java中的抽象类与接口

  18. Write Immutable class in Java: make class final and all its member variable final

    用Java编写不可变的类 将类定为final及其所有成员变量为final

  19. *Write Singleton class in java (thread-safe, reflection proof, clone proof, serialization proof)*imp*

    * 用Java语言编写Singleton类(线程安全,反射证明,克隆证明,序列化证明) * imp *

  20. what is object cloning?: The object cloning is a way to create an exact copy of an object. For this purpose, the clone() method of an object class is used to clone an object.

    什么是对象克隆? :对象克隆是一种创建对象的精确副本的方法。 为此,可以使用对象类的clone()方法来克隆对象。

  21. Shallow copy Vs deep Copy in Java

    Java中的 浅复制与深复制

  22. Marker Interface in java: It is an interface that has no abstract method eg — serializable, clonable)

    Java中的标记接口:它是没有抽象方法的接口,例如-可序列化,可克隆)

  23. Functional Interface in Java: It is an interface that contains only one abstract method. They can have only one functionality to exhibit (eg — Runnable, comparable)

    Java中的功能接口:它是仅包含一个抽象方法的接口。 他们只能展示一种功能(例如,可运行,可比较)

  24. Explain Java String Pool (equals and == operations on strings)

    解释Java字符串池 (对字符串等于和==的操作)

  25. String Builder vs String Buffer

    字符串生成器与字符串缓冲区

  26. Explain some common Design patternsFactory pattern, Singleton pattern, Builder pattern, Observer pattern, etc.

    解释一些常见的设计模式 - 工厂模式单例模式构建器模式观察者模式等。

  27. What is Exception Handling, Exception vs Error, a checked and unchecked exception?

    什么是异常处理,异常与错误,已检查和未检查的异常?

  28. What is the base class for Error and Exception

    错误和异常的基类是什么

  29. Explain final, finally and finalize in Java: Throwable

    在Java中 解释 final,finally和finalize Throwable

  30. What is the purpose of the finalize method? : It is a method that the Garbage Collector always calls just before the deletion/destroying the object which is eligible for Garbage Collection

    finalize方法的目的是什么? 这是垃圾收集器始终在删除/销毁符合垃圾收集条件的对象之前始终调用的方法

  31. What is the difference between throw and throws

    throw和throws有 什么区别

  32. What is Garbage Collector (GC)? how to invoke GC? System.gc(); Requesting JVM to call Garbage Collector method

    什么是垃圾收集器(GC)? 如何调用GC? System.gc(); 请求JVM调用垃圾收集器方法

  33. What is Serialization in java? : writing state of an object in bytes stream, We must have to implement the Serializable interface for serializing the object

    什么是Java中的序列化 ? :在字节流中写入对象的状态,我们必须必须实现Serializable接口才能序列化对象

  34. What is the transient keyword in serialization? : If you define any data member as transient, it will not be serialized.

    序列化中的瞬时关键字是什么? 注意:如果将任何数据成员定义为瞬态,则不会序列化。

  35. What is the reflection API? : Reflection is an API that is used to examine or modify the behavior of methods, classes, interfaces at runtime.

    什么是 反射 API? Reflection是一种API,用于在运行时检查或修改方法,类,接口的行为。

Multi-Threading

多线程

  1. What is a thread? Thread vs process? Thread lifecycle

    什么是线程? 线程还是进程? 线程生命周期

  2. wait() vs sleep() method? Differentiate between the Thread class and Runnable interface for creating a thread?

    wait()vs sleep() 方法? 区分Thread类和Runnable接口以创建线程吗?

  3. What does join() method do? : It will put the current thread on wait until the thread on which it is called is dead.

    join()方法有什么作用? 它将使当前线程处于等待状态,直到调用该线程的线程失效为止。

  4. Thread’s run() vs start() method

    线程的 run()与start() 方法

  5. Deamon threads? It is a low priority thread that runs in the background to perform tasks such as garbage collection.

    恶魔线程 它是一个低优先级线程,在后台运行以执行诸如垃圾收集之类的任务。

  6. What is a synchronization block and concurrency in java? : synchronization is a good way to achieve mutual exclusion on shared resource

    什么是 Java中 同步块和并发? 同步是在共享资源上实现互斥的好方法

  7. What is the difference between notify() & notifyAll()?: notify() and notifyAll() methods with wait() method are used for communication between the threads. We can use notify() method to give the notification for only one thread which is waiting for a particular object whereas by the help of notifyAll() methods we can give the notification to all waiting threads of a particular object

    notify()和notifyAll() 之间有什么区别 ?: notify()和notifyAll()方法以及wait()方法用于线程之间的通信。 我们可以使用notify()方法仅向一个正在等待特定对象的线程发出通知,而借助notifyAll()方法,我们可以向特定对象的所有等待线程提供通知。

  8. Thread pool, volatile keyword and Thread safety in java: A thread pool reuses previously created threads to execute current tasks, volatile is yet another way (like synchronized, atomic wrapper) of making class thread-safe, volatile is used to mark a Java variable as “being stored in main memory”

    Java中的 线程池 volatile关键字 线程安全性 线程池重用先前创建的线程来执行当前任务,volatile是使类线程安全的另一种方式(例如同步,原子包装),volatile用于标记Java变量作为“存储在主存储器中”

  9. What are the Executor interface and Blocking queue

    什么是 执行器接口 阻止队列

  10. Implement producer-consumer problem in Java

    用Java 实现 生产者-消费者问题

  11. Callable and Future in Java, future task in java, Callable vs Runnable: for a Callable, the call() method needs to be implemented which returns a result on completion FutureTask implements Runnable and Future, combining both functionalities conveniently.

    Java中的Callable and Future,Java中的Future任务,Callable与Runnable 对于Callable,需要实现call()方法,该方法在完成时返回结果,FutureTask实现Runnable和Future,将两种功能方便地组合在一起。

Collections in Java

Java中的集合

  1. Array vs ArrayList in Java

    Java中的 Array vs ArrayList

  2. What is the difference between Comparable and Comparator

    比较器和比较器有 什么区别

  3. HashMap vs HashSet, HashMap vs HashTree, HashMap vs HashTable

    HashMap与HashSet HashMap与HashTree,HashMap与HashTable

  4. null keys and null values in HashMap, LinkedHashMap, TreeMap

    HashMap,LinkedHashMap,TreeMa p中的 空键和空值

  5. Iterating a map in java : using keyset() and entryset()

    在Java中迭代地图 :使用keyset()和entryset()

  6. Internal Working of a HashMap

    HashMap的内部工作

Kotlin

Kotlin

  1. Why use kotlin: Concise, null-safe, interoperable

    为什么要使用kotlin:简洁,可安全空值,可互操作

  2. How does Kotlin work on Android? : Kotlin code is also compiled into the Java bytecode and is executed at runtime by the Java Virtual Machine

    Kotlin如何在Android上运行? Kotlin代码也被编译为Java字节码,并在运行时由Java虚拟机执行

  3. Var vs Val: var are mutable variable and val are immutable

    Var vs Val: var是可变变量,而val是不可变的

  4. Val vs const: Both are immutable but const value must be known at compile time

    Val vs const:两者都是不可变的,但是在编译时必须知道const的值

  5. How to ensure null safety in Kotlin? and what is safe call operator (?)

    如何确保Kotlin的无效安全? 什么是安全呼叫接线员(?)

  6. Difference between safe call (?) and null check (!!)

    安全呼叫(?)和null检查(!!)之间的区别

  7. Elvis operator in Kotlin (?:): When we have a nullable reference b, we can say "if b is not null (val l = b?.length ?: -1)

    Kotlin(?:)中的Elvis运算符:当我们有一个可为空的引用b ,我们可以说“如果b不为空(val l = b?.length?:-1)

  8. What is the use of @JvmStatic, @JvmOverloads, and @JvmFiled in Kotlin? : Kotlin code can be easily called from Java. For example, instances of a Kotlin class can be seamlessly created and operated in Java methods.Refer

    Kotlin中@ JvmStatic,@ JvmOverloads和@JvmFiled的用途是什么? Kotlin代码可以轻松地从Java调用。 例如,可以用Java方法无缝创建和操作Kotlin类的实例。 参考

  9. What is a data class in Kotlin?:A data class is a class that only contains state and does not perform any operation.When you declare a data class, the compiler automatically generates several functions such as toString(), equals(), hashcode() etc behind the scenes.

    Kotlin中数据类什么?: 数据类是仅包含状态并且不执行任何操作的类。声明数据类时,编译器会自动生成几个函数,例如toString()equals()hashcode()等在幕后。

  10. What is lateinit keyword in kotlin: It is late initialization, it can be checked using isInitialized method

    什么是kotlin中的lateinit关键字:它是后期初始化,可以使用isInitialized方法进行检查

  11. Lateinit vs Lazy

    Lateinit vs Laz y

  12. What are companion object in kotlin : A companion object is initialized when the class is loaded. If you need to write a function that can be called without having a class instance but needs access to the internals of a class, you can write it as a member of a companion object declaration inside that class. By declaring a companion object inside our class, you’ll be able to call its members with the same syntax as calling static methods in Java, using only the class name as a qualifier.

    什么是kotlin中的伴随对象:加载类时,会初始化一个伴随对象。 如果您需要编写一个可以在没有类实例的情况下调用但需要访问类内部的函数,则可以将该函数编写为该类内部伴侣对象声明的成员。 通过在我们的类中声明一个伴随对象,您将能够使用与调用Java中的静态方法相同的语法来调用其成员,而仅使用类名作为限定符。

  13. What are init blocks in Kotlin?: The primary constructor cannot contain any code therefore init blocks allow adding code to the primary constructor.

    什么是Kotlin中的init块? :主构造函数不能包含任何代码,因此init块允许向主构造函数添加代码。

  14. What is the open keyword in Kotlin used for?: the functions and the variables are final in nature by default i.e. they can’t be inherited from any other class. So, to make it inheritable from other classes, we use the open keyword with the class, function, and variable name

    Kotlin中的open关键字用于什么?:默认情况下,函数和变量本质上是final的,即它们不能从任何其他类继承。 因此,为了使其可从其他类继承,我们将open关键字与类,函数和变量名一起使用

  15. What are extension functions in Kotlin?: Kotlin provides the ability to extend a class with new functionality without having to inherit from the class or use design patterns such as Decorator. This is done via special declarations called extensions.

    Kotlin中的扩展功能是什么?: Kotlin提供了使用新功能扩展类的能力,而不必从类中继承或使用诸如Decorator之类的设计模式。 这通过称为扩展的特殊声明来完成。

  16. What is an inline function in Kotlin?: In Kotlin, the higher-order functions or lambda expressions, all stored as an object so memory allocation, for both function objects and classes, and virtual calls might introduce runtime overhead. In order to reduce the memory overhead of such higher-order functions or lambda expression, we can use the inline keyword which ultimately requests the compiler to not allocate memory and simply copy the inlined code of that function at the calling place.

    什么是 Kotlin 内联函数 ?:在Kotlin中,所有高阶函数或lambda表达式都存储为一个对象,因此针对函数对象和类以及虚拟调用的内存分配可能会引入运行时开销。 为了减少此类高阶函数或lambda表达式的内存开销,我们可以使用inline关键字,该关键字最终要求编译器不分配内存,而只是在调用位置复制该函数的内联代码。

  17. Explain Scoped Functions in Kotlin — let, run, with, also, apply

    解释 Kotlin中的作用域函数-让,运行,一起应用

  18. Sealed Class: Sealed classes are used for representing restricted class hierarchies, when a value can have one of the types from a limited set, but cannot have any other type. They are, in a sense, an extension of enum classes

    密封类:密封类用于表示受限类层次结构,当一个值可以具有受限集中的一种类型,但不能具有任何其他类型时。 从某种意义上讲,它们是枚举类的扩展

Part II Link — Android Interview Questions Series — Part II — Android, Dagger

第二部分链接 -Android面试问题系列-第二部分-Android, 匕首

翻译自: https://medium.com/tech-insider/android-interview-questions-series-part-i-core-java-3ad243230a79

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值