One of the most fundamental concepts in Java 💻 Data Types. Before writing logic, we must understand how data is stored in memory (RAM) and how Java manages it internally. 🧠 What is a Data Type? A Data Type defines: ✅ What type of value a variable can store ✅ How much memory is allocated ✅ The range of values it can hold ⚡RAM stores data in bytes, and every byte contains 8 bits. Computers understand only 0s and 1s (binary). 🔹 Java Primitive Data Types (8 Types) Java has 8 primitive data types, grouped into four categories: 1️⃣ Integer Types Data Type Size Range ✅byte 1 byte (8 bits) -128 to 127 ✅short 2 bytes -32,768 to 32,767 ✅int 4 bytes -2,147,483,648 to 2,147,483,647 ✅long 8 bytes Very large range (-2⁶³ to 2⁶³-1) 📌 Example: Java👇 int age = 21; long population = 9223372036854775807L; 2️⃣ Floating-Point Types Data Type Size float 4 bytes double 8 bytes 📌 Example: Java👇 float price = 99.99f; // f suffix required double salary = 45000.75; 3️⃣ Character Type Data Type Size char 2 bytes 📌 Example: Java👇 char grade = 'A'; 4️⃣ Boolean Type Data Type Size boolean 1 bit (logical) 📌 Example: Java👇 boolean isSelected = true; ⚫ Important Points to Remember ⭐ Java has 8 primitive data types ⭐ int is the default integer type in Java ⭐ For long, we must use L suffix ⭐ For float, we must use f suffix ⭐ Range formula for signed integers: 👉 -2ⁿ⁻¹ to 2ⁿ⁻¹ - 1 ⭐ String is NOT a primitive data type (It is an object) ⭐ Choosing the correct data type improves memory efficiency. 🚀 Why Data Types Matter? ✔ Better memory management ✔ Prevent overflow errors ✔ Improve performance ✔ Strong foundation for interviews Understanding data types means understanding how Java talks to memory 💡 TAP Academy #Java #CoreJava #DataTypes #ProgrammingBasics #JavaDeveloper #LearningJourney #SoftwareDevelopment #Coding
Java Data Types: Understanding Memory Storage and Management
More Relevant Posts
-
🚀 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
-
-
Day 20 – Learning Java Full Stack + Starting SQL A backend developer needs two core skills: 1️⃣ Application Logic → Java 2️⃣ Data Management → SQL So along with continuing my Java Full Stack journey, I’ve started exploring SQL fundamentals today. Here’s what I learned 👇 🔹 What is SQL? SQL (Structured Query Language) is a language used to communicate with databases. It helps us store, retrieve, update, and manage data efficiently. Interestingly, SQL was originally called SEQUEL (Structured English Query Language) and was introduced by Raymond Boyce and Donald Chamberlin. 🔹 What is DBMS? DBMS (Database Management System) is software used to manage databases. It allows us to perform the basic CRUD operations: ✔ Create / Insert ✔ Read / Retrieve ✔ Update / Modify ✔ Delete / Drop 🔹 Understanding the Relational Model In most modern databases, data is stored using the Relational Model, introduced by E. F. Codd. Data is stored in tables, which consist of: • Rows (Tuples) → represent complete records • Columns (Attributes) → represent properties of an entity • Cells → intersection of rows and columns Example entities: Student, Employee, Product, etc. 🔹 Important SQL Data Types Some commonly used SQL data types: CHAR(size) → Fixed length storage for characters. VARCHAR(size) → Variable length storage (more memory efficient). NUMBER(precision, scale) → Used to store numeric values. DATE → Stores date values (DD-MMM-YYYY format). LOB (Large Object) → Used to store large data. Types include: • CLOB → Character Large Object • BLOB → Binary Large Object 📌 Key takeaway today Backend development is not just about writing code. It’s about connecting applications with data. Java helps build the logic, SQL helps manage the data layer. Step by step, building stronger backend fundamentals. #Java #SQL #BackendDevelopment #JavaFullStack #Database #SoftwareDevelopment #LearningInPublic #Programming #TechLearning #100DaysOfCode
To view or add a comment, sign in
-
-
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
To view or add a comment, sign in
-
I build my own Stack data structure in Java (Array + LinkedList implementation) I did'nt just added simple (push/pop) operations, i actually implemented some decent methods in both implementations. I overrode the toString() method so that whenever the object reference is printed, it displays the stack’s contents instead of the default memory address representation. When building using Array the most important concept i learned is dynamic resizing. 🔹 Array-based Dynamic Stack: Generic implementation (Stack<T>) Dynamic resizing (capacity doubles when full) push, pop, peek, search trimToSize() for memory optimization reverse() using two-pointer technique swapTop() utility method clone() for deep copy pushAll() with varargs & collections popMultiple() for batch operations 🔹 Linked List-based Stack Generic stack with Comparable support Efficient push / pop using head pointer contains() search operation toArray() conversion clone() while preserving order sort() functionality using Collections.sort() Batch operations like pushAll() and pop(k) 💡 Key concepts practiced Generics in Java Dynamic memory management Custom exception handling Linked list node design Time complexity considerations (O(1) push/pop) Designing reusable APIs This exercise helped me understand how real data structures work internally, instead of just using library implementations. View comment section for the code on github. Next, I'm planning to implement: Queue (Array + Linked List) Deque Iterator support for custom data structures Always open to feedback, suggestions, or improvements from experienced developers. #Java #DataStructures #DSA #ComputerScience #SoftwareEngineering #LearningInPublic #JavaDeveloper
To view or add a comment, sign in
-
🔥 Understanding data structures in Java: Linked Lists explained! 🚀 Linked lists are a fundamental data structure where each element (node) is linked to the next one in line. They are flexible and dynamic, allowing for efficient insertions and deletions. Developers use linked lists to manage and organize data in an orderly manner, crucial for optimizing memory usage and improving performance. Ready to dive in? Here's a step-by-step breakdown: 1. Create a Node class to represent the elements. 2. Implement methods for insertion, deletion, and traversal. 3. Manage the connections between nodes correctly. Full code example: ```java class Node { int data; Node next; public Node(int data) { this.data = data; this.next = null; } } ``` Pro tip: Always ensure to update the pointers carefully when manipulating linked lists to avoid errors. Common mistake to avoid: Forgetting to update the pointer references when adding or removing nodes can lead to memory leaks. 🌟 What other data structures have you explored in Java? Share your favorites! 💬 🌐 View my full portfolio and more dev resources at tharindunipun.lk #DataStructures #JavaProgramming #LinkedLists #CodingTips #DeveloperCommunity #MemoryManagement #PerformanceOptimization #TechExplained
To view or add a comment, sign in
-
-
☕ DSA Using Java – Stack Data Structure Explained The Stack is one of the most fundamental data structures in Data Structures & Algorithms (DSA). It follows the principle of: 👉 LIFO (Last In, First Out) This means the last element inserted into the stack is the first one to be removed. 🔹 What is a Stack? A stack allows operations only at one end, called the top. It supports controlled data access: Only the last inserted element can be accessed or removed. Push and Pop operations are tightly connected. Think of it like a stack of plates — you can only remove the top plate first. 🔹 Basic Stack Operations 1️⃣ Push Adds an element to the top of the stack. If the stack is full → Error is shown. 2️⃣ Pop Removes the top element from the stack. Top index is decremented after removal. 3️⃣ Peek Returns the top element without removing it. 4️⃣ isFull Checks whether the stack is full. 5️⃣ isEmpty Checks whether the stack is empty. 🔹 Stack Implementation in Java A stack can be implemented using: An array A top variable (initialized to -1) Example logic: Push: intArray[++top] = data; Pop: return intArray[top--]; The demo program (StackDemo.java) creates a stack of size 10 and performs push operations: stack.push(3); stack.push(5); stack.push(9); stack.push(1); stack.push(12); stack.push(15); 🔹 Output Element at top of the stack: 15 Elements: 15 12 1 9 5 3 Stack full: false Stack empty: true This clearly demonstrates the LIFO behavior — 15 (last inserted) is removed first. 💡 Mastering Stack is essential for solving problems related to: Expression evaluation Parenthesis checking Backtracking Undo/Redo functionality Recursive algorithms Strong DSA fundamentals = Strong Java developer 🚀 #Java #DSA #Stack #DataStructures #Algorithms #JavaProgramming #CodingInterview #FullStackJava #AshokIT
To view or add a comment, sign in
-
Day 5 1️⃣ Typecasting in Java Typecasting is converting one data type into another. Sounds simple — but it can silently break logic if misunderstood. Two types: ✔ Implicit (Widening Casting) Smaller → Larger data type Handled automatically by Java. Examples: byte → short short → int int → long long → float char → int Important insight: long → float happens implicitly, but precision can be lost. Just because it compiles doesn’t mean it’s safe. That’s a blind spot many beginners miss. ✔ Explicit (Narrowing Casting) Larger → Smaller data type Requires manual instruction from the programmer. Examples: double → float long → int int → byte Here, Java forces you to take responsibility. If data is lost — that’s on you. That distinction matters in real-world applications where financial values, counters, and IDs are involved. 2️⃣ Increment & Decrement Operators Understanding the difference between: Pre-increment (++a) → increments first, then uses the value Post-increment (a++) → uses the value first, then increments Small syntax difference. Big logical impact inside loops and expressions. 3️⃣ Wrapping (Overflow Behavior) For example in byte: Maximum value: 127 If you add 1 → it wraps to -128 #FullStackDeveloper #JavaJourney #AppAcademy #BackendDevelopment #SoftwareEngineering #CodingLife
To view or add a comment, sign in
-
-
🚀 Day 15/30 – Java DSA Challenge 🔎 Problem 68: 232. Implement Queue using Stacks (LeetCode – Easy) Continuing Day 15 with another classic data structure transformation problem — implementing a Queue (FIFO) using only Stacks (LIFO) operations. This problem strengthens: ✅ Understanding of LIFO vs FIFO ✅ Stack manipulation ✅ Reversing order using auxiliary stack ✅ Core data structure fundamentals 🧠 Problem Summary We need to design a queue using only stack operations: push(x) pop() peek() empty() ⚠ Constraint: Only standard stack operations allowed — push, pop, peek, size, isEmpty. 💡 Key Insight Queue → First In First Out (FIFO) Stack → Last In First Out (LIFO) To simulate FIFO using LIFO: 👉 Use two stacks: input stack → for push operations output stack → for pop & peek operations When removing elements: If output stack is empty Transfer all elements from input stack to output stack This reverses order and maintains FIFO 🔄 Approach 1️⃣ Push → Always push into input stack 2️⃣ Pop/Peek → If output stack is empty, transfer elements Then pop/peek from output stack 3️⃣ Empty → Check both stacks ⏱ Complexity Analysis Push: O(1) Pop: Amortized O(1) Peek: Amortized O(1) Space Complexity: O(N) 📌 Concepts Reinforced ✔ Stack behavior ✔ Order reversal technique ✔ Amortized time complexity ✔ Clean data structure design 📈 Learning Reflection Even simple-tagged problems reveal deep structural concepts. Understanding how to simulate one data structure using another builds strong problem-solving foundations — crucial for interviews and system design thinking. ✅ Day 15 Progress Update 🔥 68 Problems Solved in 30 Days DSA Challenge Small daily improvements → Big long-term mastery 🚀 #Day15 #30DaysOfDSA #Java #LeetCode #Stack #Queue #DataStructures #CodingJourney #InterviewPreparation
To view or add a comment, sign in
-
-
Day 2 of #100DaysOfCode — Solved “Valid Parentheses” using Stack Today I solved the Valid Parentheses problem on LeetCode. At first glance it looks simple, but it’s a great problem to understand how the Stack data structure works in real scenarios. 🧩 Problem https://lnkd.in/gy8tkvpf Given a string containing only the characters: ( ) { } [ ] We need to determine whether the parentheses are valid. A string is valid if: 1️⃣ Every opening bracket has a corresponding closing bracket. 2️⃣ Brackets close in the correct order. 3️⃣ Each closing bracket matches the same type of opening bracket. Example: Input: "([])" Output: true But: Input: "([)]" Output: false Because the order of closing brackets is incorrect. 💡 Key Idea When we see an opening bracket, we don’t yet know where it will close. So we store it temporarily. This is exactly what a Stack (LIFO – Last In First Out) is good at. Example for "([])" ( → push [ → push ] → pop [ ) → pop ( If the stack becomes empty at the end → the string is valid. ⚙️ Algorithm 1️⃣ Create an empty stack 2️⃣ Traverse the string character by character 3️⃣ If it’s an opening bracket → push it into the stack 4️⃣ If it’s a closing bracket: check if stack is empty → invalid pop the top element and verify if it matches 5️⃣ After traversal, if stack is empty → valid string 💻 Java Implementation import java.util.Stack; class Solution { public boolean isValid(String s) { Stack<Character> stack = new Stack<>(); for(int i = 0; i < s.length(); i++){ char ch = s.charAt(i); if(ch == '(' || ch == '{' || ch == '['){ stack.push(ch); } else{ if(stack.isEmpty()){ return false; } char top = stack.pop(); if((ch == ')' && top != '(') || (ch == ']' && top != '[') || (ch == '}' && top != '{')){ return false; } } } return stack.isEmpty(); } } ⏱ Complexity Time Complexity → O(n) Space Complexity → O(n) (in worst case when all characters are opening brackets) 📚 What I Learned This problem helped me understand the Stack pattern for matching pairs, which appears frequently in problems like: Balanced Parentheses Expression Evaluation Next Greater Element Monotonic Stack problems Understanding when to use a stack is more important than just memorizing the solution. Excited to continue my #100DaysOfCode journey and strengthen my Data Structures & Algorithms fundamentals. #Java #DSA #LeetCode #Stack #ProblemSolving #CodingJourney #SoftwareEngineering #100DaysOfCode #JavaBackend
To view or add a comment, sign in
-
-
A simple SQL function can aggregate your query results, here is how it works I remember when I was working for a code to bring out the data from the DB, we had a couple of joins that resulted into duplicated rows just varying by one column. So we thought of structuring it in a way like grouping the commons with comma separated values Consider the below as your table structure name | stack ------+--------- JOHN | JAVA ROY | PYTHON JOHN | ANGULAR SAM | SQL You can see the same JOHN has two stacks, what if it is more in number and comes one by one, Our goal is to make it look like name | stack ------+-------------- SAM | SQL ROY | PYTHON JOHN | JAVA,ANGULAR How to do that? SELECT name,string_agg(stack,',') as stack FROM Employee_knowledge group by name ; string_agg is a function that combines different values of a column with the separation parameter based on the group by clause
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
As a Java student, this is exactly the kind of foundation we need before jumping into frameworks. Understanding how data types map to memory makes concepts like performance, overflow, and optimization much clearer. Really helpful breakdown for building strong core Java fundamentals!💻📚