Java Interview: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(82 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
# Design Pattern | {| | ||
| valign="top" | | |||
# MVC | |||
## Model | |||
## View | |||
## Controller | |||
# [https://www.jrebel.com/blog/solid-principles-in-java SOLID Design Principles] | |||
## Single Responsibility Principle | |||
## Open-Closed Principle | |||
## Liskov Substitution Principle | |||
## Interface Segregation Principle | |||
## Dependency Inversion Principle | |||
| valign="top" | | |||
# [https://www.xinjianl.com/Notes/0x3-Computer-Science/0x34-Language/0x340-Foundation/#7-design-pattern Design Pattern] | |||
## Creational Design Patterns | ## Creational Design Patterns | ||
### Factory Pattern | ### Factory Pattern | ||
Line 12: | Line 26: | ||
### Strategy Pattern | ### Strategy Pattern | ||
### State Pattern | ### State Pattern | ||
| valign="top" | | |||
; [https://openclassrooms.com/en/courses/5684096-use-mvc-solid-principles-and-design-patterns-in-java/6417836-avoid-stupid-practices-in-programming STUPID Practices in Programming] | |||
# S for Singleton | |||
# T for Tight Coupling | |||
# U for Untestability | |||
# P for Premature Optimization | |||
# I for Indescriptive Naming | |||
# D for Duplication | |||
; [https://www.geeksforgeeks.org/acid-properties-in-dbms/ ACID] | |||
# [https://www.geeksforgeeks.org/acid-properties-in-dbms/#:~:text=Atomicity Atomicity] | |||
# [https://www.geeksforgeeks.org/acid-properties-in-dbms/#:~:text=Consistency Consistency] | |||
# [https://www.geeksforgeeks.org/acid-properties-in-dbms/#:~:text=Isolation Isolation] | |||
# [https://www.geeksforgeeks.org/acid-properties-in-dbms/#:~:text=Durability Durability] | |||
|} | |||
==Terminology== | |||
{| | |||
| valign="top" | | |||
; OOP Features | |||
# Encapsulation (Types) | |||
# Inheritance (Type) | |||
# Polymorphism (Type) | |||
; [https://www.xinjianl.com/note/software/software-architecture/design-pattern/ Composition vs Aggregation] | |||
: Both are Association | |||
# '''Composition:''' A "owns" B | |||
# '''Aggregation:''' A "uses" B | |||
; Inheritance | |||
# Single Inheritance | |||
# Multiple Inheritance | |||
# Multilevel Inheritance | |||
# Hierarchical Inheritance | |||
# Hybrid Inheritance | |||
; Collections framework | |||
# Set | |||
## [https://www.w3schools.com/java/java_hashset.asp HashSet] | |||
## LinkedHashSet | |||
## TreeSet | |||
# List | |||
## [https://www.w3schools.com/java/java_arraylist.asp ArrayList] | |||
## [https://www.w3schools.com/java/java_linkedlist.asp#:~:text=LinkedList%20Methods LinkedList] | |||
## Vector | |||
# Map | |||
## [https://www.w3schools.com/java/java_hashmap.asp HasMap] | |||
## LinkedHashMap | |||
## Hashtable | |||
## TreeMap | |||
| valign="top" | | |||
; [https://www.xinjianl.com/note/software/#:~:text=0x56%20Network Network OSI Model] | |||
# Media Layer | |||
## '''Physical Layer:''' Ethernet, 802.11 (Bit, Symbol) | |||
## '''Data Link Layer:''' MAC, ARP, PPP (Frame) | |||
## '''Network Layer:''' IPv4, IPv6 (Packet) | |||
# Host Layer | |||
## '''Transport Layer''' (Segment, Datagram) | |||
## '''Session Layer''' (Data) | |||
## '''Presentation Layer''' (Data) | |||
## '''Application Layer:''' (DNS, Data) | |||
; JSON | |||
: JavaScript Object Notation | |||
# Replacement for XML in AJAX | |||
# It was derived from JavaScript | |||
# Language-independent data format | |||
# consisting of key–value pairs & array | |||
# Internet media type is <code>application/json</code> | |||
# JSON filenames use the extension <code>.json</code> | |||
; IoC | |||
: Inversion of control | |||
; DI | |||
: Dependency Injection | |||
| valign="top" | | |||
; TCP vs. UDP | |||
# TCP is a connection oriented protocol | |||
# UDP is a connection less protocol | |||
# TCP provides error checking support | |||
# TCP Guarantees delivery of data | |||
; Transactional Phenomena | |||
# Dirty Read (Not committed data read) | |||
# Non Repeatable read (Reads same row twice) | |||
# Phantom Read (Same Query Rows different) | |||
; Transactional Isolation levels | |||
# Read Uncommitted | |||
## Allowing dirty reads | |||
# Read Committed | |||
## Not allows dirty read | |||
## holds a read or write lock on the current row | |||
# Repeatable Read | |||
## Most restrictive isolation level | |||
## Holds read locks on all rows it references | |||
## Writes locks on all rows it inserts, updates, or deletes | |||
## Other transaction cannot read, update or delete these rows | |||
## Consequently it avoids non-repeatable read | |||
# Serializable | |||
## Highest isolation level | |||
## A serializable execution is guaranteed | |||
|} | |||
; [https://restfulapi.net/soap-vs-rest-apis/#:~:text=RESTful%20Web%20services%20are%20completely%20stateless.%20Managing%20the,stateful%20by%20changing%20the%20code%20on%20the%20server 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. | |||
; [https://www.tutorialandexample.com/java-datagramsocket-and-java-datagrampacket/ 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. | |||
; [https://www.tutorialandexample.com/java-datagramsocket-and-java-datagrampacket/ 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. | |||
; [https://www.tutorialandexample.com/java-datagramsocket-and-java-datagrampacket/ 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. | |||
; [https://www.tutorialandexample.com/java-datagramsocket-and-java-datagrampacket/ 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. | |||
; [https://www.baeldung.com/jpa-optimistic-locking Optimistic Locking] | |||
# 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. | |||
# Before the transaction wants to make an update, it checks the version property again. | |||
# If the value has changed in the meantime an OptimisticLockException is thrown. Otherwise, the transaction commits the update and increments a value version property. | |||
; [https://www.baeldung.com/jpa-optimistic-locking OptimisticLockException] | |||
# 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. | |||
# 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. | |||
; [https://www.baeldung.com/jpa-optimistic-locking#1-optimistic-read OPTIMISTIC] | |||
: <code>OPTIMISTIC</code> will ensure the other object has not been updated at the time of your commit. | |||
; [https://www.baeldung.com/jpa-optimistic-locking#2-optimisticincrement-write OPTIMISTIC_FORCE_INCREMENT] | |||
: <code>OPTIMISTIC_FORCE_INCREMENT</code> will ensure the other object has not been updated, and will increment its version on commit. | |||
; [https://www.baeldung.com/jpa-pessimistic-locking#1-pessimisticread PESSIMISTIC_READ] | |||
# Whenever we want to just read data and don't encounter dirty reads, we could use <code>PESSIMISTIC_READ</code> (shared lock). | |||
# We won't be able to make any updates or deletes though. | |||
; [https://www.baeldung.com/jpa-pessimistic-locking#2-pessimisticwrite PESSIMISTIC_WRITE] | |||
# Any transaction that needs to acquire a lock on data and make changes to it should obtain the <code>PESSIMISTIC_WRITE</code> lock. | |||
# According to the JPA specification, holding <code>PESSIMISTIC_WRITE</code> lock | |||
# prevent other transactions from reading, updating or deleting the data. | |||
; [https://www.baeldung.com/jpa-pessimistic-locking#3-pessimisticforceincrement PESSIMISTIC_FORCE_INCREMENT] | |||
# This lock works similarly to <code>PESSIMISTIC_WRITE</code>, but it was introduced to cooperate with versioned entities – entities which have an attribute annotated with <code>@Version</code>. | |||
# Any updates of versioned entities could be preceded with obtaining the <code>PESSIMISTIC_FORCE_INCREMENT</code> lock. Acquiring that lock results in updating the version column. | |||
# It's up to a persistence provider to determine whether it supports <code>PESSIMISTIC_FORCE_INCREMENT</code> for unversioned entities or not. If it doesn't, it throws the <code>PersistanceException</code> | |||
; [https://www.baeldung.com/jpa-pessimistic-locking#1-pessimisticlockscopenormal PessimisticLockScope.NORMAL] | |||
: We should know that the <code>PessimisticLockScope.NORMAL</code> is the default scope. With this locking scope, we lock the entity itself. When used with joined inheritance it also locks the ancestors. | |||
; [https://www.baeldung.com/jpa-pessimistic-locking#2-pessimisticlockscopeextended PessimisticLockScope.EXTENDED] | |||
# The <code>EXTENDED</code> scope covers the same functionality as <code>NORMAL</code>. In addition, it's able to block related entities in a join table. | |||
# Simply put, it works with entities annotated with <code>@ElementCollection</code> or <code>@OneToOne</code>, <code>@OneToMany</code> etc. with @JoinTable. | |||
==SDLC== | |||
; Most popular software development models | |||
# Waterfall | |||
# Scrum | |||
# Lean | |||
# Kanban | |||
# 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. | |||
; [https://www.atlassian.com/agile 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. | |||
; [https://www.atlassian.com/agile/kanban 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. | |||
; [https://www.atlassian.com/agile/scrum 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== | |||
; [https://www.baeldung.com/spring-bean-annotations#scanning @ComponentScan] | |||
# 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) | |||
; [https://www.baeldung.com/spring-bean-annotations#component @Component] | |||
# Is a class level annotation. During the component scan, Spring Framework automatically detects classes annotated with <code>@Component</code>. | |||
; [https://www.baeldung.com/spring-bean-annotations#repository @Repository] | |||
# DAO or Repository classes usually represent the database access layer in an application, and should be annotated with <code>@Repository</code> | |||
# One advantage of using this annotation is that it has automatic persistence exception translation enabled. | |||
# When using a persistence framework such as Hibernate, native exceptions thrown within classes annotated | |||
# With <code>@Repository</code> will be automatically translated into subclasses of Spring's <code>DataAccessExeption</code> | |||
; [https://www.baeldung.com/spring-bean-annotations#service @Service] | |||
# The business logic of an application usually resides within the service layer | |||
# Use the <code>@Service</code> annotation to indicate that a class belongs to that layer | |||
; [https://www.baeldung.com/spring-bean-annotations#controller @Controller] | |||
# Is a class level annotation which tells the Spring Framework that this class serves as a controller in Spring MVC | |||
; [https://www.baeldung.com/spring-bean-annotations#configuration @Configuration] | |||
# Configuration classes can contain bean definition methods annotated with <code>@Bean</code> | |||
; [https://www.baeldung.com/spring-bean-annotations#annotations Stereotype Annotations and AOP] | |||
# When we use Spring stereotype annotations, it's easy to create a pointcut that targets all classes that have a particular stereotype. | |||
# For example, suppose we want to measure the execution time of methods from the DAO layer. | |||
# We'll create the following aspect (using AspectJ annotations) taking advantage of <code>@Repository</code> stereotype | |||
; [https://www.baeldung.com/spring-bean-scopes Spring framework defines 6 types of scopes] | |||
# Singleton | |||
# Prototype | |||
# Request | |||
# Session | |||
# Application | |||
# Websocket | |||
; Default Bean Scope | |||
# Singleton is default bean scope in Spring container | |||
; [https://javarevisited.blogspot.com/2017/04/difference-between-autowired-and-inject-annotation-in-spring-framework.html @Autowired vs. @Inject] | |||
# <code>@Inject</code> annotation also serves the same purpose | |||
# <code>@Inject</code> is a Java standard annotation | |||
# <code>@Autowired</code> is Spring specific | |||
==Hibernate== | |||
<syntaxhighlight lang="java"> | |||
package biz.shahed.software.http.spider.entity; | |||
import java.util.Date; | |||
import javax.persistence.*; | |||
import org.hibernate.annotations.Parameter; | |||
import org.hibernate.annotations.GenericGenerator; | |||
import biz.shahed.software.http.spider.utility.Base36Style; | |||
@Entity | |||
@Table(name = "employee") | |||
@Access(AccessType.FIELD) | |||
public class Employee implements Serializable { | |||
private static final long serialVersionUID = -2598241668007035434L; | |||
@Temporal(TemporalType.TIMESTAMP) | |||
@Column(name = "enter_at", updatable = false) | |||
private Date enterAt; | |||
@Column(name = "enter_by", length = 4, updatable = false) | |||
private String enterBy; | |||
@Temporal(TemporalType.TIMESTAMP) | |||
@Column(name = "amend_at") | |||
private Date amendAt; | |||
@Column(name = "amend_by", length = 4) | |||
private String amendBy; | |||
@Version | |||
@Column(name = "revision", nullable = false) | |||
private Long revision = 0L; | |||
@Id | |||
@Column(name = "code", length = 6) | |||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "employee_sqn") | |||
// @SequenceGenerator(name = "employee_sqn", sequenceName = "employee_sqn", initialValue = 60466176, allocationSize = 1) | |||
@GenericGenerator(name = "employee_sqn", strategy = "biz.shahed.software.http.spider.utility.Base36Style", parameters = { | |||
@Parameter(name = Base36Style.INITIAL_VALUE, value = Base36Style.DIGIT_6_MIN), | |||
@Parameter(name = Base36Style.SEQUENCE_NAME, value = "employee_sqn"), | |||
@Parameter(name = Base36Style.ALLOCATION_SIZE, value = "1"), | |||
}) | |||
private String code; | |||
@Column(name = "name", length = 64, nullable = false) | |||
private String name; | |||
@Column(name = "salary", scale = 8, precision = 2) | |||
private Double salary; | |||
@Column(name = "gender_code", length = 1, nullable = false) | |||
private String genderCode; | |||
@ManyToOne(fetch = FetchType.LAZY) | |||
@JoinColumn(name ="gender_code", referencedColumnName = "code", insertable = false, updatable = false) | |||
private Gender gender; | |||
} | |||
</syntaxhighlight> | |||
---- | |||
<syntaxhighlight lang="java"> | |||
@Column(name = "gender_code", length = 1, nullable = false) | |||
private String genderCode; | |||
@ManyToOne(fetch = FetchType.LAZY) | |||
@JoinColumn(name ="gender_code", referencedColumnName = "code", insertable = false, updatable = false) | |||
private Gender gender; | |||
</syntaxhighlight> | |||
---- | ---- | ||
# | <syntaxhighlight lang="java"> | ||
## | @OneToMany(mappedBy = "gender") | ||
## Open- | private Set<Employee> employees = new HashSet<>() | ||
## | |||
## | @Override | ||
## | public int hashCode() { | ||
int hash = 0; | |||
hash += (code != null ? code.hashCode() : 0); | |||
return hash; | |||
} | |||
@Override | |||
public boolean equals(Object object) { | |||
if (!(object instanceof Employee)) { | |||
return false; | |||
} | |||
Employee other = (Employee) object; | |||
if ((this.code == null && other.code != null)|| (this.code != null && !this.code.equals(other.code))) { | |||
return false; | |||
} | |||
return true; | |||
} | |||
@Override | |||
public String toString() { | |||
return String.format("%s[%s=%s]", this.getClass().getName(), "code", code); | |||
} | |||
</syntaxhighlight> | |||
==Database== | |||
; Primary Key | |||
# Cannot be a NULL | |||
# Each table can have only one primary key. | |||
# By default, Primary key is clustered index, and the data in database table is physically organized in the sequence of clustered index. | |||
# Primary key can be related to another tables as a Foreign Key. | |||
# We can generate ID automatically with the help of Auto Increment field. Primary key supports Auto Increment value. | |||
# We can define Primary key constraint on temporary table and table variable. | |||
# We can't delete primary key value from the parent table which is used as a foreign key in child table. To delete we first need to delete that primary key value from the child table. | |||
; Unique Key | |||
# Unique Constraint may have a NULL value | |||
# Each table can have more than one Unique Constraint | |||
# By default, Unique key is a unique non-clustered index | |||
# Unique Constraint can not be related with another table's as a Foreign Key | |||
; Foreign Key | |||
# Foreign key is a field in the table that is Primary key in another table. | |||
# Foreign key can accept multiple null value. | |||
# Foreign key do not automatically create an index, clustered or non-clustered. You can manually create an index on foreign key. | |||
# We can have more than one foreign key in a table. | |||
# Foreign keys do not automatically create an index, clustered or non-clustered. You must manually create an index on foreign keys. | |||
# There are actual advantages to having a foreign key be supported with a clustered index, but you get only one per table. What's the advantage? If you are selecting the parent plus all child records, you want the child records next to each other. This is easy to accomplish using a clustered index. | |||
# Having a null foreign key is usually a bad idea instead of NULL referred to as "orphan record". | |||
# We can’t define foreign key constraint on temporary table or table variable. | |||
# We can delete the foreign key value from the child table even though that refers to the primary key of the parent table. | |||
; DELETE CASCADE | |||
: Using this option, it deletes the referencing rows in the child table when the referenced row is deleted in the parent table | |||
; UPDATE CASCADE | |||
: Using UPDATE CASCADE the referencing rows are updated in the child table when the referenced row is updated in the parent table | |||
==DevOps== | |||
; [https://www.javatpoint.com/devops#:~:text=What%20is%20DevOps? 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'''. | |||
# Automation | |||
# Collaboration | |||
# Integration | |||
# Configuration | |||
; [https://puppet.com/open-source/#:~:text=Open%20Source%20Puppet 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. | |||
; [https://en.wikipedia.org/wiki/Ansible_(software) 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. | |||
==[https://en.wikipedia.org/wiki/Representational_state_transfer REST]== | |||
{| | |||
| valign="top" | | |||
; [https://restfulapi.net/http-methods/ REST Method|Verb] | |||
# GET | |||
## 200 : OK | |||
## 400 : BAD REQUEST | |||
## 404 : NOT FOUND | |||
# POST | |||
## 200 : OK | |||
## 201 : Created | |||
## 204 : No Content | |||
# PUT | |||
## 200 : OK | |||
## 201 : Created | |||
## 204 : No Content | |||
# DELETE | |||
## 200 : OK | |||
## 202 : Accepted | |||
## 204 : No Content | |||
## 404 : NOT FOUND | |||
# PATCH | |||
## 200 : OK | |||
## 204 : No Content | |||
## 404 : NOT FOUND | |||
| valign="top" | | |||
; [https://restfulapi.net/http-status-codes/#:~:text=REST%20Specific%20Status%20Codes REST Specific Status Codes] | |||
# 200 : OK | |||
## 201 : Created | |||
## 202 : Accepted | |||
## 203 : Non-Authoritative Information | |||
## 204 : No Content | |||
# 300 : Multiple Choices | |||
## 301 : Moved Permanently | |||
## 302 : Found | |||
## 303 : See Other | |||
## 304 : Not Modified | |||
## 307 : Temporary Redirect | |||
# 400 : Bad Request | |||
## 401 : Unauthorized | |||
## 403 : Forbidden | |||
## 404 : Not Found | |||
## 405 : Method Not Allowed | |||
## 406 : Not Acceptable | |||
## 412 : Precondition Failed | |||
## 415 : Unsupported Media Type | |||
# 500 : Internal Server Error | |||
## 501 : Not Implemented | |||
| valign="top" | | |||
; [https://restfulapi.net/http-status-codes/#:~:text=HTTP%20Status%20Codes%20List HTTP Status Codes] | |||
# '''100 Series''': Informational - Transfer protocol | |||
# '''200 Series:''' Success - Client’s request | |||
# '''300 Series:''' Redirection | |||
# '''400 Series:''' Client Error | |||
# '''500 Series:''' Server Error | |||
|} | |||
; [https://en.wikipedia.org/wiki/HTTP_ETag HTTP ETag] | |||
# 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. | |||
# 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== | |||
; [https://openid.net/specs/draft-jones-json-web-token-07.html 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). | |||
; [https://en.wikipedia.org/wiki/OAuth 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. | |||
; [https://oauth.net/2/ 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== | |||
{| | |||
| valign="top" | | |||
; Responsibility | |||
# Organogram | |||
# Designation | |||
# Reporting Senior | |||
# Team Role to be play | |||
## Teammate | |||
## Teamlead | |||
; Facility | |||
# Offer Letter | |||
## NOC | |||
## Visa, DependentPass | |||
# Health Insurance | |||
## Me and Dependent | |||
| valign="top" | | |||
; Financial Benefits | |||
# Incentive | |||
# Festival Bonus | |||
# Increment Policy | |||
# Income TAX Policy | |||
; Termination Policy | |||
# Notice Period | |||
# NOC | |||
; Reason for Job Switch | |||
# Domain Knowledge | |||
# Technology | |||
# Career | |||
| valign="top" | | |||
; Policy | |||
# Leave or Vacation | |||
## Sick Leave Policy | |||
## Annual Leave Policy | |||
## Annual Leave with Return Air Ticket | |||
## Leave Replacement Salary & Ticket Policy | |||
# Employment Policy | |||
## Provision Period Policy | |||
## Permanent Employment Policy | |||
|} | |||
==References== | ==References== | ||
{| | |||
| valign="top" | | |||
* [https://openclassrooms.com/en/courses/5684096-use-mvc-solid-principles-and-design-patterns-in-java Use MVC, SOLID Principles and Design Patterns in Java] | * [https://openclassrooms.com/en/courses/5684096-use-mvc-solid-principles-and-design-patterns-in-java Use MVC, SOLID Principles and Design Patterns in Java] | ||
* [https://openclassrooms.com/en/courses/5684096-use-mvc-solid-principles-and-design-patterns-in-java/6417871-organize-objects-with-structural-design-patterns Organize Objects With Structural Design Patterns] | * [https://openclassrooms.com/en/courses/5684096-use-mvc-solid-principles-and-design-patterns-in-java/6417871-organize-objects-with-structural-design-patterns Organize Objects With Structural Design Patterns] | ||
* [https://openclassrooms.com/en/courses/5684096-use-mvc-solid-principles-and-design-patterns-in-java/6417881-manage-objects-with-behavioral-design-patterns Manage Objects With Behavioral Design Patterns] | * [https://openclassrooms.com/en/courses/5684096-use-mvc-solid-principles-and-design-patterns-in-java/6417881-manage-objects-with-behavioral-design-patterns Manage Objects With Behavioral Design Patterns] | ||
* [https://openclassrooms.com/en/courses/5684096-use-mvc-solid-principles-and-design-patterns-in-java/6417861-create-objects-with-creational-design-patterns Create Objects With Creational Design Patterns] | * [https://openclassrooms.com/en/courses/5684096-use-mvc-solid-principles-and-design-patterns-in-java/6417861-create-objects-with-creational-design-patterns Create Objects With Creational Design Patterns] | ||
* [https://openclassrooms.com/en/courses/5684096-use-mvc-solid-principles-and-design-patterns-in-java/6417836-avoid-stupid-practices-in-programming Avoid STUPID Practices in Programming] | |||
* [https://www.javatpoint.com/osi-model#:~:text=Functions%20of%20the%20OSI%20Layers Functions of the OSI Layers] | |||
* [https://www.jrebel.com/blog/solid-principles-in-java SOLID Principles in Java] | * [https://www.jrebel.com/blog/solid-principles-in-java SOLID Principles in Java] | ||
* [https://www.xinjianl.com/note/software/ Computer Science] | |||
* [https://www.xinjianl.com/note/software/software-architecture/design-pattern/ Design Pattern] | |||
* [https://www.xinjianl.com/note/software/algorithm/ Algorithm] | |||
| valign="top" | | |||
* [https://medium.com/globalluxsoft/5-popular-software-development-models-with-their-pros-and-cons-12a486b569dc 5 Popular Software Development Models] | |||
* [https://www.javatpoint.com/devops#:~:text=DevOps%20Advantages%20and%20Disadvantages DevOps Advantages & Disadvantages] | |||
* [https://dzone.com/articles/all-jpa-annotations-mapping-annotations ALL the JPA Mapping Annotations] | |||
* [https://restfulapi.net/soap-vs-rest-apis/ Comparing SOAP vs REST APIs] | |||
* [https://restfulapi.net/rest-architectural-constraints/ REST Architectural Constraints] | |||
* [https://medium.com/@shavi22/solid-principles-in-java-cf9f5b167600 SOLID Principles in Java] | |||
* [https://restfulapi.net/http-status-codes/ HTTP Status Codes] | |||
* [https://www.atlassian.com/agile/kanban/kanban-vs-scrum Kanban vs. Scrum] | |||
* [https://restfulapi.net/http-methods/ HTTP Methods] | |||
* [https://www.ansible.com/ Ansible] | |||
| valign="top" | | |||
* [https://www.baeldung.com/spring-boot-12-factor 12-Factor Methodology in a Spring Boot Micro-service] | |||
* [https://medium.com/javarevisited/do-you-know-about-the-12-factor-app-in-microservices-architecture-50bd34551bd8 12 Factor App in Micro-services Architecture] | |||
* [https://12factor.net/ Twelve-Factor Methodology of Micro-service] | |||
* [https://www.patterns.dev/ Improve how you architect webapps] | |||
* [https://unix.stackexchange.com/questions/200239/ SSH Sessions Prevent From Freezing] | |||
* [https://www.castsoftware.com/glossary/what-is-software-architecture-tools-design-definition-explanation-best Software Architecture] | |||
* [[Online App]] | |||
|} |
Latest revision as of 20:29, 27 October 2024
|
|
|
Terminology
|
|
|
- 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.
- 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.
- Before the transaction wants to make an update, it checks the version property again.
- If the value has changed in the meantime an OptimisticLockException is thrown. Otherwise, the transaction commits the update and increments a value version property.
- 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.
- 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.
- Whenever we want to just read data and don't encounter dirty reads, we could use
PESSIMISTIC_READ
(shared lock). - We won't be able to make any updates or deletes though.
- Any transaction that needs to acquire a lock on data and make changes to it should obtain the
PESSIMISTIC_WRITE
lock. - According to the JPA specification, holding
PESSIMISTIC_WRITE
lock - prevent other transactions from reading, updating or deleting the data.
- This lock works similarly to
PESSIMISTIC_WRITE
, but it was introduced to cooperate with versioned entities – entities which have an attribute annotated with@Version
. - Any updates of versioned entities could be preceded with obtaining the
PESSIMISTIC_FORCE_INCREMENT
lock. Acquiring that lock results in updating the version column. - 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 thePersistanceException
- 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.
- The
EXTENDED
scope covers the same functionality asNORMAL
. In addition, it's able to block related entities in a join table. - Simply put, it works with entities annotated with
@ElementCollection
or@OneToOne
,@OneToMany
etc. with @JoinTable.
SDLC
- Most popular software development models
- Waterfall
- Scrum
- Lean
- Kanban
- 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
- 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)
- Is a class level annotation. During the component scan, Spring Framework automatically detects classes annotated with
@Component
.
- DAO or Repository classes usually represent the database access layer in an application, and should be annotated with
@Repository
- One advantage of using this annotation is that it has automatic persistence exception translation enabled.
- When using a persistence framework such as Hibernate, native exceptions thrown within classes annotated
- With
@Repository
will be automatically translated into subclasses of Spring'sDataAccessExeption
- The business logic of an application usually resides within the service layer
- Use the
@Service
annotation to indicate that a class belongs to that layer
- Is a class level annotation which tells the Spring Framework that this class serves as a controller in Spring MVC
- Configuration classes can contain bean definition methods annotated with
@Bean
- When we use Spring stereotype annotations, it's easy to create a pointcut that targets all classes that have a particular stereotype.
- For example, suppose we want to measure the execution time of methods from the DAO layer.
- We'll create the following aspect (using AspectJ annotations) taking advantage of
@Repository
stereotype
- Singleton
- Prototype
- Request
- Session
- Application
- Websocket
- Default Bean Scope
- Singleton is default bean scope in Spring container
@Inject
annotation also serves the same purpose@Inject
is a Java standard annotation@Autowired
is Spring specific
Hibernate
package biz.shahed.software.http.spider.entity;
import java.util.Date;
import javax.persistence.*;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.GenericGenerator;
import biz.shahed.software.http.spider.utility.Base36Style;
@Entity
@Table(name = "employee")
@Access(AccessType.FIELD)
public class Employee implements Serializable {
private static final long serialVersionUID = -2598241668007035434L;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "enter_at", updatable = false)
private Date enterAt;
@Column(name = "enter_by", length = 4, updatable = false)
private String enterBy;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "amend_at")
private Date amendAt;
@Column(name = "amend_by", length = 4)
private String amendBy;
@Version
@Column(name = "revision", nullable = false)
private Long revision = 0L;
@Id
@Column(name = "code", length = 6)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "employee_sqn")
// @SequenceGenerator(name = "employee_sqn", sequenceName = "employee_sqn", initialValue = 60466176, allocationSize = 1)
@GenericGenerator(name = "employee_sqn", strategy = "biz.shahed.software.http.spider.utility.Base36Style", parameters = {
@Parameter(name = Base36Style.INITIAL_VALUE, value = Base36Style.DIGIT_6_MIN),
@Parameter(name = Base36Style.SEQUENCE_NAME, value = "employee_sqn"),
@Parameter(name = Base36Style.ALLOCATION_SIZE, value = "1"),
})
private String code;
@Column(name = "name", length = 64, nullable = false)
private String name;
@Column(name = "salary", scale = 8, precision = 2)
private Double salary;
@Column(name = "gender_code", length = 1, nullable = false)
private String genderCode;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name ="gender_code", referencedColumnName = "code", insertable = false, updatable = false)
private Gender gender;
}
@Column(name = "gender_code", length = 1, nullable = false)
private String genderCode;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name ="gender_code", referencedColumnName = "code", insertable = false, updatable = false)
private Gender gender;
@OneToMany(mappedBy = "gender")
private Set<Employee> employees = new HashSet<>()
@Override
public int hashCode() {
int hash = 0;
hash += (code != null ? code.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
if (!(object instanceof Employee)) {
return false;
}
Employee other = (Employee) object;
if ((this.code == null && other.code != null)|| (this.code != null && !this.code.equals(other.code))) {
return false;
}
return true;
}
@Override
public String toString() {
return String.format("%s[%s=%s]", this.getClass().getName(), "code", code);
}
Database
- Primary Key
- Cannot be a NULL
- Each table can have only one primary key.
- By default, Primary key is clustered index, and the data in database table is physically organized in the sequence of clustered index.
- Primary key can be related to another tables as a Foreign Key.
- We can generate ID automatically with the help of Auto Increment field. Primary key supports Auto Increment value.
- We can define Primary key constraint on temporary table and table variable.
- We can't delete primary key value from the parent table which is used as a foreign key in child table. To delete we first need to delete that primary key value from the child table.
- Unique Key
- Unique Constraint may have a NULL value
- Each table can have more than one Unique Constraint
- By default, Unique key is a unique non-clustered index
- Unique Constraint can not be related with another table's as a Foreign Key
- Foreign Key
- Foreign key is a field in the table that is Primary key in another table.
- Foreign key can accept multiple null value.
- Foreign key do not automatically create an index, clustered or non-clustered. You can manually create an index on foreign key.
- We can have more than one foreign key in a table.
- Foreign keys do not automatically create an index, clustered or non-clustered. You must manually create an index on foreign keys.
- There are actual advantages to having a foreign key be supported with a clustered index, but you get only one per table. What's the advantage? If you are selecting the parent plus all child records, you want the child records next to each other. This is easy to accomplish using a clustered index.
- Having a null foreign key is usually a bad idea instead of NULL referred to as "orphan record".
- We can’t define foreign key constraint on temporary table or table variable.
- We can delete the foreign key value from the child table even though that refers to the primary key of the parent table.
- DELETE CASCADE
- Using this option, it deletes the referencing rows in the child table when the referenced row is deleted in the parent table
- UPDATE CASCADE
- Using UPDATE CASCADE the referencing rows are updated in the child table when the referenced row is updated in the parent table
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.
- Automation
- Collaboration
- Integration
- 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
|
|
|
- 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.
- 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
|
|
|