Tuan Nguyen Stop talking start building

java-funny

Who created java ?

Java was created by James Gosling, Mike Sheridan, and Patrick Naughton, who were engineers at Sun Microsystems at the time. They began the project in 1991, with the goal of developing a language for digital devices, particularly for interactive television. Java was officially released to the public in 1995, with its “Write Once, Run Anywhere” (WORA) philosophy, allowing Java programs to run on any device with a Java Virtual Machine (JVM). Over the years, Java has become one of the most popular programming languages worldwide, used for a wide range of applications, including web development, mobile app development, enterprise software, and more.

Why Java has class ?

Java, like many object-oriented programming languages, utilizes classes as a fundamental building block for organizing and structuring code. Classes serve several important purposes in Java:

Encapsulation: Classes provide a way to encapsulate data (attributes) and behavior (methods) into a single unit. This helps to organize code logically and promotes modularity and code reusability.

Abstraction: Classes allow developers to create abstract data types that represent real-world entities or concepts. By defining classes with attributes and methods that model the characteristics and behaviors of these entities, developers can work with higher-level abstractions in their code.

Inheritance: Java supports inheritance, where one class (subclass or derived class) can inherit attributes and methods from another class (superclass or base class). This allows developers to create hierarchical relationships between classes, promoting code reuse and enabling polymorphism.

Polymorphism: Through inheritance and method overriding, Java enables polymorphism, allowing objects of different classes to be treated interchangeably based on their common interface or superclass.

Code Organization: Classes provide a structured way to organize code, making it easier to manage and maintain larger software projects. By grouping related attributes and methods together within a class, developers can more easily understand and navigate the codebase.

Encapsulation of Complexity: Classes help encapsulate the complexity of a system by hiding implementation details and exposing only relevant interfaces to other parts of the program. This improves code readability, reduces coupling between different components, and promotes code maintainability.

Overall, classes play a central role in Java programming by providing a mechanism for defining objects, organizing code, and implementing key object-oriented concepts such as encapsulation, inheritance, and polymorphism.

whether the use of classes in Java has contributed to its failure ?

ava is widely regarded as a successful programming language, widely used in a variety of applications and industries.

Classes are actually one of the key features of Java that have contributed to its success. They provide a fundamental mechanism for organizing code, implementing object-oriented principles, and facilitating code reuse and modularity. The use of classes allows developers to create well-structured, maintainable codebases that can scale effectively with the size and complexity of the project.

While Java, like any programming language, has its challenges and limitations, the use of classes is generally not considered a reason for its failure. In fact, classes and object-oriented programming are often cited as strengths of the language, enabling developers to build robust, scalable software systems.

It’s important to note that the success or failure of a programming language depends on various factors, including its design, features, performance, ecosystem, community support, and adaptability to evolving technology trends. Java has remained a popular and widely-used language for over two decades, demonstrating its resilience and ongoing relevance in the ever-changing landscape of software development.

Why do java projects have such messy, complicated folder structures ?

The perceived messiness and complexity of folder structures in Java projects can stem from several factors:

Historical Reasons: Many Java projects have evolved over time, with new features, modules, and components added incrementally. As a result, the folder structure may become convoluted as developers adapt to changing requirements and technologies without restructuring the project.

Lack of Standardization: Unlike some other ecosystems, such as Ruby on Rails or Django, Java does not enforce a specific folder structure or project layout. This can lead to inconsistency across different projects and teams, as developers may organize their code according to personal preferences or past practices.

Integration with Build Tools and Frameworks: Java projects often rely on build tools like Maven or Gradle and frameworks like Spring or Hibernate, which may impose their own conventions and folder structures. While these tools provide valuable features for dependency management, build automation, and configuration, they can also introduce complexity to the project layout.

Legacy Code and Dependencies: Java projects may inherit legacy codebases or dependencies with outdated folder structures or unconventional organization. Integrating and maintaining these components within the project can contribute to the perceived messiness of the folder structure.

Large-scale and Modular Projects: In larger projects with multiple modules, libraries, and components, maintaining a clean and organized folder structure becomes more challenging. Developers may struggle to balance the need for modularity and separation of concerns with the desire for simplicity and clarity.

To address these challenges and improve the organization of Java projects, developers can consider the following strategies:

Adopting established conventions and best practices for project layout, such as those recommended by Maven or popular Java frameworks. Regularly reviewing and refactoring the folder structure to remove unnecessary complexity and improve readability. Using tools and plugins that automate code organization and enforce coding standards, such as Checkstyle or SonarQube. Documenting the project structure and conventions to ensure consistency and facilitate onboarding of new team members. Encouraging communication and collaboration among team members to identify areas for improvement and streamline the development process. By proactively managing the folder structure and adhering to established conventions, Java projects can become more organized, maintainable, and easier to navigate for developers.

From ChatGPT!

microservices

What is microservice ? and how can we build microservices system ? bla bla Microservices. Here is step by step to build microservice system base on my experiences.

Big picture

Microservices architecture

Techlology using:

  • Spring boot, Spring Oauth2
  • Hibernate
  • Mysql, Postgresql, ELK
  • Zipkin
  • Kafka
  • Prometheus
  • Grafana
  • Sentry
  • Docker and Kubernetes
  • Angular

Next post

Leraning and sharing experiences about Authentication server:

  • How to biuld Authentication server:
  • Running and testing Authentication server:
  • Using open source Authentication server: keycloak.
  • Documents.

Next next post

Will know after this post.

Download

Example is developed by me in GitHub Microservice repository for downloads and running.

Thanks!

authentication server

What is Authentication server ? and how can we build Authentication server ? bla bla Authentication server.

Authentication server

Symetric and Asymetric:

2.1. Symmetric Encryption: Same key for both encryption and decryption. Only using this for sample demo don’t use for production

2.2. Asymmetric Encryption: Different key between encryption and decryption. Authentication Server using private key Resource Server using public key for verify token

Generate keypair:

2.3. Step Generate Keypair:

A. Generate JKS: Using by Auth Server keytool -genkeypair -alias ms-oauth-server -keyalg RSA -keypass Nation@123 -keystore auth-server.jks -storepass Day@123

What is your first and last name?
  [Unknown]:  Tuan Nguyen
What is the name of your organizational unit?
  [Unknown]:  PTIT
What is the name of your organization?
  [Unknown]:  PTIT
What is the name of your City or Locality?
  [Unknown]:  Sai Gon
What is the name of your State or Province?
  [Unknown]:  Sai Gon
What is the two-letter country code for this unit?
  [Unknown]:  VN
Is CN=Tuan Nguyen, OU=PTIT, O=PTIT, L=Sai Gon, ST=Sai Gon, C=VN correct? B. Generate public key: using by Resource Server
1. Download https://code.google.com/archive/p/openssl-for-windows/downloads
2. Get Private and Public Key: keytool -list -rfc --keystore auth-server.jks | "C:\openssl\bin\openssl.exe" x509 -inform pem -pubkey
3. Get public key only: keytool -list -rfc --keystore auth-server.jks | "C:\openssl\bin\openssl.exe" x509 -inform pem -pubkey -noout

Authentication server using asymmetric

2.4. Sample Code : Auth Server with grant type password https://github.com/tuannguyendang/microservice/tree/master/auth/src/main/java/com/dangtuan/auth

  • Branch Master: Used Jwt token store. Token generated store in memory.

  • Branch oauth2-server-jdbc: Used Jwt token store. Token generated store in MYSQL database.

  • For third party application Authentication server must support authentication code and exchange authentication code (Proof key of code exchange) Research Keycloak…

2.5. Self encoded token JWT (in memory) vs Database

  • JWT (in memory) includes all information for Resource Server. no way invalidate token in case hacker get token

  • Database easy validate and make invalidate token because it saves token in database and resource will call API validate token from Auth Server.

  • For application running in multiple region we need using distributed database

Techlology using:

  • Spring boot, Spring Oauth2
  • Hibernate
  • Mysql
  • Open source keycloak

Next post

Leraning and sharing experiences about Gateway: Gateway discovery service:

  • How to biuld Authentication server:
  • Running and testing Authentication server:
  • Using open source Authentication server: keycloak (right sidebar).
  • Documents.

Next next post

Will know after this post.

Download

Example is developed by me in GitHub authentication server repository for downloads and running.

Thanks!

Gateway and Discovery Service

Discovery service Eureka registry services

Application Gateway NextFlix Zuul implement in your application

Sidecar Gateway Kong install independent with application

Discovery Service

Discovery service auto detection of devices and services

Application Gateway

Gateway router request to services, implementation in application

Sidecar Gateway

Install independent with application and language.

Next post

  • More information about Kong Gateway

Download

  • All the code you need here

Thanks!

Communication between services

Communication between services and client (web app, mobile app) to services
  • REST API
  • GRPC
  • KAFKA
  • OUTBOX pattern

Communication In Microservice

REST API

Best practice design rest api

HTTP Method Use For Description
GET READ Get resource state
POST CREATE Create new resource
PUT UPDATE Update exist resource
DELETE DELETE Delete resource

GRPC

gRPC is a binary message-based protocol

KAFKA

Message Queue

Some Questions

  • What is ACID ? Atomic, Consistent, Isolated, Durable
  • How can we apply Saga pattern in microservices ?
  • Why Kafka ?

OUTBOX pattern

https://tuannguyendang.github.io/blog/public/img/20210414/outboxtransaction.png

JMS message sent out will insert to the outbox table in the same transaction with the service table. Using debezium or some other data event tool to publish messages to kafka. Or use scheduler job reading and send messages to kafka.

For more information here!


Want to more information? ask Google   contact me tuan193@gmail.com