Day 9- What I Learned In a Day(JAVA) What is a Data Type? A data type in Java defines the type of value a variable can store and how much memory is allocated for it. Types of Data Types in Java: Java data types are divided into two categories: 1️⃣ Primitive Data Types Primitive data types store simple values directly in memory. They are predefined by Java and have fixed size. Java has 8 primitive data types: 1️⃣ byte Size: 1 byte (8 bits) Range: -128 to 127 2️⃣ short Size: 2 bytes (16 bits) Range: -32,768 to 32,767 3️⃣ int Size: 4 bytes (32 bits) Range: -2,147,483,648 to 2,147,483,647 4️⃣ long Size: 8 bytes (64 bits) Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 5️⃣ float Size: 4 bytes (32 bits) Range: Approximately ±3.4 × 10³⁸ 6️⃣ double Size: 8 bytes (64 bits) Range: Approximately ±1.7 × 10³⁰⁸ 7️⃣ char Size: 2 bytes (16 bits) Range: 0 to 65,535 (Unicode characters) 8️⃣ boolean Size: JVM dependent (typically 1 bit logically) Values: true or false Note:The number datatype in increasing order the capacity byte<short<int<long<float<double Non-Primitive Data Types: Non-primitive data types store references (addresses) of objects, not the actual value. They do not have fixed size. Examples: String Arrays Classes Objects Interfaces Note:In java,every class name is considered as a Non-Primitive Datatype. Practiced the primitive datatype declaration: 👇 #Java #JavaProgramming #CoreJava #LearnJava #CodingJourney #DailyLearning
Java Data Types: Primitive & Non-Primitive Explained
More Relevant Posts
-
Day 2/100 — Variables & Data Types in Java 🧱 Before you can write any meaningful Java program, you must understand one fundamental concept — how Java stores data in memory. That’s where variables and data types come in. A variable is simply a named container in memory. When you write int age = 25, you’re telling Java to reserve a space in memory, label it age, and store the value 25 inside it. A data type tells Java two things: • What type of value will be stored • How much memory should be allocated Java has 8 primitive data types: int → whole numbers double → decimal numbers char → a single character (always use single quotes) boolean → true or false long → large whole numbers float → decimal numbers with less precision byte → very small integers short → small integers ⚠️ One important thing beginners often miss: String is NOT a primitive data type. It’s a class, which is why it starts with a capital S. 3 rules you should always remember: ✔ Use single quotes (' ') for char ✔ Use double quotes (" ") for String ✔ long values should end with L → 123456789L ✔ float values should end with f → 3.14f 💻 Today's Challenge Declare 5 variables about yourself: • Name • Age • Height • City • Whether you are a student Use the correct data types for each one. Drop your code in the comments — I’ll check if the types are correct. 👇 #Java #100DaysOfJava #100DaysOfCode #CoreJava #LearnJava #JavaDeveloper #Programming
To view or add a comment, sign in
-
-
Day 11 – Arrays in Java | Full Stack Journey Today I learned one of the most important data structures in Java — Arrays. What is an Array? An Array is a data structure that stores multiple values of the same data type under a single variable name. Arrays are objects in Java They store homogeneous data Index starts from 0 Declaring an Array int[] a; int a[]; Creating / Initializing an Array int[] a = new int[5]; Or directly: Java Copy code int[] a = {10, 20, 30, 40, 50}; Accessing Elements Java Copy code a[0] = 10; System.out.println(a[2]); Index range: Copy code 0 to (n - 1) Types of Arrays 1-D Array Stores elements in a single row. int[] a = new int[5]; 2-D Array Rows and columns (matrix form). int[][] a = new int[2][5]; Access: a[0][1] 3-D Array Blocks → Rows → Columns Java Copy code int[][][] a = new int[2][3][5]; Access: Java Copy code a[0][1][2] Jagged Array Rows have different column sizes. Java Copy code int[][] a = new int[2][]; a[0] = new int[3]; a[1] = new int[5]; Important: length Property a.length // Rows a[0].length // Columns Drawbacks of Arrays Can store only homogeneous data Fixed size (cannot grow or shrink) Requires contiguous memory Key Takeaway Arrays are the foundation for advanced data structures like: ArrayList Matrices Dynamic Programming Multi-dimensional Data Handling Understanding arrays clearly builds a strong base for backend development and problem solving. #Day11 #Java #Arrays #DataStructures #FullStackJourney #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Java Series – Day 2 📌 Variables & Data Types in Java 🔹 What is it? A variable is a container used to store data in memory, and data types define what kind of value a variable can store. Java mainly has two types of data types: • Primitive Data Types – int, double, char, boolean, etc. • Non-Primitive Data Types – String, Arrays, Objects, etc. 🔹 Why do we use it? Variables help programs store and manipulate data during execution. For example: In a banking application, a variable can store a user's account balance, name, or transaction amount. Also, Java stores data in different memory areas: • Stack Memory – Stores primitive variables and method calls. • Heap Memory – Stores objects like Strings, arrays, and custom objects. This separation helps Java manage memory efficiently. 🔹 Example: public class Main { public static void main(String[] args) { int age = 22; // Primitive type (stored in stack) double salary = 50000.50; String name = "Raushan"; // Object stored in heap System.out.println(name + " is " + age + " years old."); } } 💡 Key Takeaway: Understanding variables and memory (Stack vs Heap) helps you write efficient and optimized Java programs. What do you think about this? 👇 #Java #CoreJava #JavaDeveloper #Programming #BackendDevelopment
To view or add a comment, sign in
-
🔹 In Java, the Map hierarchy forms the foundation for key-value data structures: Map interface → HashMap, LinkedHashMap, TreeMap. Each has its own behavior and use-case in terms of ordering, and sorting. Many developers use HashMap daily, but do you know what happens behind the scenes? Let’s decode it 👇 HashMap Internals: Beyond Simple Key-Value Storage 1️⃣ Buckets & Nodes HashMap stores entries in an array of buckets. Each bucket contains nodes, and each node holds a key-value pair. 2️⃣ Hashing: The Core Mechanism Every key generates a hash code, which is used to compute the bucket index: index = (n - 1) & hash This ensures efficient data distribution and fast access. 3️⃣ Collision Handling When multiple keys map to the same bucket → collision occurs. Java handles collisions using: Linked List (Java < 8) Red-Black Tree (Java 8+, when bucket size > 8) 4️⃣ Insertion & Retrieval Insertion (put): hash → bucket → insert/update node Retrieval (get): hash → bucket → traverse nodes → match key 5️⃣ Resize & Load Factor Default capacity = 16, load factor = 0.75 When size > capacity × load factor, HashMap resizes (doubles capacity) to maintain performance 💡 Performance Insights Average case: O(1) ✅ Worst case: O(log n) after Java 8 ✅ Takeaway: A well-implemented hashCode() and equals() is key to fast, reliable HashMap performance. #Java #HashMap #DataStructures #Programming #SoftwareEngineering #CodingTips #DeveloperInsights
To view or add a comment, sign in
-
-
🚀 From Temporary Memory to Persistent Data — My Deep Dive into Java File Handling While studying Java File Handling, I realized an important concept about how programs manage data. When a program runs, data is stored in RAM (temporary memory). But once the program stops, that data disappears. So the real challenge is: How do applications preserve data even after the program stops running? This is where File Handling becomes essential. It allows programs to store data on disk (files) so it can be read again later. 📂 File Class Java provides the File class to interact with the file system. Operations I explored: • createNewFile() → create a file • mkdir() / mkdirs() → create directories • exists() → check file existence • list() → list files inside a directory Important: The File class manages files, but it does not read or write data. 📦 Streams — Reading & Writing Data Actual data operations are done using Streams. File → Program → Input Stream (Read) Program → File → Output Stream (Write) Examples: FileInputStream FileOutputStream Streams process data byte by byte, allowing efficient file handling. ⚡ Buffered Streams To improve performance, Java uses Buffered Streams. A buffer temporarily stores data before transferring it. Program → Buffer → File Examples: BufferedInputStream BufferedOutputStream BufferedReader BufferedWriter This significantly improves I/O performance. 🔐 Serialization & Deserialization Serialization converts a Java object into a byte stream so it can be stored or transmitted. Key concepts: Serializable interface serialVersionUID transient keyword ObjectOutputStream The reverse process, Deserialization, converts the byte stream back into the original object using ObjectInputStream. 💡 Key Insight Java File Handling connects multiple core concepts: • RAM vs Disk storage • Data persistence • Stream-based data flow • Buffered I/O optimization • Object serialization & deserialization Understanding this helped me see how Java applications store, manage, and retrieve data in real systems. Grateful to my mentor Prasoon Bidua at REGex Software Services for guiding us to understand the “why behind the technology.” #Java #JavaDeveloper #FileHandling #Serialization #JavaIO #BackendDevelopment
To view or add a comment, sign in
-
-
🚀 Problem Solved: Two Sum (Java) Today I solved the classic Two Sum problem using Java and HashMap. Instead of using a brute-force approach with nested loops (O(n²)), I optimized the solution using a HashMap to achieve O(n) time complexity. 🔹 Key Idea: While iterating through the array, store each number and its index in a HashMap. For every element, calculate the complement (target − current value) and check if it already exists in the map. If it exists, we found the pair of indices that add up to the target. #DSA #DataStructures #Algorithms #CodingInterview #ProblemSolving 💡 Concepts Used: HashMap Time Complexity Optimization Problem Solving with Data Structures This approach improves performance and is commonly asked in coding interviews. #Java #DSA #ProblemSolving #CodingInterview #LeetCode #HashMap #SoftwareDevelopment Problem Explanation (You can add in comments or description) Problem: Given an array nums and an integer target, return the indices of two numbers such that they add up to the target. Example: nums = [2,7,11,15] target = 9 Output = [0,1] Because: nums[0] + nums[1] = 2 + 7 = 9 Approach Used (HashMap – Optimal) Create a HashMap to store numbers and their indices. Loop through the array. For each number: Calculate complement = target - nums[i] Check if the complement exists in the HashMap. If yes → return the stored index and current index. Otherwise store the current number and index in the map.
To view or add a comment, sign in
-
-
🚀 Day 26 of 30 Days of Java: Let's Map It Out! Today, we're diving deep into one of the most essential data structures in Java: the Map interface! Think of it like a super-powered dictionary. A Map stores data as key-value pairs, where each unique key points to a specific value. It's the go-to structure whenever you need efficient data retrieval based on a unique identifier. Java gives us several powerful Map implementations, each with its own special features. We explored the most common ones: 🚀 HashMap: The fastest option, but doesn't guarantee any specific order of elements. Great for maximum performance! 🔗 LinkedHashMap: Maintains the order of elements based on insertion. Useful when order matters! 🌳 TreeMap: Stores keys in their natural sorted order (e.g., alphabetical or numerical). Perfect for sorted data retrieval! 🔒 Hashtable: A thread-safe Map, but slower than HashMap. Used mainly in multithreaded environments! We also looked at some essential Map methods: put(key, value): Adds a new key-value pair to the Map. get(key): Retrieves the value associated with a given key. remove(key): Deletes the key-value pair for a specific key. containsKey(key): Checks if a particular key exists in the Map. containsValue(value): Checks if a certain value exists in the Map. size(): Returns the number of key-value pairs in the Map. clear(): Removes all key-value pairs from the Map. And we learned a couple of ways to iterate through a Map, so we can access and process each element. The choice of which Map implementation to use depends on your specific needs: performance, order, sorted keys, or thread safety. Maps are absolutely fundamental in Java programming, from handling user data to building complex applications. Check out the sketchnote for a quick visual summary of these Map types and their characteristics! #Java #Programming #DataStructures #MapInterface #JavaHashMap #LinkedHashMap #JavaTreeMap #JavaHashtable #LearningJava #Coding #SoftwareEngineering #DeveloperLife #TechLearning #30DaysOfJava
To view or add a comment, sign in
-
-
📂 Deep Dive into FileInputStream & FileOutputStream (Java) Today I explored Java File Handling more deeply, focusing on FileInputStream and FileOutputStream, which are part of the Byte Stream API in Java. Understanding how data actually moves between RAM and the Hard Disk is an important concept when working with files, streams, and data processing. 🔹 FileOutputStream – Writing Data to a File FileOutputStream is used when we want to transfer data from the program (RAM) to a file stored on the hard disk. Key points: • It belongs to Byte Streams • Works with 8-bit data (bytes) • The write(int) method writes only one byte at a time • When writing text like a String, it must first be converted into a byte array 📌 Conceptual Flow RAM → Byte Array → FileOutputStream → File (Hard Disk) 🔹 FileInputStream – Reading Data from a File FileInputStream is used to read data from a file and bring it into the program memory. Key points: • Reads data byte by byte • The read() method returns data in the form of an integer • Since the value represents a byte, it is usually typecast into a character for display or processing 📌 Conceptual Flow File (Hard Disk) → FileInputStream → Program (RAM) 💡 Key Learning Working with byte streams helped me understand how Java internally handles low-level file operations, where data flows as bytes between memory and storage. This concept becomes very important when dealing with: • Binary files • Image or media processing • Serialization • Network streams Continuing to explore deeper concepts in Java I/O and backend fundamentals. 🚀 A special thanks to my trainer Prasoon Bidua at REGex Software Services for sharing such deep insights and explaining these concepts so clearly during the class. #Java #JavaIO #FileHandling #BackendDevelopment #Programming #LearningInPublic
To view or add a comment, sign in
-
-
🚀 **Mastering Java Collection Framework – The Backbone of Data Handling!** Understanding the **Collection Framework** is essential for every Java developer aiming to write efficient and scalable applications. 📌 **What is Collection Framework?** It allows us to manage a **group of elements and objects** effectively in Java. 💡 **Key Operations You Can Perform:** ✔️ Data Insertion ✔️ Deletion ✔️ Manipulation ✔️ Updation ✔️ Searching ✔️ Sorting 🔹 The Collection Framework internally supports **Generics**, which means: 👉 You can store different types of data and objects safely and efficiently. 📚 **Core Concept:** * `Collection` is an **interface** from the `java.util` package * It is the **root interface** of the collection hierarchy * Represents a group of objects (elements) ⚡ **Important Points:** 🔸 Some collections allow duplicates, others do not 🔸 Some are ordered, others are unordered 🔸 No direct implementation for Collection interface 🔸 Instead, Java provides implementations through sub-interfaces 📊 **Sub-Interfaces & Implementations:** 👉 **List** * ArrayList * LinkedList * Stack * Vector 👉 **Set** * HashSet * LinkedHashSet * TreeSet 👉 **Map** *(Not a direct subtype of Collection but part of framework)* * HashMap * LinkedHashMap * TreeMap * Hashtable #Java #JavaDeveloper #FullStackDeveloper #Programming #Coding #Developers #SoftwareEngineering #TechLearning #LearnJava #JavaCollections #DataStructures #CodingLife #ITCareer #DeveloperCommunity #ProgrammingTips #JavaTraining #CareerGrowth #TechSkills #SoftwareDeveloper #ShiftEduTech
To view or add a comment, sign in
-
-
The Hidden Mechanism Behind ThreadLocal in Java ThreadLocal is often explained simply as: “Data stored per thread.” That’s true — but the interesting part is how it actually works internally. Most developers think the data lives inside ThreadLocal. It doesn’t. How ThreadLocal Works Internally Each Thread object maintains its own internal structure: Thread └── ThreadLocalMap ├── ThreadLocal → Value ├── ThreadLocal → Value The important detail: The map belongs to the Thread, not to ThreadLocal. ThreadLocal simply acts as a key. Basic Flow When you call: ThreadLocal.set(value) Internally: Copy code thread = currentThread map = thread.threadLocalMap map.put(ThreadLocal, value) When you call: ThreadLocal.get() It retrieves the value from the current thread’s map. Each thread therefore has its own independent copy. Where This Is Used in Real Systems You’ll find ThreadLocal used in many frameworks: • Spring Security → SecurityContextHolder • Transaction management → TransactionSynchronizationManager • Logging correlation IDs • Request scoped context It allows frameworks to store request-specific data without passing it through every method. The Hidden Danger If you forget to call: Copy code ThreadLocal.remove() You can create memory leaks. Why? Because thread pools reuse threads. Old values may remain attached to long-lived threads. ThreadLocal is simple conceptually. But its internal design is what makes many Java frameworks work efficiently. Have you used ThreadLocal in production code? #Java #CoreJava #Multithreading #ThreadLocal #SpringBoot #BackendEngineering #InterviewPreparation
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