Day - 52 #120DaysOfLearning | Java Full Stack ☑️ 𝐓𝐨𝐩𝐢𝐜: 𝐉𝐚𝐯𝐚 𝟖 𝐅𝐞𝐚𝐭𝐮𝐫𝐞𝐬 — Functional Interface, Lambda Expression, Higher Order Function & Iterator Method in Collections. 🌟 Learning modern Java 8 concepts that make code more functional, readable, and efficient — plus mastering how to iterate cleanly using Java Collections. ☑️ Functional Interface : 🔅 A Functional Interface contains exactly one abstract method 🔅 It may include any number of default and static methods 🔅 Use @FunctionalInterface annotation to prevent adding more abstract methods 🧾 Syntax: @FunctionalInterface interface MyInterface { void myMethod(); } ☑️ Lambda Expressions : 🔅 Lambda Expressions are anonymous functions 🔅 Used to eliminate boilerplate code 🔅 Can be passed where a functional interface is expected 🧾 Syntax: (parameters) -> { // body } 🔷 Example: MyInterface ref = () -> System.out.println("Hello from Lambda!"); ref.myMethod(); ☑️ Higher Order Function : 🔅 A Higher Order Function accepts another function as an argument 🧾 Syntax Example : void executeFunction(MyInterface ref) { ref.myMethod(); } 🔷 Here, executeFunction() is a higher-order function ☑️ Iterator Method in Collections : 🔅 Used to traverse elements in collections like List, Set, etc. 🔷 Key Methods: 1️⃣ iterator() → Gets the Iterator object 2️⃣ hasNext() → Checks for remaining elements 3️⃣ next() → Retrieves next element 4️⃣ remove() → (Optional) Removes current element 🧾 Syntax : Iterator<String> it = list.iterator(); while(it.hasNext()) { System.out.println(it.next()); } 🫶 Special Thanks to : #DestinationCodegn.. Anand Kumar Buddarapu Sir , Saketh Kallepu Sir , Uppugundla Sairam Sir. #Java8 #FunctionalInterface #LambdaExpressions #HigherOrderFunction #Iterator #JavaCollections #120DaysOfLearning #JavaFullStack #CleanCode #CodeBetter #LearnJavaDaily
More Relevant Posts
-
🚀 Today’s Java Learning: Strings & Their Superpowers Hey LinkedIn fam 👋 Today I dived deep into one of Java’s most important topics — Strings! Here’s my quick mind map recap 🧠👇 💡 What is a String? A String is a sequence of characters enclosed in " " — and yes, it’s an object in Java! There are 2️⃣ types of Strings: ✅ Immutable Strings → cannot be changed (String) 🟢 Used for fixed data like Name, Gender, DOB ✅ Mutable Strings → can be changed (StringBuffer, StringBuilder) 🟣 Used for editable data like Password, Messages, Email ID ⚔️ String Comparison Methods 🔹 equals() → Compares content 🔹 equalsIgnoreCase() → Ignores case while comparing 🔹 compareTo() → Lexicographical (Unicode-based) ➕ String Concatenation ✨ Using '+' → Created in String Constant Pool (if literals) ✨ Using concat() → Creates new object in Heap memory 🧩 Handy String Methods toUpperCase() / toLowerCase() – Change case length() – String length charAt() – Character at index contains() – Check substring startsWith() / endsWith() – Prefix/suffix indexOf() / lastIndexOf() – Find position replace() – Replace part of string isEmpty() / isBlank() – Empty or only spaces split() – Split into array toCharArray() – Convert to char array 🔧 Mutable Strings Quick Facts Feature StringBuffer StringBuilder Thread Safe ✅ Yes ❌ No Speed ⏳ Slower ⚡ FasterInitial Capacity 16 16 Growth (current × 2) + 2 (current × 2) + 2 🧱 Common Methods → append(), capacity(), length(), trimToSize() 💭 Key Takeaway: Knowing how Strings work (memory, mutability, and methods) helps you write faster, cleaner, and more efficient Java code 💪 #Java #StringHandling #MutableStrings #LearningJourney #CodingInJava #FullStackDeveloper #DailyLearning
To view or add a comment, sign in
-
-
⭐𝐄𝐱𝐩𝐥𝐨𝐫𝐢𝐧𝐠 𝐚𝐛𝐨𝐮𝐭 𝐭𝐡𝐞 𝐓𝐨𝐤𝐞𝐧𝐬 𝐢𝐧 𝐉𝐚𝐯𝐚: In Java, tokens are the smallest meaningful elements of a program that the compiler can understand. They act as the fundamental building blocks of a Java program. Here's a breakdown of the types of tokens in Java: ➜ 1. Keywords: Reserved words in Java with predefined meanings. Examples: class, public, static, if, else, while, return, etc. Cannot be used as identifiers (e.g., variable names). ➜ 2. Identifiers: Names used to identify variables, methods, classes, or objects. • 𝐑𝐮𝐥𝐞𝐬: Must begin with a letter, _, or $. Cannot be a keyword. Case-sensitive. • 𝙀𝙭𝙖𝙢𝙥𝙡𝙚𝙨: myVariable, calculateSum. ➜ 3. Literals: Constant values directly used in the program. • 𝐓𝐲𝐩𝐞𝐬: Integer literals: 10, -5 Floating-point literals: 3.14, -0.01 Character literals: 'A', '9' String literals: "Hello", "Java" Boolean literals: true, false ➜ 4. Operators: Symbols used to perform operations on variables and values. • 𝐓𝐲𝐩𝐞𝐬: Arithmetic operators: +, -, *, /, % Relational operators: ==, !=, <, >, <=, >= Logical operators: &&, ||, ! Assignment operators: =, +=, -=, etc. ➜ 5. Separators (Delimiters): Characters used to separate tokens in a program. • 𝙀𝙭𝙖𝙢𝙥𝙡𝙚𝙨: 𝐏𝐚𝐫𝐞𝐧𝐭𝐡𝐞𝐬𝐞𝐬: () 𝐂𝐮𝐫𝐥𝐲 𝐛𝐫𝐚𝐜𝐞𝐬: { } 𝐒𝐞𝐦𝐢𝐜𝐨𝐥𝐨𝐧: ; 𝐂𝐨𝐦𝐦𝐚: , #java #Day3 #Corejava #Codegnan Thanks to my mentor: Anand Kumar Buddarapu Saketh Kallepu Uppugundla Sairam
To view or add a comment, sign in
-
-
💭 Question: 👉 Is Java a Pure Object-Oriented Programming (OOP) language? 🤔 💡 Answer: No, Java is not a purely object-oriented language — and here’s why 👇 Java follows almost all the OOP principles like Encapsulation, Inheritance, Polymorphism, and Abstraction. 🧠 It treats most of its components as objects, making it one of the strongest OOP-based languages today. ⚙️ However, there’s a twist! 🔄 Java still uses primitive data types (int, float, char, boolean, etc.) — which are not objects. Pure OOP languages treat everything as an object, so this makes Java not 100% object-oriented. To fix this, Java offers Wrapper Classes (Integer, Float, Character, etc.) that turn primitives into objects. 💪 So, we can say — 👉 Java is Object-Based but not Purely Object-Oriented. It’s a hybrid language that balances OOP concepts with performance efficiency. 🚀 I learned this interesting concept from Prem Kumar Ch, whose explanation made it crystal clear! 🙌 Thank you for the valuable guidance. 💫 #Java #OOPS #Programming #Developers #LearningJourney #Gratitude #TechFacts
To view or add a comment, sign in
-
🧠 Inside Java’s Map: How It Really Works! Ever wondered what happens under the hood when you put a key-value pair into a Map in Java? 🤔 Let’s peel back the layers and see how the magic happens! ⚙️ 🔍 What is a Map? A Map in Java stores data as key-value pairs — where each key is unique and maps to a specific value. Common implementations include: HashMap LinkedHashMap TreeMap ConcurrentHashMap But the real star of the show is HashMap — the most commonly used one! 🌟 ⚙️ How HashMap Works Internally When you call: map.put("Apple", 10); Here’s what happens step by step 👇 ➡️ Hashing the Key The hashCode() of the key ("Apple") is computed. The hash value is processed (via a hashing algorithm) to find the bucket index in the underlying array. ➡️ Storing in a Bucket Each bucket is a linked list (or tree after Java 8). If no key exists in that bucket, a new Node is created and stored there. ➡️ Handling Collisions If two keys map to the same bucket, they form a linked list (chaining). In Java 8+, if the list grows beyond 8 elements, it’s converted into a balanced Red-Black Tree — improving lookup time from O(n) to O(log n)! ➡️ Retrieval During get(key), Java again computes the hash and goes to the right bucket. It compares keys using equals() to find the exact match. 🧩 Key Methods Used hashCode() → Generates hash for locating the bucket equals() → Ensures uniqueness of keys resize() → Expands the array when load factor (default 0.75) is exceeded 💡 Fun Fact: HashMap’s design balances speed, memory efficiency, and collision handling — a masterpiece of data structure engineering! 📘 In short: HashMap = Array + Linked List + Red-Black Tree + Hashing = ⚡Fast Key-Value Lookup #Java #HashMap #DataStructures #JavaDeveloper #Coding #SoftwareEngineering #Internals #Performance
To view or add a comment, sign in
-
☕ Day 7 – Java 2025: Smart, Stable, and Still the Future 💡 🔹 Topic: ASCII Value in Java 🧩 What is ASCII Value? ASCII stands for American Standard Code for Information Interchange. It is a numerical representation of characters — where every letter, number, or symbol is assigned a specific numeric value between 0 and 127. For example, 'A' → 65, 'a' → 97, '0' → 48. --- ⚙️ How We Can Use ASCII Values in Java In Java, each character (char) has an internal ASCII code. You can easily get this value by type casting a character to an integer. This helps programmers perform character comparisons, sorting, encryption, and pattern logic. --- 🎯 Purpose of ASCII Values 1️⃣ Character Comparison: To check which character comes first or is greater based on ASCII order. Example: 'A' < 'a' because 65 < 97. 2️⃣ Encoding & Data Transmission: When sending text over systems or networks, ASCII ensures characters are universally understood. 3️⃣ Sorting and Logic Building: Used in string sorting algorithms or validation logic (e.g., checking if a character is uppercase, lowercase, or a number). 4️⃣ Mathematical Operations on Characters: You can perform arithmetic operations like converting uppercase to lowercase using ASCII difference. --- 💻 Simple Example char ch = 'A'; int ascii = (int) ch; // Type casting char to int System.out.println("ASCII value of " + ch + " is: " + ascii); Output: ASCII value of A is: 65 --- 🧠 Extra Insight 'A' to 'Z' → 65 to 90 'a' to 'z' → 97 to 122 '0' to '9' → 48 to 57 ASCII makes Java programs language-neutral and machine-readable for text processing tasks. --- ✨ #Day7OfJava #Java2025 #LearnJava #ASCIICode #JavaBasics #JavaCharacters #JavaForBeginners #CodeWithSneha #ProgrammingConcepts #100DaysOfJava #TechLearning #DeveloperJourney
To view or add a comment, sign in
-
-
🚀 Java Learning Journey – Day 22 🔥 Understanding Switch Case with Expressions (Java) Today I explored how switch-case works when we use expressions inside the case labels. ~ In Java, expressions like (0+1) or (1+2) get evaluated first, and then matched with the switch variable. The interesting part is fall-through, which happens when we don’t use a break statement. This helps in understanding how multiple cases can run together. ✅ Here’s the code I practiced today: -------------------------------------code start------------------------------------ public class SwitchDemo2 { public static void main(String[] args) { int x = 0; //x=0 (E) | x=1 (A,B) | x=2 (B) | x=3 (C,D,E) | x=4 (D,E) | x=5 (E) switch (x) { case (0+1): System.out.println("A"); case (1+1): System.out.println("B"); break; case (1+2): System.out.println("C"); case (2+2): System.out.println("D"); default: System.out.println("E"); } } } ----------------------------------code output------------------------------------ E -------------------------------------code end------------------------------------ 🧠 Key Takeaways case expressions are evaluated before matching. Without break, execution continues to the next case (fall-through). Helps in understanding how switch-case flows internally. 🌱 Personal Note: I’m continuously learning Java and exploring DevOps tools and practices to build a strong foundation for full-stack and automation development. If you like my daily progress posts, please support with a like, comment, or share ~ it truly motivates me to keep learning and sharing. 🙌 I’m also looking for internship opportunities in Java development or DevOps to apply my skills in real-world projects, learn from professionals, and grow further. If you know of any such opportunities or can guide me, I’d really appreciate your help 🙏 #JavaLearningJourney #day22 #Java #Programming #LearningInPublic #SwitchCase #JavaBeginners #CodeNewbie #FallThrough #DeveloperJourney #DevOps #TechJourney #LearningEveryday
To view or add a comment, sign in
-
-
🧠 Today’s Java Insight: Understanding Static Methods Today, I explored one of the most important concepts in Java — Static Methods and how they differ from object members. Here’s what I learned 👇 ⚙️ Static Methods ✅ Can be called without creating an object → ClassName.methodName(); ✅ Declared using the static keyword. ✅ Used when a method’s logic is common for all objects. ✅ Belongs to the class, not any specific object. 💻 Example: class MathUtils { static int square(int n) { return n * n; } } public class Main { public static void main(String[] args) { System.out.println(MathUtils.square(5)); } } 🧩 Static Members (Class Members) Class Members (static): Shared by all objects and can be accessed directly using the class name.(Everyone can access) 🔹static variables 🔹static methods 🔹static blocks 🔹static nested classes 🧱 Object Members (Instance Members) Object Members (non-static): Each object has its own copy and can only be accessed through an instance.(By instance can Access only ) 🔹instance variables 🔹instance methods 🔹constructors 🔹instance blocks ⚡ Dynamic Nature of Java Java is a dynamic programming language — 👉 The JVM loads classes only when needed, making execution efficient and memory-friendly. ✨ Key Takeaway: Use static when something should be shared among all objects and does not depend on instance data. Comment What will be the Output for these codes? #Java #OOP #StaticKeyword #Programming #JVM #JavaLearning #LearningJourney #Developers
To view or add a comment, sign in
-
-
Exploring JShell — Java’s REPL You Should Be Using More Often When Java 9 arrived, it brought something developers had been waiting for: a REPL (Read–Eval–Print Loop) called JShell. It lets you run Java code interactively, without creating a class, a main method, or even a file. That makes it one of the best tools for learning, prototyping, and debugging. Why use JShell? JShell is perfect for: Testing small pieces of Java code instantly Exploring new APIs without creating a project Validating algorithms before writing full classes Teaching Java in a fast, interactive way Trying out functional programming features from Java 8+ It dramatically shortens the feedback loop: you write → JShell executes → you learn. How to Start Just run: jshell You're inside an interactive Java environment. Useful Examples 1. Quick arithmetic or logic tests int x = 5; int y = 12; x * y JShell prints the result immediately. 2. Exploring Java APIs import java.time.*; LocalDate.now() Try new API methods without writing a full project. 3. Writing and testing methods on the fly int sum(int a, int b) { return a + b; } sum(10, 20) No class. No boilerplate. Just code. 4. Prototyping algorithms String reverse(String s) { return new StringBuilder(s).reverse().toString(); } reverse("Henrique") Perfect for preparing coding interviews or validating logic. Other Handy Commands /help # shows commands /vars # list variables /methods # list defined methods /imports # list imports /edit # open an editor to modify code /save file.jsh # save your session /open file.jsh # load a saved script Final Thoughts JShell is one of those tools that quietly boosts your productivity. It turns Java into the fast-feedback environment developers love in Python and JavaScript, while keeping the structure and safety of the JVM. If you haven’t used it yet, try it today — you’ll be surprised how much it speeds up your workflow. #Java #JShell #JDK #DeveloperTools #Productivity #LearningJava #SoftwareEngineering #JVM
To view or add a comment, sign in
-
🚀 Fixed a Logical Bug in “Contains Duplicate II” (Sliding Window Problem in Java) Today I revisited one of the seemingly simple problems — “Contains Duplicate II” — and realized how small syntax choices can completely change logic flow 😅 At first, I wrote the code using a mix of C++ and Java syntax, which caused compilation and logical issues. But while debugging, I learned some key lessons that made my solution cleaner, faster, and interview-ready 💪 🧩 The Problem Given an integer array nums and an integer k, return true if there are two distinct indices i and j such that: nums[i] == nums[j] && |i - j| <= k ⚙️ My Fixed Java Code import java.util.HashSet; class Solution { public boolean containsNearbyDuplicate(int[] nums, int k) { HashSet<Integer> set = new HashSet<>(); int i = 0; int j = 0; int n = nums.length; while (j < n) { if (Math.abs(j - i) > k) { set.remove(nums[i]); i++; } if (set.contains(nums[j])) { return true; } set.add(nums[j]); j++; } return false; } } ❌ Mistakes I Made Initially 1️⃣ Used set.get() and set.end — which belong to C++, not Java. ✅ Fixed by using set.contains(nums[j]). 2️⃣ Didn’t maintain a proper sliding window size. ✅ Simplified with if (Math.abs(j - i) > k) to ensure the window never exceeds k elements. 3️⃣ Didn’t clearly understand the window logic — that we remove older elements as we move forward. ✅ Learned to visualize the window as a moving frame over the array. 4️⃣ Overcomplicated the logic. ✅ Cleaned it up using a simple while loop and HashSet. 🧠 What I Learned Clean, minimal code > fancy syntax. Always check for language-specific methods — C++ vs Java can trick you! The sliding window technique isn’t about moving two pointers randomly — it’s about maintaining constraints efficiently. Debugging teaches more than success on the first try. 🎯 Targeting Product-Based & EdTech Companies As part of my SDE preparation for product-based and EdTech companies like FloBiz, Scaler, Razorpay, Unacademy, and Swiggy, I’m focusing on building strong fundamentals — not just solving problems, but deeply understanding why they work. 💬 Final Thought Every “wrong submission” is just a lesson wrapped in logic. Keep coding, keep debugging, and every small improvement compounds over time 💻🔥 Masai Prepleaf by Masai Newton School PhonePe Paytm Paytm Payments Bank Razorpay Razor Group PayU #Java #DSA #ProblemSolving #LeetCode #LearningInPublic #SoftwareDevelopment #ProductBasedPreparation #CodeWithDilsah #EdTech #FrontendDeveloper #FloBiz
To view or add a comment, sign in
-
-
💡 How Generics Make Object Comparison in Java Safer & Cleaner One of the most underrated benefits of Java Generics is how they simplify and secure the way we use Comparable and Comparator while comparing objects. Before Generics (pre-JDK 1.5), comparison logic often involved: ✔️ Storing objects as Object ✔️ Downcasting them manually ✔️ Hoping the cast doesn’t fail at runtime 😅 But with Generics, Java gives us compile-time type safety and eliminates unnecessary upcasting/downcasting. --- 🔍 What Problem Did Generics Solve? Without generics: class Student implements Comparable { int marks; public int compareTo(Object o) { Student s = (Student) o; // ❌ Risky downcast return this.marks - s.marks; } } Problems: You must cast from Object to Student. ⚠️ No compile-time checking — mistakes explode at runtime. Code becomes cluttered and unsafe. --- ✅ With Generics – Cleaner, Type-Safe, and Zero Casting class Student implements Comparable<Student> { int marks; public int compareTo(Student s) { // ✔️ No casting needed return this.marks - s.marks; } } And with Comparator: Comparator<Student> sortByName = (s1, s2) -> s1.name.compareTo(s2.name); Benefits: No upcasting to Object No downcasting back to original types Comparator & Comparable work with the specific type you intend Compiler ensures type correctness → safer & cleaner code --- 🎯 Why This Matters in Real Projects When working with large domain models (Employee, Product, Order, etc.), using generics avoids subtle runtime bugs. Collections like TreeSet, TreeMap, or Collections.sort() work perfectly with type-safe comparators. Your IDE offers better autocomplete because it knows the type you’re working with. --- 🚀 In short: Generics transformed the way we compare objects in Java—by replacing unsafe casting with clean, type-checked logic. Less boilerplate, more safety. #CleanCode #CodeQuality #SoftwareDevelopment #ProgrammingTips #LearnCoding
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