🔥 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
Day 3: Java Data Types and Variables Explained
More Relevant Posts
-
☀️ Day 10: Arrays in Java Today’s focus was on Arrays — one of the most powerful tools to store and manage data efficiently in Java. 💡 What I Learned Today An array is a collection of similar data types stored in contiguous memory. Indexing starts from 0. Arrays have a fixed size once created. You can access elements easily using a loop. Arrays make data handling faster and organized. 🧩 Example Code public class ArrayExample { public static void main(String[] args) { int[] numbers = {10, 20, 30, 40, 50}; System.out.println("Array elements:"); for (int i = 0; i < numbers.length; i++) { System.out.println(numbers[i]); } int sum = 0; for (int n : numbers) { sum += n; } System.out.println("Sum = " + sum); } } 🗣️ Caption for LinkedIn 📊 Day 10 – Arrays in Java Arrays are the backbone of structured data storage in Java. Today, I explored how to declare, access, and loop through arrays efficiently. Arrays make large data sets easy to manage — all stored neatly in one place! 💻 #CoreJava #LearnJava #Programming #JavaDeveloper #CodingJourney
To view or add a comment, sign in
-
-
⚙️ Day 3/100 — Exploring Java Operators, Expressions & Comments 💡 Today in my #100DaysOfJavaChallenge, I explored the true language of logic in Java — 👉 Operators, Expressions, and Comments ☕💻 Understanding how data interacts and how code communicates is a huge step toward writing clean, readable, and smart programs. 💡 What I Learned Today ✅ Java Operators Arithmetic: +, -, *, /, % Relational: ==, !=, >, <, >=, <= Logical: &&, ||, ! Assignment: =, +=, -=, *= Increment/Decrement: ++, -- Ternary Operator: condition ? trueValue : falseValue ✅ Expressions combine variables and operators to produce results. ✅ Comments help make code understandable and maintainable: Single-line: // This is a comment Multi-line: /* This is a multi-line comment */ Documentation comment: /** Used for generating docs */ 💻 Sample Practice Code public class Day3 { public static void main(String[] args) { // Variables and arithmetic operations int a = 10, b = 5; // initializing two integers System.out.println("Addition: " + (a + b)); // adds two numbers System.out.println("Division: " + (a / b)); // divides a by b /* Relational and logical operations */ System.out.println("Is a greater than b? " + (a > b)); boolean result = (a > b) && (b > 0); System.out.println("Result of logical expression: " + result); // Ternary operator String message = (a > b) ? "a is greater" : "b is greater"; System.out.println(message); } } #Day3 #100DaysOfCode #JavaDeveloper #LearningJourney #JavaProgramming #CodingChallenge #SpringBoot #SQL #JDBC #ProgrammerLife #IntelliJIDEA #JavaOperators #CommentsInCode #CleanCode
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
-
-
🧩 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
-
-
🚀 Understanding HashMap in Java – The Heart of Fast Lookups! Have you ever wondered how Java’s HashMap gives such blazing-fast access to data? ⚡ Let’s break it down simply 👇 🧠 What is a HashMap? A HashMap in Java is a data structure that stores data in key-value pairs. It allows O(1) average time complexity for insertion, deletion, and lookup! 💡 How it works internally: 1️⃣ Every key is converted into a hash code using the hashCode() method. 2️⃣ The hash code decides which bucket (or index) the entry will be stored in. 3️⃣ If two keys map to the same bucket (collision), Java uses a LinkedList or Balanced Tree (after Java 8) to handle it. 4️⃣ When you call get(key), Java calculates the hash again, jumps directly to the bucket, and fetches the value — super fast! ⚙️ Key Features: ✅ No duplicate keys ✅ Allows one null key and multiple null values ✅ Not thread-safe (use ConcurrentHashMap for concurrency) 🔍 Quick Tip: Always override equals() and hashCode() together to avoid unexpected behavior in collections like HashMap. #Java #HashMap #Coding #BackendDevelopment #JavaInterview #SpringBoot #AdvanceJava
To view or add a comment, sign in
-
🚀 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
To view or add a comment, sign in
-
-
📦 Day 14: Arrays vs ArrayList in Java Today I explored the difference between Arrays and ArrayList — both store multiple elements, but the way they work is totally different. 💡 What I Learned Today Arrays have a fixed size once created. ArrayList can grow or shrink dynamically. Arrays can hold primitive data types, while ArrayLists hold objects only. Arrays are faster and more memory-efficient. ArrayLists are flexible and come with many built-in methods. Use Arrays when you know the size in advance. Use ArrayList when you need to add or remove elements easily. 🧩 Example Code import java.util.ArrayList; public class ArrayVsArrayList { public static void main(String[] args) { // Array int[] numbers = {10, 20, 30}; System.out.println("Array element: " + numbers[1]); // ArrayList ArrayList<String> fruits = new ArrayList<>(); fruits.add("Apple"); fruits.add("Banana"); fruits.add("Mango"); System.out.println("ArrayList element: " + fruits.get(1)); } } 🗣️ Caption for LinkedIn 📊 Day 14 – Arrays vs ArrayList in Java Arrays are great for speed and fixed-size data, while ArrayLists offer flexibility with easy resizing. Choosing the right one depends on your use case — stability or adaptability. Another solid step forward in my #30DaysOfJava challenge 💪 #Java #Programming #CoreJava #LearnJava #CodingJourney
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
Full-Stack Developer (Kotlin/Java) & DevOps Engineer @ LSEG (London Stock Exchange Group) | Oracle Java Certified | HashiCorp Terraform & 2x AWS Certified
6moyou've laid out these fundamentals really nicely. the way you've explained primitive types and their role in memory management really shows how thoughtful type selection makes such a difference in real applications.