🖍️
Developer Note
  • Welcome
  • Git
    • Eslint & Prettier & Stylelint & Husky
  • Programming Language
    • JavaScript
      • Script Async vs Defer
      • Module
      • Const VS Let VS Var
      • Promise
      • Event Loop
      • Execution Context
      • Hoisting
      • Closure
      • Event Buddling and Capturing
      • Garbage Collection
      • This
      • Routing
      • Debounce and Throttle
      • Web Component
      • Iterator
      • Syntax
      • String
      • Array
      • Object
      • Proxy & Reflect
      • ProtoType
      • Class
      • Immutability
      • Typeof & Instanceof
      • Npm (Node package manager)
    • TypeScript
      • Utility Type
      • Type vs Interface
      • Any vs Unknown vs Never
      • Void and undefined
      • Strict Mode
      • Namespace
      • Enum
      • Module
      • Generic
    • Python
      • Local Development
      • Uv
      • Asyncio & Event loop
      • Context Manager
      • Iterator & Generator
      • Fast API
      • Pydantic & Data Class
    • Java
      • Compilation and Execution
      • Data Type
      • Enumeration
      • Data Structure
      • Try Catch
      • InputStream and OutputStream
      • Concurrent
      • Unicode Block
      • Build Tools
      • Servlet
      • Java 8
  • Coding Pattern
    • MVC vs MVVM
    • OOP vs Functional
    • Error Handling
    • MVC vs Flux
    • Imperative vs Declarative
    • Design Pattern
  • Web Communication
    • REST API
      • Web Hook
      • CORS issue
    • HTTPS
    • GraphQL
      • REST API vs GraphQL
      • Implementation (NodeJS + React)
    • Server-Sent Event
    • Web Socket
    • IP
    • Domain Name System (DNS)
  • Frontend
    • Progressive Web App (PWA)
    • Single Page & Multiple Page Application
    • Search Engine Optimiaztion (SEO)
    • Web bundling & Micro-frontend
      • Webpack
        • Using Webpack to build React Application
        • Using Webpack to build react library
      • Vite
      • Using rollup to build react library
      • Implementing micro frontend
    • Web Security
      • CSRF & Nonce
      • XSS
      • Click hijacking
    • Cypress
    • CSS
      • Core
        • Box Model
        • Inline vs Block
        • Flexbox & Grid
        • Pseudo Class
        • Position
      • Tailwind CSS
        • Shadcn
      • CSS In JS
        • Material UI
    • React
      • Core
        • Component Pattern
        • React Lazy & Suspense
        • React Portal
        • Error Boundary
        • Rendering Methods
        • Environment Variable
        • Conditional CSS
        • Memo
        • Forward Reference
        • High Order Component (HOC) & Custom Hook
        • TypeScript
      • State Management
        • Redux
        • Recoil
        • Zustand
      • Routing
        • React Router Dom
      • Data Fetching
        • Axios & Hook
        • React Query
        • Orval
      • Table
        • React Table
      • Form & Validation
        • React Hook Form
        • Zod
      • NextJS
        • Page Router
        • App Router
      • React Native
    • Angular
    • Svelte
      • Svelte Kit
  • Backend
    • Cache
      • Browser Cache
      • Web Browser Storage
      • Proxy
      • Redis
    • Rate limit
    • Monitoring
      • Logging
      • Distributed Tracing
    • Load Test
    • Encryption
    • Authentication
      • Password Protection
      • Cookie & Session
      • JSON Web Token
      • SSO
        • OAuth 2.0
        • OpenID Connect (OIDC)
        • SAML
    • Payment
      • Pre-built
      • Custom
    • File Handling
      • Upload & Download (Front-end)
      • Stream & Buffer
    • Microservice
      • API Gateway
      • Service Discovery
      • Load Balancer
      • Circuit Breaker
      • Message Broker
      • BulkHead & Zipkin
    • Elastic Search
    • Database
      • SQL
        • Group By vs Distinct
        • Index
        • N + 1 problem
        • Normalization
        • Foreign Key
        • Relationship
        • Union & Join
        • User Defined Type
      • NOSQL (MongoDB)
      • Transaction
      • Sharding
      • Lock (Concurrency Control)
    • NodeJS
      • NodeJS vs Java Spring
      • ExpressJS
      • NestJS
        • Swagger
        • Class Validator & Validation Pipe
        • Passport (Authentication)
      • Path Module
      • Database Connection
        • Integrating with MYSQL
        • Sequalize
        • Integrating with MongoDB
        • Prisma
        • MikroORM
        • Mongoose
      • Streaming
      • Worker Thread
      • Passport JS
      • JSON Web Token
      • Socket IO
      • Bull MQ
      • Pino (Logging)
      • Yeoman
    • Spring
      • Spring MVC
      • Spring REST
      • Spring Actuator
      • Aspect Oriented Programming (AOP)
      • Controller Advice
      • Filter
      • Interceptor
      • Concurrent
      • Spring Security
      • Spring Boot
      • Spring Cloud
        • Resilience 4j
      • Quartz vs Spring Batch
      • JPA and Hibernate
      • HATEOS
      • Swagger
      • Unit Test (Java Spring)
      • Unit Test (Spring boot)
  • DevOp
    • Docker
    • Kubernetes
      • Helm
    • Nginx
    • File System
    • Cloud
      • AWS
        • EC2 (Virtual Machine)
        • Network
        • IAM
          • Role-Service Binding
        • Database
        • Route 53
        • S3
        • Message Queue
        • Application Service
        • Serverless Framework
        • Data Analysis
        • Machine Learning
        • Monitoring
        • Security
      • Azure
        • Identity
        • Compute Resource
        • Networking
        • Storage
        • Monitoring
      • Google Cloud
        • IAM
          • Workload Identity Federation
        • Compute Engine
        • VPC Network
        • Storage
        • Kubernetes Engine
        • App Engine
        • Cloud function
        • Cloud Run
        • Infra as Code
        • Pub/Sub
    • Deployment Strategy
    • Jenkins
    • Examples
      • Deploy NextJS on GCP
      • Deploy Spring on Azure
      • Deploy React on Azure
  • Domain Knowledge
    • Web 3
      • Blockchain
      • Cryptocurrency
    • AI
      • Prompt
      • Chain & Agent
      • LangChain
      • Chunking
      • Search
      • Side Products
Powered by GitBook
On this page
  • Intoduction
  • Size
  • Wrapper Type
  • Autoboxing
  • Unboxing
  • Wrapper vs Primitive
  • Reference Type vs Value Type
  • Reference Type
  • Value Type
  • Generic
  • Interface and Abstract Class
  • Static Type and Final Type
  • Static
  • Final
  • String vs String Buffer vs String Builder
  • String
  • String Buffer & String Builder

Was this helpful?

  1. Programming Language
  2. Java

Data Type

Intoduction

Size

  • Whole Number: long (involve larger range of number) > int

  • Decimal Number: double (involve more decimal places) > float

Wrapper Type

  • Number: Include all of the wrapper type

  • It is an object that include primitive type

Autoboxing

  • Turn Primitive type into Wrapper type

int a = 1;
//Autoboxing
Integer b = a;

Unboxing

  • Turn Wrapper type into primitive type

Integer a = 1;
//Unboxing
int b = a;

Wrapper vs Primitive

  • Wrapper type such as Integer is an Object but including primitive type , default is null

  • Primitive type such as integer default is 0

  • When returning a value as a json object, wrapper type is preferred

  • When involving large of calculation, primitive type is preferred, as autoboxing is not needed

Reference Type vs Value Type

Reference Type

List<String> stringList1 = new ArrayList<>();
List<String> stringList2 = stringList1;
stringList1.add("test");
stringList2.forEach(s -> System.out.println(s));
// test
  • When creating new object or new list , a variable (string1) is pointed to the address in memory of the object

  • When stringlist2 is equal to stringlist1, which means that stringlist variable is also pointed to the same memory of the object

  • So that, the result will be shown below

Value Type

  • Mostly on primitive type, e.g int, double, ...

int test1 = 1;
int test2 = test1;
test1++;
System.out.println(test2);
// 1

Generic

  • Generic is a parameterized type, to allow type to be parameter, so as to let the class work well with different classes

  • It is not suitable for primitive type

  • Example 1:

// typical example is List, which can work well with different types
List<String> StringList = new ArrayList<>();
...
  • Example2:

public class Dog<T,D> {
   private T name;
   private D age;

    public Dog(T name, D age) {
        this.name = name;
        this.age = age;
    }

    public T getName() {
        return name;
    }

    public void setName(T name) {
        this.name = name;
    }

    public D getAge() {
        return age;
    }

    public void setAge(D age) {
        this.age = age;
    }
}
List<String> stringList1 = new ArrayList<>();
List<String> stringList2 = stringList1;
stringList1.add("test");
stringList2.forEach(s -> System.out.println(s));

Dog<String,Integer> dog = new Dog<>("happy",18);
System.out.println(dog.getName());
System.out.println(dog.getAge());

Interface and Abstract Class

  • Abstract class cannot be declared as an instance, need to be extended by concrete class

  • Both only include the type of functions only but not the content of function, like the plot

  • Abstract Class can include non-abstract class , but interface cannot

  • Interface can be implemented by many functions , but abstract class can only be inherited by one function

  • An abstract class can have abstract and/or non-abstract methods, while an interface can only have abstract methods.

  • An abstract class can have final, static or non-static or non-final variables, while interfaces can have only final and static variables.

Static Type and Final Type

Static

  • The value cannot be changed by setter and belong to the class but not object , and this type of function can be called without declaring new Object. e.g: Math.round(1000); round is a static type of function

  • When we do not need to depend on the variable of the class on method and also want to apply singleton, we can use static method or variable

Final

  • The value is finalized and cannot be changed / override.

String vs String Buffer vs String Builder

String

  • String is immutable in Java. So it’s suitable to use in a multi-threaded environment. We can share it across functions because there is no concern of data inconsistency. String is a final class.

  • If the new operator is used to create a string, it gets created in the heap memory.

  • The + operator is overloaded for String. We can use it to concatenate two strings. Although internally it uses StringBuffer to perform this action.

  • Since String is immutable in Java, whenever we do String manipulation like concatenation, substring, etc. it generates a new String and discards the older String for garbage collection.These are heavy operations and generate a lot of garbage in heap. So Java has provided StringBuffer and StringBuilder classes that should be used for String manipulation.

String Buffer & String Builder

  • StringBuffer is thread-safe and synchronized whereas StringBuilder is not. That’s why StringBuilder is faster than StringBuffer

  • For String manipulations in a non-multi threaded environment, we should use StringBuilder else use StringBuffer class

PreviousCompilation and ExecutionNextEnumeration

Last updated 1 year ago

Was this helpful?