JavaInteview_unlocked
JavaInteview_unlocked
JavaInteview_unlocked
https://freestudy247.com/category/interview-question/
<Các bạn không tốt tiếng Anh thì có thể dùng google dịch nhé.
Mình viết sẵn bằng tiếng Anh vì mình hay phỏng vấn bằng tiếng Anh thôi
😊>
Tại đây chúng tôi đã xây dựng nhiều khóa học theo từng lộ trình như Java, C#, cơ sở dữ
liệu, DevOps, ReactJs, VueJS,… Trang web được xây dựng gồm cả tiếng Anh và tiếng
Việt
Để xem giải thích chi tiết hơn và đặt câu hỏi nếu có thắc mắc
về bộ câu hỏi phỏng vấn, vui lòng truy cập:
Fanpage facebook: Fanpage Free Study 247
Nhóm Facebook: Chia sẻ khóa học Udemy, Udacity, Coursera miễn phí
Java Interview
1. Introduce about Java Programming Language
- Java is object-oriented programming language and it’s one of the most popular languages
in the world.
- It’s a high security language and often used to build large software systems like
ecommerce or banking.
- It’s famous for its write one and run anywhere feature or in other word; it’s crossplatform
programming language.
Java Heap Memory is the memory used Stack Memory is memory to store local variables
at runtime to store Objects. Whenever in functions and function calls at runtime in a java
anywhere in your program when you Thread. Local variables include: primitive types,
create an Object it will be stored in the reference types to objects in the heap (reference),
Heap (execute the new operator) declarations in functions, or arguments passed to
the function.
Objects stored in the heap are globally Stack memory is used only by one thread of
accessible execution.
Heap memory lives from the start till Stack memory is short-lived.
the end of application execution.
- It’s pass by value because wrapper class in Java is immutable. When you try to change
the value of a wrapper class, JVM create a new wrapper class with the value we just
changed
An abstract class can have abstract and non- Java version < 8 Interface can only
abstract methods have abstract method.
Java 8 version can add default and
static methods.
Java 9 version can add private methods
Abstract class does not support multiple Interface supports multiple inheritance
inheritance
Abstract class can have final, non-final, static and Interface has only static final variables
non-static variables
Use Abstract class when we can only complete a Use Interface when you want to build a
few standard functions (method/function) of the standard framework of functions
system, some of the remaining functions extend (method/function) that all
classes have to complete. These finished features modules/projects need. Modules must
are still usable as usual, these are general features. implement all defined functionality.
35.What is the purpose of the overriden method and when we can use the override method?
- In OOP, method overriding can understand as a subclass can provide specific
implementation of a method and that method already provide the implementation by
parent class.
- The condions of method overriding
+ Two methods must have the same name, the same return data type and data type of
parameter and it’s can not be final method or static method
36. When we log an instance of a class, it will return a hasdcode. The meaning of that
hashCode and if we want to write the content of Object. How can you do that?
- The string return when we log an instance of a class is the name of class and hashcode of
that instance
- If you want to wirte the content of that instance, you must override the toString method
LinkedList
ArrayList
ArrayList uses dynamic array to store LinkedList uses a linked list (Doubly Linked List) to
elements. store elements.
ArrayList is an index-based data The elements in the LinkedList are called nodes,
structure, where each element is each node needs to store three pieces of information:
associated with an index. the reference of the previous element, the value of
the element, and a reference to the next element.
Adding and removing elements with Adding and removing elements with LinkedList is
ArrayList is slow because it uses faster than ArrayList. Because it doesn't need to
arrays internally. Because after rearrange the elements after adding or removing. It
adding or removing elements need simply updates the reference to the element before
reordering. and after it.
ArrayList can only act as a list LinkedList can act as an ArrayList, stack (queue),
because it only implements the List queue, Singly Linked List and Doubly Linked List
interface. because it implements List and Deque interfaces.
60.Why HashSet can’t contain duplicated elements and can’t main the order of elements?
- HashSet can't contain duplicated elements because inside HashSet, it uses HashMap to
store the elements and the elements of HashSet are the key of HashMap in key, value
pair, and the value of that key is a dumpy object. And because the key is unique, therefore
HashSet only contains unique elements.
- Hash Set can not maintain the orders of elements because it uses the hash algorithm to
implement and in the hash Map, the key will be caculate by hash function and it returns
the hashCode, and it store element in a bucket base on the hash code. So, it can not
maintain the order of elements added.
elements. elements.
order.
slightly slower as it
also maintains an after each insertion and
sequence of the
elements.
elements.
compare elements
possible
duplicates.
Null element HashSet allows up LinkedHashSet also TreeSet does not allow null
element, it throws
NullPointerException.
62. You add an element already exist in SET. How did JVM do that? Equal () method and
HashCode () method, which one call first.
- When you add an element into SET, first, it will hashCode () the value and hashCode ()
value is the bucket identifier. If there is no bucket exist with the same hashCode, it will
create new one and store elements in that, otherwise it will traverse through that bucket to
check whether there is no one element with the same key exist in that bucket by equal
method or not, if no one exist, it will create a new one otherwise, it will ignore that
element
Comparator
Comparable
comparison. That is, we can only compare by comparisons. That is, we can sort based on
id or name, or age, ... many factors such as id, name, age, ...
Comparable modifies the original class, that is, Comparator does not change the original
the comparable object's class must modify and class. We can create a new class that
implement. implement.
Comparable provides compareTo () method Comparator provides compare () method
Any list can be sorted using the Any list can be sorted using the
method
68.Which Java version, you often use? Why do you use it?
- I often use Java 8. Java 8 is recommended by many people beacause it has many
important improvements of Java programming language and it also have very large user
community.
Java Heap Memory is the memory used Stack Memory is memory to store local variables
at runtime to store Objects. Whenever in functions and function calls at runtime in a java
anywhere in your program when you Thread. Local variables include: primitive types,
create an Object it will be stored in the reference types to objects in the heap (reference),
Heap (execute the new operator) declarations in functions, or arguments passed to
the function.
Objects stored in the heap are globally Stack memory is used only by one thread of
accessible execution.
Heap memory lives from the start till Stack memory is short-lived.
the end of application execution.