🚀 Java Arrays felt limiting today… until I explored ArrayList. A normal array has a fixed size, which means once created, its size cannot grow. That’s where ArrayList feels super useful 👇 ✅ Dynamic size ✅ Maintains insertion order ✅ Allows duplicates ✅ Easy built-in methods like add(), remove(), get() Small example: ArrayList skills = new ArrayList<>(); skills.add("Java"); skills.add("Spring Boot"); skills.add("React"); System.out.println(skills); Output: [Java, Spring Boot, React] 💡 Key takeaway: Use ArrayList when the number of elements is not fixed. It gives the flexibility that normal arrays don’t. Still exploring how it resizes internally 👀 #Java #ArrayList #LearningInPublic #BackendDevelopment
Java ArrayList: Dynamic Size and Flexibility
More Relevant Posts
-
Hello Connections, Post 20— Java Fundamentals A-Z This one compiles perfectly. But breaks everything at runtime. 😱 Can you spot the bug? 👇 @FunctionalInterface interface Calculator { int calculate(int a, int b); int multiply(int a, int b); // 💀 Won't compile! } The bug? A Functional Interface can have only ONE abstract method! Two abstract methods = not functional! 💀 Here’s the fix 👇 // ✅ One abstract method only! @FunctionalInterface interface Calculator { int calculate(int a, int b); // ✅ Only one! } // ✅ Use it with Lambda! Calculator add = (a, b) -> a + b; Calculator multiply = (a, b) -> a * b; Calculator subtract = (a, b) -> a - b; System.out.println(add.calculate(5, 3)); // 8 ✅ System.out.println(multiply.calculate(5, 3)); // 15 ✅ System.out.println(subtract.calculate(5, 3)); // 2 ✅ Java’s Built-in Functional Interfaces // Predicate — returns boolean Predicate<String> isEmpty = s -> s.isEmpty(); // Function — transforms input to output Function<String, Integer> length = s -> s.length(); // Consumer — takes input, returns nothing Consumer<String> print = s -> System.out.println(s); // Supplier — no input, returns value Supplier<String> greeting = () -> "Hello DBS!"; Post 20 Summary: 🔴 Unlearned → Functional Interface can have multiple methods 🟢 Relearned → Exactly ONE abstract method — that’s what makes it functional! 🤯 Biggest surprise → Built-in functional interfaces replaced 20+ custom interfaces in codebase! Which built-in functional interface do you use most? Drop below! 👇 #Java #JavaFundamentals #BackendDevelopment #LearningInPublic #SDE2 Follow along for more! 👇
To view or add a comment, sign in
-
-
🚀 Day 2 – Subtle Java Behavior That Can Surprise You Today I explored the difference between "==" and ".equals()" in Java — and it’s more important than it looks. String a = "hello"; String b = "hello"; System.out.println(a == b); // true System.out.println(a.equals(b)); // true Now this: String c = new String("hello"); System.out.println(a == c); // false System.out.println(a.equals(c)); // true 👉 "==" compares reference (memory location) 👉 ".equals()" compares actual content 💡 The catch? Because of the String Pool, sometimes "==" appears to work correctly… until it doesn’t. This small misunderstanding can lead to tricky bugs, especially while working with collections or APIs. ✔ Rule I’m following: Always use ".equals()" for value comparison unless you explicitly care about references. #Java #BackendDevelopment #JavaBasics #LearningInPublic
To view or add a comment, sign in
-
🚀 String Manipulation (Java) Java's `String` class provides numerous methods for manipulating strings. Common operations include finding the length of a string using `length()`, concatenating strings using `+` or `concat()`, extracting substrings using `substring()`, and comparing strings using `equals()` or `equalsIgnoreCase()`. These methods allow developers to efficiently work with and process text data. Because strings are immutable, many manipulation methods return a *new* String object. Learn more on our app: https://lnkd.in/gefySfsc #Java #JavaDev #OOP #Backend #professional #career #development
To view or add a comment, sign in
-
-
Hello Everyone👋👋 What is Java String Pool? The Java String Pool is a special memory area where Java stores string literals to optimize memory usage. When a string literal is created, Java checks the pool to see if an identical string already exists. If it does, the same reference is used, reducing memory consumption and improving performance. #Java #backend #frontend #FullStack #software #developer #programming #code #class #object #lambda #inheritance #Array #ArrayList #collections #super #constructor #Java26 #GenAI #AI #OpenAI #Claude #Nodejs #Angular #React #interface #abstract #interview
To view or add a comment, sign in
-
Java apps shouldn’t need a Node.js sidecar just to render MJML emails. So I built mjml-java: a native Java MJML renderer for producing responsive HTML email from JVM applications. Still early, but real, useful, and open source. https://lnkd.in/dpm2zbCi #java #mjml #oss #opensource
To view or add a comment, sign in
-
💡 Day 1 Hey everyone! Let’s learn 1 Java program daily for the next 90 days. 🚀 👉 Problem: Find the second highest number from a list of integers. import java.util.*; public class SecondHighestNumber { public static void main(String[] args) { List<Integer> numbers = List.of(30, 20, 40, 90, 80, 60, 30); numbers.stream() .distinct() // remove duplicates .sorted(Comparator.reverseOrder()) // sort in descending order .skip(1) // skip the highest .limit(1) // take second highest .forEach(n -> System.out.println("Second Highest Number: " + n)); } } 🧠 Explanation: distinct()→ removes duplicates sorted(reverseOrder())→ sorts numbers in descending order skip(1) → skips the highest number limit(1)→ gets the second highest 📌 Output: Second Highest Number: 80 #Java #JavaStreams #CodingInterview #90DaysOfCode
To view or add a comment, sign in
-
🚀 Exploring CompletableFuture in Java (When to use & when to avoid) While revisiting Java 8 concepts, I explored CompletableFuture and how it helps in handling asynchronous operations. 💡 A common backend scenario: An API needs to call multiple services: User Service Order Service Payment Service If executed sequentially: getUser(); getOrder(); getPayment(); ⏱️ Total time increases as each call waits for the previous one. 👉 Using CompletableFuture, we can execute them in parallel: CompletableFuture<String> user = CompletableFuture.supplyAsync(() -> getUser()); CompletableFuture<String> order = CompletableFuture.supplyAsync(() -> getOrder()); CompletableFuture<String> payment = CompletableFuture.supplyAsync(() -> getPayment()); CompletableFuture.allOf(user, order, payment).join(); ⚡ Independent tasks run concurrently → better performance ✅ When to use CompletableFuture: Calling multiple independent APIs Microservices communication Improving response time Parallel data fetching ⚠️ When to avoid: When tasks depend on each other Heavy blocking operations (like DB calls without proper thread management) Small/simple logic where async adds complexity 📌 My takeaway: Even if not used directly yet, understanding where it fits helps design better scalable systems. Looking forward to applying this in real projects. Have you used CompletableFuture in your applications? Any challenges or best practices? 👇 #Java #SpringBoot #BackendDevelopment #Microservices #CompletableFuture #JavaDeveloper #SoftwareEngineering
To view or add a comment, sign in
-
Working with native memory in Java? Understanding VarHandle access modes is key to writing thread-safe code. David Vlijmincx breaks down the different access modes available when working with native memory, from plain reads and writes to volatile and atomic operations. The article explains when to use each mode and how they affect visibility and ordering guarantees across threads. If you're building performance-critical applications or working with off-heap memory, this is a practical guide to get the concurrency semantics right. Read the full article: https://lnkd.in/exQRjdEy #Java #VarHandle #Concurrency #NativeMemory
To view or add a comment, sign in
-
“Java is too hard to write.” Every developer at some point. But are we talking about Java then or Java now? Old Java: You had to write a lot to do something small. Modern Java: Here I did it fast. You’re welcome. The truth is. Java has changed a lot. It has streams, records and more… it’s not the same language people like to complain about. And here’s something cool. I found a site that shows new Java code side, by side: https://lnkd.in/g7n9VhMD (https://lnkd.in/g7n9VhMD) It’s like watching Java go through a glow-up. So next time someone says "Java is too hard to write" Just ask them: Which Java are you talking about? Java didn’t stay hard to write. We just didn’t keep up with Java. #Java #JDK #Features #Software #Engineering
To view or add a comment, sign in
-
-
Most Java developers write multithreaded code every day. But most of us don't know what happens inside the JVM when two threads hit the same counter — and things get quiet. I've been preparing deeply for senior Java interviews and decided to document everything I learned about multithreading from scratch. Not just definitions — real internals. Here's what Module 02 covers: 🔹 Multithreading 🔹 Process vs. Program vs. Thread 🔹 Thread lifecycle (all 6 states — and why there's no RUNNING state) 🔹 Race conditions — why count++ is never safe 🔹 synchronized — object lock vs class lock (most devs miss this) 🔹 ReentrantLock — tryLock, fairness, reentrancy explained 🔹 ReadWriteLock — when to separate reads from writes 🔹 Deadlock, Livelock, Starvation — all three with code and fixes 🔹 wait() / notify() — the producer-consumer pattern the right way 🔹 volatile vs Atomic — visibility vs atomicity (not the same thing) 🔹 ABA problem — why CAS isn't always enough 🔹 ExecutorService + ThreadPoolExecutor internals 🔹 Callable, Future — handling results and exceptions from threads 🔹 CompletableFuture — full methods guide (thenApply, thenCombine, exceptionally…) 🔹 ThreadLocal — usage, and the memory leak trap in thread pools This is Part 03 of my Java Interview Prep series. Part 01 covered JVM Internals, and Part 02 covered OOPs Internals - Find the post link in the comments. More modules on Collections, Streams, Spring Boot, etc., are coming. If you're preparing for a senior Java role or want to understand what's really happening when your threads collide, finally, this is for you. #Java #Multithreading #JavaConcurrency #InterviewPrep #CoreJava #BackendDevelopment #JavaDeveloper #LearningInPublic
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development