Java Interview: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
Line 236: Line 236:
# We'll create the following aspect (using AspectJ annotations) taking advantage of <code>@Repository</code> stereotype
# We'll create the following aspect (using AspectJ annotations) taking advantage of <code>@Repository</code> stereotype


; Spring framework defines 6 types of scopes
; [https://www.baeldung.com/spring-bean-scopes Spring framework defines 6 types of scopes]
# Singleton
# Singleton
# Prototype
# Prototype

Revision as of 08:11, 26 October 2020

  1. MVC
    1. Model
    2. View
    3. Controller
  2. SOLID Design Principles
    1. Single Responsibility Principle
    2. Open-Closed Principle
    3. Liskov Substitution Principle
    4. Interface Segregation Principle
    5. Dependency Inversion Principle
  1. Design Pattern
    1. Creational Design Patterns
      1. Factory Pattern
      2. Prototype Pattern
      3. Builder Pattern
      4. Singletons
    2. Structural Design Patterns
      1. Adapter Pattern
      2. Composite Pattern
      3. Decorator Pattern
    3. Behavioral Design Patterns
      1. Strategy Pattern
      2. State Pattern
STUPID Practices in Programming
  1. S for Singleton
  2. T for Tight Coupling
  3. U for Untestability
  4. P for Premature Optimization
  5. I for Indescriptive Naming
  6. D for Duplication
ACID
  1. Atomicity
  2. Consistency
  3. Isolation
  4. Durability

Terminology

OOP Features
  1. Encapsulation
  2. Inheritance
  3. Polymorphism
Composition vs Aggregation
Both are Association
  1. Composition: A "owns" B
  2. Aggregation: A "uses" B
Collections framework
  1. Set
    1. HashSet
    2. LinkedHashSet
    3. TreeSet
  2. List
    1. ArrayList
    2. LinkedList
    3. Vector
  3. Map
    1. HasMap
    2. LinkedHashMap
    3. Hashtable
    4. TreeMap
Network OSI Model
  1. Media Layer
    1. Physical Layer: Ethernet, 802.11 (Bit, Symbol)
    2. Data Link Layer: MAC, ARP, PPP (Frame)
    3. Network Layer: IPv4, IPv6 (Packet)
  2. Host Layer
    1. Transport Layer (Segment, Datagram)
    2. Session Layer (Data)
    3. Presentation Layer (Data)
    4. Application Layer: (DNS, Data)
JSON
JavaScript Object Notation
  1. Replacement for XML in AJAX
  2. It was derived from JavaScript
  3. Language-independent data format
  4. consisting of key–value pairs & array
  5. Internet media type is application/json
  6. JSON filenames use the extension .json
IoC
Inversion of control
DI
Dependency Injection
TCP vs. UDP
  1. TCP is a connection oriented protocol
  2. UDP is a connection less protocol
  3. TCP provides error checking support
  4. TCP Guarantees delivery of data
Transactional Phenomena
  1. Dirty Read (Not committed data read)
  2. Non Repeatable read (Reads same row twice)
  3. Phantom Read (Same Query Rows different)
Transactional Isolation levels
  1. Read Uncommitted
    1. Allowing dirty reads
  2. Read Committed
    1. Not allows dirty read
    2. holds a read or write lock on the current row
  3. Repeatable Read
    1. Most restrictive isolation level
    2. Holds read locks on all rows it references
    3. Writes locks on all rows it inserts, updates, or deletes
    4. Other transaction cannot read, update or delete these rows
    5. Consequently it avoids non-repeatable read
  4. Serializable
    1. Highest isolation level
    2. A serializable execution is guaranteed
Statefulness
RESTful Web services are completely stateless. Managing the state of conversation is the complete responsibility of the client itself. The server does not help you with this. Normally, a SOAP Web services are stateless – but you can easily make SOAP API stateful by changing the code on the server.
TCP/IP
TCP/IP style networking specifies a serialized, predictable, and reliable stream of data in the form of a packet. Servers and clients communicate through a reliable channel, such as TCP socket, have a dedicated point-to-point channel between themselves. They make a connection, transmit the data, and then close the connection. All of the data visit over the channel and are received in the same order in which it is sent.
Datagrams
Datagrams are groups(bundles) of information passed from one device to another over the network. When the datagram has been released for its intended target, there is no assurance that it will arrive or even that someone will be there to catch the datagram packets. Likewise, when the datagram is received, there is no assurance that it has not been damaged in the transit or that whosoever sent it, is still there to receive a response.
DatagramSocket
This class represents a socket for sending and receiving a datagram packet. A datagram socket provides sending or receiving ends for a connectionless packet. Each packet is sent or received on the socket. Many packets are sent from one machine to another and maybe routed differently in any order.
DatagramPacket
This class represents a datagram packet. The DatagramPacket class provides a connectionless packet delivery service. Each message routes from one machine to another based on the information contained within that packet. Numerous packets are sent from one host to another that may route differently and may arrive in random order.
Collections framework
The Java collections framework is a set of classes and interfaces that implement commonly reusable collection data structures. Although referred to as a framework, it works in a manner of a library. The collections framework provides both interfaces that define various collections and classes that implement them.
Optimistic Locking
  1. In order to use optimistic locking, we need to have an entity including a property with @Version annotation. While using it, each transaction that reads data holds the value of the version property.
  2. Before the transaction wants to make an update, it checks the version property again.
  3. If the value has changed in the meantime an OptimisticLockException is thrown. Otherwise, the transaction commits the update and increments a value version property.
OptimisticLockException
  1. When the persistence provider discovers optimistic locking conflicts on entities, it throws OptimisticLockException. We should be aware that due to the exception the active transaction is always marked for rollback.
  2. There is a recommended way of handling the described exception, though. We should retrieve the entity again by reloading or refreshing. Preferably in a new transaction. After that, we can try to update it once more.
OPTIMISTIC
OPTIMISTIC will ensure the other object has not been updated at the time of your commit.
OPTIMISTIC_FORCE_INCREMENT
OPTIMISTIC_FORCE_INCREMENT will ensure the other object has not been updated, and will increment its version on commit.
PESSIMISTIC_READ
  1. Whenever we want to just read data and don't encounter dirty reads, we could use PESSIMISTIC_READ (shared lock).
  2. We won't be able to make any updates or deletes though.
PESSIMISTIC_WRITE
  1. Any transaction that needs to acquire a lock on data and make changes to it should obtain the PESSIMISTIC_WRITE lock.
  2. According to the JPA specification, holding PESSIMISTIC_WRITE lock
  3. prevent other transactions from reading, updating or deleting the data.
PESSIMISTIC_FORCE_INCREMENT
  1. This lock works similarly to PESSIMISTIC_WRITE, but it was introduced to cooperate with versioned entities – entities which have an attribute annotated with @Version.
  2. Any updates of versioned entities could be preceded with obtaining the PESSIMISTIC_FORCE_INCREMENT lock. Acquiring that lock results in updating the version column.
  3. It's up to a persistence provider to determine whether it supports PESSIMISTIC_FORCE_INCREMENT for unversioned entities or not. If it doesn't, it throws the PersistanceException
PessimisticLockScope.NORMAL
We should know that the PessimisticLockScope.NORMAL is the default scope. With this locking scope, we lock the entity itself. When used with joined inheritance it also locks the ancestors.
PessimisticLockScope.EXTENDED
  1. The EXTENDED scope covers the same functionality as NORMAL. In addition, it's able to block related entities in a join table.
  2. Simply put, it works with entities annotated with @ElementCollection or @OneToOne, @OneToMany etc. with @JoinTable.

SDLC

Most popular software development models
  1. Waterfall
  2. Scrum
  3. Lean
  4. Kanban
  5. Feature driven development
Waterfall
This is the oldest, most trusted and most straightforward of the software development methodologies. It resembles the waterfall, as each stage can be completed only after the previous one is finished. The stages include product requirement gathering, design and development of the software, testing, release and maintenance.
Agile
Agile is a structured and iterative approach to project management and product development. It recognizes the volatility of product development, and provides a methodology for self-organizing teams to respond to change without going off the rails. Today, agile is hardly a competitive advantage. No one has the luxury to develop a product for years or even months in a black box. This means it’s more important than ever to get it right.
Kanban
Kanban is all about visualizing your work, limiting work in progress, and maximizing efficiency(or flow). Kanban teams focus on reducing the time it takes to take a project(or user story) from start to finish. They do this by using a kanban board and continuously improving their flow of work.
Scrum
Scrum teams commit to ship working software through set intervals called sprints. Their goal is to create learning loops to quickly gather and integrate customer feedback. Scrum teams adopt specific roles, create special artifacts, and hold regular ceremonies to keep things moving forward.
Lean
Lean software development model has its roots in Toyota approach to doing things: when you need to change something, do only the changes that bring the most VALUE, require the least EFFORT (budget) to be accomplished and take only 30% of the TIME planned. Such approach helped Toyota build a workflow able to switch their car constructing conveyors to producing another model of Toyota vehicles in mere hours, while the other manufacturers needed weeks to do it.
Feature Driven Development
In feature driven development or FDD model, features are the cornerstones of development. As the features are added, the new sets of requirements are introduced. This works best for larger internal teams of developers, working on the incremental improvement of a large-scale product. This approach is also quite often used as an interim workflow between a Waterfall and Agile software development methodologies.

Spring

@ComponentScan
  1. Configures which packages to scan for classes with annotation configuration. We can specify the base package names directly with one of the basePackages or value arguments (value is an alias for basePackages)
@Component
  1. Is a class level annotation. During the component scan, Spring Framework automatically detects classes annotated with @Component.
@Repository
  1. DAO or Repository classes usually represent the database access layer in an application, and should be annotated with @Repository
  2. One advantage of using this annotation is that it has automatic persistence exception translation enabled.
  3. When using a persistence framework such as Hibernate, native exceptions thrown within classes annotated
  4. With @Repository will be automatically translated into subclasses of Spring's DataAccessExeption
@Service
  1. The business logic of an application usually resides within the service layer
  2. Use the @Service annotation to indicate that a class belongs to that layer
@Controller
  1. Is a class level annotation which tells the Spring Framework that this class serves as a controller in Spring MVC
@Configuration
  1. Configuration classes can contain bean definition methods annotated with @Bean
Stereotype Annotations and AOP
  1. When we use Spring stereotype annotations, it's easy to create a pointcut that targets all classes that have a particular stereotype.
  2. For example, suppose we want to measure the execution time of methods from the DAO layer.
  3. We'll create the following aspect (using AspectJ annotations) taking advantage of @Repository stereotype
Spring framework defines 6 types of scopes
  1. Singleton
  2. Prototype
  3. Request
  4. Session
  5. Application
  6. Websocket

Hibernate

DevOps

DevOps
The DevOps is a combination of two words, one is software Development, and second is Operations. This allows a single team to handle the entire application lifecycle, from development to testing, deployment, and operations. DevOps helps us to reduce the gap between software developers, quality assurance (QA) engineers, and system administrators.
DevOps tools such as Git, Docker, Jenkins, Chef, Puppet, Ansible, SaltStack, Nagios and Kubernetes.
  1. Automation
  2. Collaboration
  3. Integration
  4. Configuration
Puppet
Puppet is the most powerful configuration management tool in the solar system. It’s the engine that drives your compliance, baseline, drift remediation, and deployment needs. It has always been and always will be open source, with freely downloadable operating system-specific agent packages, a massively scalable server, and data warehousing capabilities via PuppetDB.
Ansible
Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code. It runs on many Unix-like systems, and can configure both Unix-like systems as well as Microsoft Windows. It includes its own declarative language to describe system configuration. Ansible was written by Michael DeHaan and acquired by Red Hat in 2015. Ansible is agentless, temporarily connecting remotely via SSH or Windows Remote Management (allowing remote PowerShell execution) to do its tasks.

REST

HTTP ETag
  1. The ETag or entity tag is part of HTTP, the protocol for the World Wide Web. It is one of several mechanisms that HTTP provides for Web cache validation, which allows a client to make conditional requests. This allows caches to be more efficient and saves bandwidth, as a Web server does not need to send a full response if the content has not changed. ETags can also be used for optimistic concurrency control as a way to help prevent simultaneous updates of a resource from overwriting each other.
  2. An ETag is an opaque identifier assigned by a Web server to a specific version of a resource found at a URL. If the resource representation at that URL ever changes, a new and different ETag is assigned. Used in this manner, ETags are similar to fingerprints and can quickly be compared to determine whether two representations of a resource are the same.

Security

JWT
JSON Web Token (JWT) is a means of representing claims to be transferred between two parties. The claims in a JWT are encoded as a JSON object that is digitally signed using JSON Web Signature (JWS) and/or encrypted using JSON Web Encryption (JWE).
OAuth
OAuth is an open standard for access delegation, commonly used as a way for Internet users to grant websites or applications access to their information on other websites but without giving them the passwords. This mechanism is used by companies such as Amazon, Google, Facebook, Microsoft and Twitter to permit the users to share information about their accounts with third party applications or websites.
OAuth 2.0
OAuth 2.0 is the industry-standard protocol for authorization. OAuth 2.0 focuses on client developer simplicity while providing specific authorization flows for web applications, desktop applications, mobile phones, and living room devices.

HR & Admin

Responsibility
  1. Organogram
  2. Designation
  3. Reporting Senior
  4. Team Role to be play
    1. Teammate
    2. Teamlead
Facility
  1. Offer Letter
    1. NOC
    2. Visa, DependentPass
  2. Health Insurance
    1. Me and Dependent
Financial Benefits
  1. Incentive
  2. Festival Bonus
  3. Increment Policy
  4. Income TAX Policy
Termination Policy
  1. Notice Period
  2. NOC
Reason for Job Switch
  1. Domain Knowledge
  2. Technology
  3. Career
Policy
  1. Leave or Vacation
    1. Sick Leave Policy
    2. Annual Leave Policy
    3. Annual Leave with Return Air Ticket
    4. Leave Replacement Salary & Ticket Policy
  2. Employment Policy
    1. Provision Period Policy
    2. Permanent Employment Policy

References