🚀 Today I Learned About the static Keyword in Java While learning Java today, I discovered why we use the static keyword — it helps in efficient memory management and avoids redundancy. 💡 Why We Use static The static keyword allows us to share common data or behavior across all objects of a class instead of duplicating it. It ensures memory efficiency and consistency. 🧩 When to Use static Before declaring a variable as static, ask: “Is this value common to all objects?” If yes, make it static. Example: In a Bank Application, the interest rate is common for all customers. So it should be declared as a static variable: class Bank { static double interestRate = 7.5; } ⚙️ Static Block – Real-World Example A static block runs once when the class is loaded, not every time an object is created. It’s ideal for initialization tasks like loading configuration files or connecting to a database. class DatabaseUtil { static { System.out.println("Loading Database Driver..."); // Code to initialize DB connection } } This ensures one-time setup and avoids repeated execution. ✨ In Summary static variable → shared data static method → shared behavior static block → one-time initialization ✅ Advantage: Saves memory and improves performance 💬 How did you first understand the concept of static in Java? See an example code that usage of static variable. #Java #OOP #CodingJourney #StaticKeyword #SoftwareDevelopment #TodayILearned
Understanding the static keyword in Java for memory efficiency
More Relevant Posts
-
🧩 1️⃣ Data Types in Java Java is a strongly typed language, meaning each variable must have a defined data type before use. There are two main categories: 🔹 Primitive Data Types: Used to store simple values like numbers, characters, or booleans. (Examples: int, float, char, boolean, etc.) 🔸 Non-Primitive Data Types: These store memory references rather than direct values. Includes Strings, Arrays, Classes, and Interfaces. Together, they define how data is represented and managed in memory. ⚙️ 2️⃣ Type Casting Type casting allows conversion from one data type to another. There are two kinds of casting in Java: ✅ Widening (Implicit) — Automatically converts smaller types to larger ones. 🧮 Narrowing (Explicit) — Manually converts larger types to smaller ones. This ensures flexibility while maintaining type safety, especially during calculations and data transformations. 🔄 3️⃣ Pass by Value vs Pass by Reference Java always uses Pass by Value, but the behavior varies depending on whether we’re working with primitives or objects. For Primitive Data Types: A copy of the value is passed, so changes inside the method don’t affect the original variable. For Objects (Reference Types): The reference (memory address) is passed by value, meaning both point to the same object. Any change made inside the method reflects on the original object. 💡 Key Takeaways ✅ Java has 8 primitive and multiple non-primitive data types. ✅ Type casting ensures smooth conversions between compatible types. ✅ Java is always pass-by-value, even when handling objects through references. 🎯 Reflection Today’s revision helped me understand how Java manages data behind the scenes — from defining variables to converting data types and managing memory references. Building strong fundamentals in these areas strengthens the base for advanced Java concepts ahead. 💪 #Java #Programming #Coding #FullStackDevelopment #LearningJourney #DailyLearning #RevisionDay #TAPAcademy #TechCommunity #SoftwareEngineering #JavaDeveloper #DataTypes #TypeCasting #PassByValue #PassByReference
To view or add a comment, sign in
-
-
⚙️ Deep Dive into Java Interfaces, Exception Handling, and Collections Framework Ever wondered how Java manages polymorphism, abstraction, and safe error handling — all while keeping performance in check? 🤔 That’s exactly what I explored this week while learning Java in depth. Here’s a quick breakdown of what I learned 👇 💥 1️⃣ Exception Handling — Writing Robust Code Learned about throw, throws, and the difference between checked & unchecked exceptions. Explored how try, catch, and finally blocks work under the hood. Understood how Java ensures program stability even when errors occur. 📚 2️⃣ Collections Framework — Efficient Data Management Understood why Java Collections are used instead of arrays. Studied the time complexity and internal working of List, Set, and Map. Learned how data structures like HashMap, LinkedHashSet, and ArrayList are implemented internally. 🧩 3️⃣ Interfaces — The Power of Abstraction Understood how interfaces help achieve polymorphism and multiple inheritance in Java. Learned that interfaces can extend other interfaces but cannot implement them. Explored default methods (Java 8+), which allow method bodies inside interfaces. Attached my handwritten summary 📸 for a quick glance at these key interface concepts. 🚀 Takeaway: Understanding these topics gave me deeper insight into how Java ensures modularity, flexibility, and runtime efficiency — the backbone of backend development. #Java #BackendDevelopment #LearningJourney #JavaDeveloper #ExceptionHandling #CollectionsFramework #Interface #OOP #SpringBoot #CodingJourney #SoftwareDevelopment #TechLearning
To view or add a comment, sign in
-
🧠 What is hashCode in Java and when should you override it? In Java, every object has a hashCode() method inherited from Object. It returns an int value that acts like a numeric fingerprint of that object. It’s not guaranteed to be unique, but: • Equal objects must have the same hash code. • Different objects can have the same hash code (called a hash collision). Hash codes are mainly used to speed up lookups in hash-based data structures like HashMap, HashSet, and ConcurrentHashMap 🤔How does this lookup work? When you add or search for an object in a HashMap or HashSet, Java: 1. Calls hashCode() to find the bucket where the object might be. 2. Then uses equals() to check if the object is actually there. This makes lookups very fast on average O(1). Due to this double check, you must override hashCode() whenever you override equals(). This is required by the hashCode contract: “If two objects are equal according to equals(), then calling hashCode() on each of them must return the same integer result.” Failing to follow this rule can lead to: • Objects being “lost” in hash collections. • Inconsistent or unpredictable behavior. #Java #HashCode #Equals #JavaProgramming #SoftwareEngineering #DataStructures #CodingTips #HashMap #HashSet
To view or add a comment, sign in
-
-
Bloom Filters-An Advanced Data Structure implementation with Spring Boot Java Application Hi All, While working on an application project , We as developers come across the use case where we need find a if a record already exists in system having billions of datasets. Thankfully , there is a library available to make is simple for us . For example : Like finding an email id exists in system or not . This check needs to be real quick . it is just like finding a needle in a Haystack . How this problem can be solved quickly in no time . Well , the answer to our mystery lies in our favorite topic DSA — Data Structure and Algorithms. Today , We will go through an Overview of Bloom Filters-An Advanced Data Structure implementation with Spring Boot Java Application. So Let’s Begin : More Details on the topic are in my blog post at javarevisited. https://lnkd.in/djVCvefZ Happy Learning … 😊 Happy Coding ….. 👍 I publish content regularly. Follow me on Medium & let’s grow together 👏. #passionateprogrammer #java #javadevelopers #javaengineer #javafullstackdeveloper #javadevelopment #JavaFeatures #Javatimeline #javachronology #jee #futureofjava #development #funwithjava #computing #programming #coding #handson #crazycoder #passionateprogrammer #technologyenthusiast #handsonarchitect😊
Bloom Filters-An Advanced Data Structure implementation with Spring Boot Java Application medium.com To view or add a comment, sign in
-
🚀 Day 102: Mastered Java Fundamentals — Data Types, String, Arithmetic & Logical Operators Today I focused on strengthening the core of Java — the building blocks that every backend/Java developer must master. 🔹 1. Data Types in Java Java is statically typed, meaning every variable must have a type. ✅ There are 8 primitive data types: TypeSizeExamplebyte1 bytebyte b = 10;short2 bytesshort s = 1000;int4 bytesint age = 21;long8 byteslong views = 100000L;float4 bytesfloat pi = 3.14f;double8 bytesdouble price = 89.99;char2 byteschar grade = 'A';boolean1 bitboolean isActive = true; 👉 Non-primitive types like String, Arrays, Classes store references instead of direct values. 🔹 2. String in Java Strings are not primitive — they are objects from the String class. ✨ Why are they special? Immutable (cannot be changed after creation) Stored in String Constant Pool to improve memory efficiency Thread-safe and used heavily in Java internals Common methods: name.length(); name.toUpperCase(); name.charAt(0); name.contains("Java"); 🔹 3. Arithmetic Operators Basic mathematical operations in Java: OperatorMeaning+Addition-Subtraction*Multiplication/Division%Remainder++ / --Increment / Decrement 🔹 4. Logical Operators Used in conditions and decision-making: OperatorMeaning&&Logical AND (true if both conditions are true)`!NOT (reverses the value) Example: if(age >= 18 && hasLicense) { System.out.println("You can drive!"); } ✅ Mastering these concepts builds a strong foundation for: OOP concepts Collections Exception Handling Spring Boot & Backend development Learning fundamentals pays off later. The deeper your basics → the stronger your code. #Java #Day102 #LearningInPublic #BackendDevelopment #100DaysOfCode #JavaDeveloper #DSA #ProgrammingJourney
To view or add a comment, sign in
-
-
🔥 Day 3 – Data Types and Variables in Java 🧠 Post Content (for LinkedIn): ☕ Day 3 of my 30-day Core Java journey! Today, I explored one of the most important topics — Data Types and Variables in Java. Every program handles data, and understanding how Java stores and processes it is key. 💡 What is a Variable? A variable is like a container that stores a value in memory. You must declare it with a data type before using it. 🧩 Example: int age = 22; String name = "Pasupathi"; double marks = 89.5; ⚙️ Types of Data in Java 🔹 1. Primitive Data Types (8 total) Used for basic values. byte short int long float double char boolean Example: int x = 10; boolean isOn = true; 🔹 2. Non-Primitive (Reference) Data Types Used for complex objects like Strings, Arrays, Classes, Interfaces. Example: String city = "Coimbatore"; int[] numbers = {1, 2, 3, 4}; 🎯 Takeaway: 💭 Variables help store and reuse data efficiently. Choosing the right data type improves performance and memory usage. #CoreJava #JavaLearning #PasupathiLearnsJava #Programming #DataTypes #JavaVariables
To view or add a comment, sign in
-
-
Master Java TreeMap: A 2025 Guide to sorted Key-Value Pairs Tame Your Data Chaos: A No-BS Guide to Java TreeMap Ever found yourself with a bunch of key-value pairs in Java and thought, "Ugh, I need to sort this, but doing it manually is a pain"? You’re not alone. We've all been there, writing loops and comparators until our eyes glaze over. What if I told you Java has a built-in superhero that automatically keeps your data sorted for you? Say hello to the TreeMap. In this guide, we're not just going to skim the surface. We're going to dive deep into what a TreeMap is, how it works under the hood, and when you should (and shouldn't) use it. We'll break it down with real-world analogies and code examples that actually make sense. Let's get sorted! 😉 What is a TreeMap, Actually? Think of it like a super-organized contact list on your phone. A regular HashMap would be like adding contacts randomly—you have them, but finding "Zara" might take a while. A TreeMap, however, is like your contact list set to automatically sort by name. The moment you https://lnkd.in/guHRVTf5
To view or add a comment, sign in
-
Master Java TreeMap: A 2025 Guide to sorted Key-Value Pairs Tame Your Data Chaos: A No-BS Guide to Java TreeMap Ever found yourself with a bunch of key-value pairs in Java and thought, "Ugh, I need to sort this, but doing it manually is a pain"? You’re not alone. We've all been there, writing loops and comparators until our eyes glaze over. What if I told you Java has a built-in superhero that automatically keeps your data sorted for you? Say hello to the TreeMap. In this guide, we're not just going to skim the surface. We're going to dive deep into what a TreeMap is, how it works under the hood, and when you should (and shouldn't) use it. We'll break it down with real-world analogies and code examples that actually make sense. Let's get sorted! 😉 What is a TreeMap, Actually? Think of it like a super-organized contact list on your phone. A regular HashMap would be like adding contacts randomly—you have them, but finding "Zara" might take a while. A TreeMap, however, is like your contact list set to automatically sort by name. The moment you https://lnkd.in/guHRVTf5
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