Core Java
Basic
- JDK, JRE , JVM
- Java Acrhitecture
- JVM Architecture
- Classloader and its types
- Local variable, instance variable, static variable difference?
- Why java is not pure object oriented language
- Object Oriented vs Object Based language
- Constructor (super, this)
- Characteristics of OOP (Encapsulation, Abstraction , inheritance, polymorphism)
- Types of Polymorphism(static vs dynamic or overloading vs overrriding)
- Covariant Type
- Interface vs Abstract
- Interface: default and static methods
- Exception Handling(checked and unchecked)
- String concept : String constant pool [https://study.com/academy/lesson/java-string-constant-pool-concept-mechanism.html]
- StringBuilder and StringBuffer
- Equals vs ==
- Equals and Hashcode
- Inner Class and types
- Garbage Collection: Strategy and Types [ Types: {Serial, parallel, CMS, G1}, Strategy: oldGen, young gen, permgen]
- Serialisation and Deserialisation
- Reflection
- final, finally, finalize
- transient,volatile
- HashMap [https://medium.com/javarevisited/internal-working-of-hashmap-in-java-97aeac3c7beb, https://www.codingninjas.com/codestudio/library/implementation-of-hashmap ] it adds at first position when duplicate index, HashTable, Concurrent HashMap [array of linkedlist]
- HashSet [ https://medium.com/javarevisited/internal-working-of-hashset-in-java-e8b171fa3d41 ]
- LinkedHashMap [https://anmolsehgal.medium.com/java-linkedhashmap-internal-implementation-44e2e2893036 ] work as double linkedlist [array of doublinkedlist]
- LinkedHashSet [https://javaconceptoftheday.com/how-linkedhashset-works-internally-in-java/]
- TreeMap: internally uses RB Tree [https://medium.com/xebia-engineering/treemap-internals-199e0e0050b5]
- TreeSet: The data structure for the TreeSet is TreeMap; it contains SortedSet & NavigableSet interface to keep the elements sorted in ascending order and navigated through the tree
SOLID principle
Liskov subsistition ::
Bad example
public class Bird{
public void fly(){}
}
public class Duck extends Bird{}
The duck can fly because it is a bird, but what about this:
public class Ostrich extends Bird{}
Ostrich is a bird, but it can't fly, Ostrich class is a subtype of class Bird, but it shouldn't be able to use the fly method, that means we are breaking the LSP principle.
Good example
public class Bird{}
public class FlyingBirds extends Bird{
public void fly(){}
}
public class Duck extends FlyingBirds{}
public class Ostrich extends Bird{}
Design Pattern in Java
- Creational Design pattern: are concerned with the way of creating objects.
Singleton, Builder, Factory pattern
https://www.baeldung.com/creational-design-patterns - Structural Design pattern : These patterns explain how to assemble objects and classes into larger structures while keeping these structures flexible and efficient.
Adopter, Decorator, Composite, Bridge
https://www.baeldung.com/java-core-structural-patterns - Behavioural Design pattern : are concerned with the interaction and responsibility of objects.
Strategy,Command,Observer, ChainOfResponsibility
https://www.baeldung.com/java-behavioral-patterns-jdk
https://www.digitalocean.com/community/tutorials/strategy-design-pattern-in-java-example-tutorial
Microservice Design Pattern
12 Factor App
Spring Framework
JPA Vs Hibernate
Following table summerises the differences between JPA and Hibernate.
Category | JPA | Hibernate |
---|---|---|
Type | JPA is a specification and defines the way to manage relational database data using java objects. | Hibernate is an implementation of JPA. It is an ORM tool to persist java objects into the relational databases. |
Package | JPA uses javax.persistence package. | Hibernate uses org.hibernate package. |
Factory | JPA uses EntityManagerFactory interface to get the entity manager to persist objects. | Hibernate uses SessionFactory interface to create session object which is then used to persist objects. |
CRUD Operations | JPA uses EntityManager interface to create/read/delete operation and maintains the persistence context. | Hibernate uses Session interface to create/read/delete operation and maintains the persistence context. |
Language | JPA uses JPQL (Java Persistence Query Language) as Object Oriented Query language for database operations. | Hibernate uses HQL (Hibernate Query Language) as Object Oriented Query language for database operations. |
Transaction Management in Spring: ACID property
How to use Spring’s @Transactional annotation ( Declarative Transaction Management )
Now let’s have a look at what modern Spring transaction management usually looks like:
public class UserService {
@Transactional
public Long registerUser(User user) {
// execute some SQL that e.g.
// inserts the user into the db and retrieves the autogenerated id
// userDao.save(user);
return id;
}
}
How is this possible? There is no more XML configuration and there’s also no other code needed. Instead, you now need to do two things:
Make sure that your Spring Configuration is annotated with the @EnableTransactionManagement annotation (In Spring Boot this will be done automatically for you).
Make sure you specify a transaction manager in your Spring Configuration (this you need to do anyway).
And then Spring is smart enough to transparently handle transactions for you: Any bean’s public method you annotate with the @Transactional annotation, will execute inside a database transaction (note: there are some pitfalls).
So, to get the @Transactional annotation working, all you need to do is this:
@Configuration
@EnableTransactionManagement
public class MySpringConfig {
@Bean
public PlatformTransactionManager txManager() {
return yourTxManager; // more on that later
}
}
Now, when I say Spring transparently handles transactions for you. What does that really mean?
Armed with the knowledge from the JDBC transaction example, the @Transactional UserService code above translates (simplified) directly to this:
public class UserService {
public Long registerUser(User user) {
Connection connection = dataSource.getConnection(); // (1)
try (connection) {
connection.setAutoCommit(false); // (1)
// execute some SQL that e.g.
// inserts the user into the db and retrieves the autogenerated id
// userDao.save(user); <(2)
connection.commit(); // (1)
} catch (SQLException e) {
connection.rollback(); // (1)
}
}
}
This is all just standard opening and closing of a JDBC connection. That’s what Spring’s transactional annotation does for you automatically, without you having to write it explicitly.
This is your own code, saving the user through a DAO or something similar.
Authentication Framework
[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.]
The most common OAuth grant types are listed below.
- Authorization Code (web app mostly)
- PKCE. (mobile or any app)
- Client Credentials (service account or microservice)
- Device Code. (apps auth via authenticator)
- Refresh Token
Legacy
Device Flow [authentication in smart tv , amazon ccount]Auth granttype [web apps]https://developer.okta.com/blog/2018/04/10/oauth-authorization-code-grant-typePKCE [mobile apps]https://medium.com/identity-beyond-borders/auth-code-flow-with-pkce-a75ee203e242Client Credentials [servcie to servcie , internally]https://www.oauth.com/oauth2-servers/access-tokens/client-credentials/
7. JWT Structure [https://jwt.io/introduction]. Explain how it is implemented in java
8. JWT vs Oauth 2.0 Access token. [JWT defines a token format while OAuth deals in defining authorization protocols. JWT is simple and easy to learn from the initial stage while OAuth is complex. OAuth uses both client-side and server-side storage while JWT must use only client-side storage. JWT has limited scope and use cases.]
9. OpenId Connect [There is one more way to combine JWT and OAUth2. You need to guide OAuth2 to issue two tokens. The first token should be access_token and the second token should be a JWT token featuring additional identity details. While you plan to adopt this way to combine JWT and OAuth2, you need to make sure that you’re using OpenID Connect.]
Also read SAML, SWT
Data Structure
const Dashboard = () => {
const [tableData, setTableData] = useState();
const [showError, setShowError] = useState(false);
const [loading, setLoading] = useState(false);
useEffect(() => {
fetchListData();
}, [])
const fetchListData = async () => {
setLoading(true);
setShowError(false);
await axios.get("/ims/dashboard/",
{headers: {'Accept-Type': 'application/json'}})
.then((res) => {
setTableData(res.data);
setLoading(false);
})
.catch((err) => {
console.log(err)
setShowError(true);
setLoading(false);
});
}
return <>
{showError && <Alert />}
<CustomizedTables rows={tableData} isLoading={loading}/>
</>
}
export default Dashboard;
No comments:
Post a Comment