Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

1) Why String, Integer and other wrapper classes are considered good keys in HashMap?

String is most frequently used key as well because String is immutable and final, and
overrides equals and hashcode() method

2) Can we use any custom object as a key in HashMap?


you can use any Object as key in Java HashMap provided it follows equals and
hashCode contract

3) Can we use ConcurrentHashMap in place of Hashtable?

Lista niz razlika


Imutabilmni objekti- kako napraviti
Deep copy, shell of copy(clone metoda)

Just in time- direktno na masinski


Funkcion interfejsi – novi predicate, stari

Indexi – cela tabela menja kada ubacujes nove reinndeksiranje r=traje

Spring dozvoljava da idu 2 reda sa istim id

Jsonwebtoken za auth korisnika roll da li je ok da se stave


Thread- race codtion
Strat vs run
Wait sleep da li je staticka
Sinh monitor, monitori brojacki semafor

Koje resurse dele tredovi


Svaki tred ima svoj stek, registar procesora program conuter, data segnet zajednicki
Da li moze da se naprave bean isti- drugo ime

27. How can annotation wiring be turned on in Spring?

To allow annotation wiring, include <context:annotation-config/> in your XML


configuration file: <beans
    //...
    xmlns:context="http://www.springframework.org/schema/context"
    //...
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-2.5.xsd">
    //...
 
    <context:annotation-config /> //annotation wiring enabled here
    //...
</beans>
29. What is Reactive Programming?

Reactive Programming is a programming paradigm that relies on programmed actions trigger on


events rather than based on the chronological order of the code. Reactive programs make
efficient use of computer resources and scale well with just a few threads. Its non-sequential
form allows you to avoid stack blocking and maintain responsiveness.

30. What is Spring Webflux?

Webflux is a reactive web framework that serves as an alternative to MVC. Webflux provides
better scalability and prevents stack blocking.

2. Can Spring Boot allow Spring MVC or Spring WebFlux in the same
application?

Boot allows both in the same application but can only apply one at a time. WebFlux is a non-
blocking framework while MVC is a blocking framework, making them incompatible together.

4. What is a Proxy in Spring?

A Proxy is an object created after applying advice to a target object. Proxies are used to perform
meta-programming operations like intercepting an object call or altering an object’s property.

35. When is the target object and proxy object the same?

This is a “gotcha” question used to test if you know how different object types interact. The
target and proxy objects are the same when dealing with client objects.

38. What are the ways Hibernate can be accessed using Spring?

Hibernate ORM is an object-relational mapping framework for Java. It is used with Spring to
map object-oriented domain models to a relational database. Hibernate can be accessed in Spring
in the following two ways:

1. First, extend HibernateDAOSupport and then apply an AOP Interceptor node


2. Use Inversion of Control with Hibernate Template and Callback structures

What Are the Benefits of Using Spring?

 Lightweight: there is a slight overhead of using the framework in development


 Inversion of Control (IoC): Spring container takes care of wiring dependencies of
various objects, instead of creating or looking for dependent objects
 Aspect Oriented Programming (AOP): Spring supports AOP to separate business logic
from system services
 IoC container: it manages Spring Bean life cycle and project specific configurations
 MVC framework: that is used to create web applications or RESTful web services,
capable of returning XML/JSON responses
 Transaction management: reduces the amount of boiler-plate code in JDBC operations,
file uploading, etc., either by using Java annotations or by Spring Bean XML
configuration file
 Exception Handling: Spring provides a convenient API for translating technology-
specific exceptions into unchecked exceptions

Q15. What Is Spring Security?

Spring Security is a separate module of the Spring framework that focuses on providing
authentication and authorization methods in Java applications. It also takes care of most of the
common security vulnerabilities such as CSRF attacks. To use Spring Security in web
applications, annotation: @EnableWebSecurity.

Q17. Name Some of the Design Patterns Used in the Spring Framework?

 Singleton Pattern: Singleton-scoped beans


 Factory Pattern: Bean Factory classes
 Prototype Pattern: Prototype-scoped beans
 Adapter Pattern: Spring Web and Spring MVC
 Proxy Pattern: Spring Aspect Oriented Programming support
 Template Method Pattern: JdbcTemplate, HibernateTemplate, etc.
 Front Controller: Spring MVC DispatcherServlet
 Data Access Object: Spring DAO support
 Model View Controller: Spring MVC

Q8. What is the difference between Array list and vector in Java?

ArrayList Vector

Array List is not synchronized.  Vector is synchronized.

Array List is fast as it’s non-synchronized. Vector is slow as it is thread safe.

If an element is inserted into the Array List, it


Vector defaults to doubling size of its array.
increases its Array size by 50%.

Array List does not define the increment size. Vector defines the increment size.
Vector can use both Enumeration and Iterator for
traversing.
Array List can only use Iterator for traversing
an Array List.

Q13. What is JIT compiler in Java?

JIT stands for Just-In-Time compiler in Java. It is a program that helps in converting the Java
bytecode into instructions that are sent directly to the processor. By default, the JIT compiler is
enabled in Java and is activated whenever a Java method is invoked. The JIT compiler then
compiles the bytecode of the invoked method into native machine code, compiling it “just in
time” to execute. Once the method has been compiled, the JVM summons the compiled code of
that method directly rather than interpreting it. This is why it is often responsible for the
performance optimization of Java applications at the run time.

Q22. What is the difference between break and continue statements?

Q23.What is an infinite loop in Java?

Q29. What is a classloader in Java?

The Java ClassLoader is a subset of JVM (Java Virtual Machine) that is responsible for loading
the class files. Whenever a Java program is executed it is first loaded by the classloader. Java
provides three built-in classloaders:

1. Bootstrap ClassLoader
2. Extension ClassLoader
3. System/Application ClassLoader

Java Core

Questions

 What is the difference between JVM, JDK and JRE?


 What is default value of not-initialised properties of the class boolean b and Integer i?
 What is default value of not-initialised variables inside local method boolean b and
Integer i?
 How to initialize final variables?
 How are strings passed to a method - by reference or by value? What’s about primitive
booleans?
 Where are booleans and Strings stored in the JVM?
 What is difference between overriding and overloading?
 Can I override overloaded method?
 Can I override private method?
 Can I override static method?
 Can I overload overridden method?
 Can I overload final method?
 Can I declare static method in interface?
 Can I change return type in overridden method?
 Can I call non-static method from static method? (Need to say about creating object
inside static method)
 What is the difference between composition and aggregation?
 What is the difference between abstraction and encapsulation?
 What is polymorphism?
 Why we need 3 different classes for working with strings: String, StringBuilder and
StringBuffer?
 What is immutability? 
 Is String immutable?
 How to implement immutable object?
 Can we rethrow same exception multiple times?
 Describe top three levels of exception hierarchy.
 What is the difference between checked and unchecked exceptions?
 Is Throwable an interface or a class?
 Can we use try-finally without catch? 
 In a method, try {return 1} finally {return 2;}. What will be returned?
 try {throw new Exception();} catch(Exception ex){throw new Exception();}finally{...}.
Will “finally” be executed?
 Why HashMap uses LinkedList inside it instead of ArrayList?
 Can I call private method outside class?
 What is a transient variable?
 What is “static” keyword?
 Is multiple inheritance supported in Java?
 Can I call more than one constructor from the constructor? 
 Can I override a constructor?
 Can hashCode() return negative value?
 GC algorithms and types of memory
 What will happen if a runtime exception is thrown from a static initialization block?
 Complexity of getting an object from a hash map (big O notation) in the worst case
(when hashCode is a constant).
 HashSet vs TreeSet
 Why would we use Optional class?

Java 8
 Why defaults methods in interface were added in Java 8?
 What is the difference between Stream and List?
 What are intermediate methods in streams?
 What can’t be done with parallel streams?
 Describe three main parts of lambda expressions
 Main features of new DateTime API

Multithreading

Questions
 What is the difference between Thread and Process?
 What is the difference between Thread.start() and Thread.run()?
 What is the purpose of volatile keyword?
 What is semaphore?
 What is the difference between sleep and wait?
 How I can get an exception from some other thread?
 What happens when an exception is thrown from a thread and it doesn’t have an
exception handler?
 What states of Thread do you know?
 A thread have been started and then finished their work. Can I start this thread again?
 How to implement thread safe singletone?
 How many stack do we have in JVM?
 Future vs Callable

Spring

Questions
 What are possible scopes of the bean?
 Is it possible to have two singleton beans of the same type in the same spring context?
 What will happen if we inject a prototype scope bean into singleton scope bean?
 I create a singleton bean and autowire a prototype bean into it. After that I call the
singleton bean 10 times. How many prototype beans will be created? How to do that
prototype bean is created for each call of singletone.
 How this situation can occur: I annotate one bean as a singleton scope bean, after that
start application and in VisualVM I see that there are 2 instances of this bean?
 All possible ways to inject dependencies in Spring.
 How to inject a dependency from a non-spring context?
 How to use a bean from a spring context outside of the spring application?
 Are beans thread-safe?
 What is the difference between BeanFactory and ApplicationContext?
 What does the Spring bean lifecycle look like?
 What is Spring Boot?
 Name some of the Design Patterns used in the Spring Framework?
 What is the role of the @Autowired annotation?
 How to handle exceptions in Spring MVC environment?
 Name some standard Events in spring framework
 Integration testing / integration context in spring
 Transaction Management (@Transactional) 
 How to work with two databases in one application?
 How is it possible that jars inside an “uber jar” appear in the class path?

Resources
 Spring In Action (4th edition)
 Baeldung: Spring Interview Questions

Hibernate

Questions
 Is Session object thread-safe?
 It is necessary to run three queries in parallel with hibernate. Will it require three session
objects or one session object will be enough?
 How to map one entity to two tables?
 What is first-level cache?
 Explain all states of entity.
 How to implement distributed cache in Hibernate?
 Different types of fetching
 What is difference between Hibernate Session get() and load() method?
 What is automatic dirty checking in Hibernate?
 What is Query Cache in Hibernate?
 What are the inheritance mapping strategies?
 What will happen if lazy loaded entity is accessed in detached state?
 When id is set for entity?
 In what cases equals() and hashCode() should be overridden when using Hibernate?
 Distributed transactions/multiple EntityManagers/XA transactions(managers)
 Lazy loading collection was not loaded but session was closed. How to load this
collection?

Resources
 Java Persistence with Hibernate
 High-Performance Java Persistence
Databases
 Explain all types of joins
 What is index?
 Why we don’t use index for every column?
 Explain Isolation levels

SQL
 How to find number of customers in each location? (TABLE customer(name,
location_id))
 How to implement MANY-TO-MANY relationship?
 What we will get if we execute Select * From A, B ? (TABLE A (a), TABLE B(b))
 There is a table with duplicates. How to delete duplicates?
 What is a prepared statement?
 What are the benefits of using prepared statements?
 When would we use “having” key-word in an SQL query?

REST

Questions
 What is JAX/RS?
 What is Resource in REST?
 What is the difference between GET and POST requests?
 What are the parts of HTTP request?
 How can you send arguments via REST (possible answers: query string, body, headers)
 How to say to server, that it should work with XML, not with JSON
 How we can make REST endpoints secure?
 What is content type negotiation?
 What is an idempotent operation?
 How to implement stateful service using REST?

Design Patterns
 SOLID with examples from Java
 Describe Singleton pattern
 What is Chain of Responsibility pattern
 Difference between Factory and Builder patterns
 “Template method” pattern.
 You opinion on if composition is better than inheritance.
 There are two classes class A {void a();} and class B {void b();} How to reuse methods
a() and b() in a new class? (ans: use composition)
 Functional vs Imperative programming.

You might also like