Skip to main content

28 posts tagged with "Java"

Java programming language

View All Tags

Java Streams: Understanding .stream(), .map(), and .collect()

· 9 min read
Mahmut Salman
Software Developer

"What do .stream(), .map(), and .collect() actually do?" These three methods form a powerful pipeline for transforming collections in Java. Instead of writing loops to transform each element, you create a stream, transform elements, and collect results. Let's break down exactly what happens at each step.

Why Two Methods for JWT Token Generation? Understanding Single Responsibility Principle

· 12 min read
Mahmut Salman
Software Developer

"Why do we need both generateToken() (public) and createToken() (private) instead of just one method?" Because separation of concerns makes your code extensible. The public method handles what claims to add (business logic), while the private method handles how to build the JWT (technical details). This lets you add new token types without repeating code. Let's understand why this design pattern is essential.

ResponseEntity<T>: The Delivery Box That Can Hold Anything

· 9 min read
Mahmut Salman
Software Developer

"What does ResponseEntity<UnlockResponse> mean? Why can I use <UnlockResponse> here but <LoginResponse> somewhere else?" ResponseEntity is like a delivery box - it's a generic container that can hold any type of content. The <T> is a placeholder that you fill with your specific data type. Let's understand how this "magic" works and why it's incredibly powerful.

Spring Data JPA Part 5: Why UserRepository MUST Be an Interface - Java Type System Rules

· 8 min read
Mahmut Salman
Software Developer

"Why can't I use class instead of interface for UserRepository?" Because Java's type system has strict rules: class extends class, interface extends interface, class implements interface. When you try class UserRepository extends JpaRepository, Java sees JpaRepository is an interface and throws an error. Let's understand the three-level inheritance chain and who implements what.

Utility Classes vs Interfaces: Why Static Methods Aren't Enough

· 8 min read
Mahmut Salman
Software Developer

"Can't we just create a utility class with static methods instead of using interfaces? Isn't the interface approach just fancy?" Great question! Yes, you could use utility classes - but you'd be solving only 50% of the problem. Let's see what happens in practice and why interfaces aren't fancy, they're necessary.