Interview Preparation

 A. Core Java

1. JVM daxilindeki esas yaddaw saheleri:

a) Metaspace: static variables ve static primitive value, klass komponentleri(konstructor, method, field)

b) Heap - Shared memory: instance variables, instance variable value, local reference variable values

c) Stack - Per Thread: method signature, method parameter, method return type, local variables, local primitive variables value

d) PC Register: 

e) Native Method Stack:


2. JIT Compiler nedir?

JVM-in icinde JIT Compiler var. Ve JIT Compiler Interpreterin iwini asanlawdirir. Kod tekrarlarini onceden detekt edib maswin koduna cevirir, ve bu zaman interpreter her kod tekrarinda yeniden interpretasiya etmeyecek. 


3. Wrapper type-in dezavantajlari:

a) Riyazi emeliyyatlarda elave olaraq unboxing emeliyyati baw verir, bu da cost-dur. 


4. Primitiv tipin Wrapper type gore dezavantaji nedir?

a) Primitiv tipleren default deyerler vardir amma Wrapper type-da default deyeri null-dur, Bu da data inconsistency (fileda deyer set etmediyimiz halda primitive type bazaya mes 0 duwur, lakin wrapper type da null duwur, bu da check zamani bize lazim olur) yaradir.


5. Immutable nedir?

Hec bir halda fieldleri deyiwmeyen objectler. Deyiwmez state sahib olan objectler. Butun fieldari finaldir. Class ozu finaldir. Setterleri yoxdur yalniz gtterleri var. 


6. Niye Java multiple inheritance desteklemir? 


7. HasMap da put metodunun time complexitysi necedir?

a) O(1) - eger bucket bowdursa

b) O(n) - eger bucket bow deyilde ve node-lar 8 catmayibsa

c) O(log(n)) - eger bucket bow deyilde ve node-lear 8-i kecibse, bu zaman b+ tree yaranir


8. Linked Hash Set ve Hash Set ferqi?

Linked Hash Set elave olunma ardicilligini gozleyir.


9. Stack ile Queue ferqi?

Stack - LIFO, Queue ise - FIFO prinsipi ile iwleyir.


10. Genericlerin bize verdiyi avantajlari:

1 - Code reusability

2 - Compile time safety


11. Genericlerde wildcard nece hisseye bolunur?

2 hisseye bolunur: 1 - bounded tipler 2 - unbounded tipler

Unbounded ? iwaresi ile yazilir ve istenilen tipden object qebul edir.

Bounded tipler upper bound ve lower bounda bolunur.

Upper bound (extend) - verilmiw T tipinden varislik almiw istenilen klas ola biler.

Lower bound (super) - verilmiw T tipinin istenilen super klasi. 


--------------------------------------------------------------------------------------------------------------------------------

1. What is JIT?

JIT is Just In Time Compiler. It increases of efficiency of the interpreter by compiling the bytecode in the runtime. JIT compiles Code to Machine level directly for higher speeds of code execution. 

 

2. What is a ClassLoader?

A classloader in Java is a subsystem of Java Virtual Machine, dedicated to load class files when a program is executed, ClassLoader is the first one to load the executable file. 

Java has BootStrap, Extension, and Application classloaders.


3. What are the Memory Allocations available in Java?

Java has five major types of memory allocations:

- Class memory.

- Heap memory.

- Program counter memory.

- Native Method Stack memory.


4. Will the program run if I write static public void main?

Yes, the program will successfully execute if written so. Because, in Java, there is no specific rule for order of specifiers. 


5. What is the default value stored in Local Variables?

Neither the Local Variables nor any primitives and Object references have any default value stored in them. 


6. What is a Marker Interface?

An empty interface in Java is referred as a Marker Interface. Serializable and Clonable are some popular examples of Marker Interface. 


7. Why is Java not completely object oriented?

Java is not considered as a 100% object-oriented programming language, because it still makes use of 8 primitive data types. 


8. Define Singleton Classes in Java

In Java, when you make the constructor of a class as private, then that particular class can generate only one single object. This type of class is called as a Singleton class. 


9. Differentiate between instance and local variables

Instance variables are declared inside a class and the scope is limited to only a specific object. 

Local variables can be anywhere inside a method, or a specific block of code. Also, the scope is limited to the block of code where the variable is declared. 


10. Explain Java String pool

A collection of strings in Java's Heap memory is referred as Java String Pool. In case you try to create a new string object, JVM first checks for the presence of object in the pool. If available, the same object reference is shared with the variable, else a new object is created. 


11. Can we overload a static method?

No, Java does not support overloading a static method. The process would throw an error reading "static method cannot be referenced". 


12. Why is delete function is faster in Linked List than Array?

Delete function is faster in Linked List as the user needs to make a minor update to the pointer value so that the node can point to the next successor in the list


13. Why are generics used in Java Programming

Compile-time type safety is provided by using generics. Generic methods and classes help programmers to specify, a single method declaration, a set of related methods or, with a single class declaration, a set of related types. 


14. How many times the finalize method called?

The finalize method is called by the Garbage collector. For every object, the Garbage Collector calls the finalize() method just for one time. 


15. Comparator vs Comparable

Comparator

example1:

Comparator<Integer> com = new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
if (o1 % 10 > o2 % 10) return 1;
return -1;
}
};

List<Integer> list = new ArrayList<>();
list.add(43);
list.add(31);
list.add(72);
list.add(29);

System.out.println(list);

Collections.sort(list, com);
System.out.println(list);


example2:


Comparator<String> com = new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
if(o1.length() > o2.length()) return 1;
return -1;
}
};

List<String> list = new ArrayList<>();
list.add("Parvin");
list.add("Adil");
list.add("Mahammad");
list.add("Ali");

System.out.println(list);
Collections.sort(list, com);
System.out.println(list);


example3:

package org.example;

public class Student {
public String name;
public int age;

public Student(String name) {
this.name = name;
}

public Student(String name, int age) {
this.name = name;
this.age = age;
}

@Override
public String toString() {
return "Student{name='%s', age=%d}".formatted(name, age);
}
}
Comparator<Student> com = new Comparator<Student>() {
@Override
public int compare(Student o1, Student o2) {
if(o1.age > o2.age) return 1;
return -1;
}
};

List<Student> list = new ArrayList<>();
list.add(new Student("Ali", 22));
list.add(new Student("Ahmad", 19));
list.add(new Student("Nihad", 30));
list.add(new Student("Xalid", 25));

System.out.println(list);
Collections.sort(list, com);
System.out.println(list);


Comparable

example1:

package org.example;

public class Student implements Comparable<Student>{
public String name;
public int age;

public Student(String name) {
this.name = name;
}

public Student(String name, int age) {
this.name = name;
this.age = age;
}

@Override
public String toString() {
return "Student{name='%s', age=%d}".formatted(name, age);
}

@Override
public int compareTo(Student o) {
if(this.age > o.age) return 1;
return -1;
}
}


package org.example;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Test {
public static void main(String[] args) {
Comparator<Student> com = new Comparator<Student>() {
@Override
public int compare(Student o1, Student o2) {
if(o1.age > o2.age) return 1;
return -1;
}
};

List<Student> list = new ArrayList<>();
list.add(new Student("Ali", 22));
list.add(new Student("Ahmad", 19));
list.add(new Student("Nihad", 30));
list.add(new Student("Xalid", 25));

System.out.println(list);
Collections.sort(list);
System.out.println(list);
}
}
























Комментарии

Популярные сообщения из этого блога

Lesson1: JDK, JVM, JRE

SE_21_Lesson_11: Inheritance, Polymorphism

SE_21_Lesson_9: Initialization Blocks, Wrapper types, String class