When we store data in a program, one question naturally comes up: ❓𝐖𝐡𝐚𝐭 𝐤𝐢𝐧𝐝 𝐨𝐟 𝐝𝐚𝐭𝐚 𝐢𝐬 𝐭𝐡𝐢𝐬? In real life, we already treat information differently. • A name is treated as text. • An age is treated as a number. Programming works the same way — Java just needs this difference to be stated clearly. That’s where data types come in. 🛠️𝐃𝐚𝐭𝐚 𝐓𝐲𝐩𝐞𝐬 Data types tell Java what kind of data a variable can store. Java classifies data types into two main categories: 🔹 Primitive Data Types (8 types) Primitive data types are predefined (built-in) in Java, which means Java already knows how to store and handle them. They include: byte, short, int, long, float, double, char, boolean Each primitive type has a fixed size and specific behavior, which helps Java manage memory efficiently. 🔹 Non-Primitive Data Types Non-primitive data types are user-defined or reference types. They are created using primitive data types and are used to store more complex data. Examples include: • String • arrays • classes • objects In simple terms: 🧩 Primitive data types are predefined and store actual values. 🏷️ Non-primitive data types are user-defined and store references to data. By defining a data type, Java knows: 🧠 how much memory to allocate ⚙️ what operations are allowed 🔄 how the value should behave during execution This prevents confusion and unexpected errors while the program runs. That’s why data types matter: they remove ambiguity and keep programs predictable and reliable. 🧩 Variables hold information. 🏷️ Data types tell Java how to handle it. 🤔 𝑰𝒇 𝒗𝒂𝒓𝒊𝒂𝒃𝒍𝒆𝒔 𝒂𝒏𝒅 𝒅𝒂𝒕𝒂 𝒕𝒚𝒑𝒆𝒔 𝒅𝒆𝒇𝒊𝒏𝒆 𝒘𝒉𝒂𝒕 𝒅𝒂𝒕𝒂 𝒂 𝒑𝒓𝒐𝒈𝒓𝒂𝒎 𝒘𝒐𝒓𝒌𝒔 𝒘𝒊𝒕𝒉, 𝒉𝒐𝒘 𝒅𝒐𝒆𝒔 𝒂 𝑱𝒂𝒗𝒂 𝒑𝒓𝒐𝒈𝒓𝒂𝒎 𝒈𝒆𝒕 𝒕𝒉𝒂𝒕 𝒅𝒂𝒕𝒂 𝒇𝒓𝒐𝒎 𝒕𝒉𝒆 𝒖𝒔𝒆𝒓? 💬 If you know the answer, feel free to share your thoughts in the comments. Here’s a small Java program demonstrating different data types in action... #Java #CoreJava #JavaBasics #LearningJourney #Programming #BuildInPublic
Java Data Types: Primitive vs Non-Primitive
More Relevant Posts
-
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
To view or add a comment, sign in
-
-
🚀 Core Java – Day 6 📌 Topic: Data Types (Primitive Data Types) Today, I learned about Data Types in Core Java. 👉 Meaning: Data types help convert real-world data into binary format (0s and 1s) so that a computer can store and understand it. 💡 Real-world data cannot be stored directly because it is not in binary form, and computers understand only binary values. 🗂️ Real-world data can be categorized into 7 types: 1️⃣ Integer data 2️⃣ Real number data 3️⃣ Character data 4️⃣ Yes/No data 5️⃣ Audio 6️⃣ Video 7️⃣ Still pictures (Images) 📌 Java Data Types are categorized into two types: 1️⃣ Primitive Data Types 2️⃣ Non-Primitive Data Types 🔹 Primitive Data Types a) Integer Type Data Stores whole numbers (positive, negative, and zero) without decimals 📌 Example: Age of a person byte → 1 byte (8 bits), range: -128 to 127 short → 2 bytes (16 bits), range: -32,768 to 32,767 int → 4 bytes (32 bits), range: -2,147,483,648 to 2,147,483,647 long → 8 bytes (64 bits), range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 📝 Note: Use L suffix for long values. b) Real Number Type Data Stores numbers with decimal values float → 4 bytes (example: 13.4f) double → 8 bytes (example: 9.34324) c) Character Type Data Stores a single character such as letters, digits, or symbols char → 2 bytes d) Boolean Type Data Stores true/false or yes/no values boolean → Size depends on JVM Commonly used in conditions and logical operations ✨ Understanding data types is essential for building a strong Java foundation. #CoreJava #Day6 #JavaBasics #LearningJourney #Programming
To view or add a comment, sign in
-
-
Completed Primitive Data Types and Type Casting today. I used to think data types were just sizes and keywords. Turns out they decide how data is stored, interpreted, and sometimes lost. A few things that finally made sense today: – the same number can mean different things in decimal, binary, octal, and hexadecimal – real numbers aren’t stored exactly the way we write them – float and double don’t just differ in size, they differ in behavior – implicit casting feels convenient until it silently changes values – explicit casting exists because Java doesn’t trust assumptions – char looks simple but is actually numeric underneath – Java uses Unicode, not ASCII, for a reason – boolean is simple, but Java is strict about how it’s used Big takeaway for me : Just because code compiles doesn’t mean it’s correct. Still learning. Still unlearning things I took for granted.Continuing tomorrow. #Java #LearningInPublic #Beginner #DSA
To view or add a comment, sign in
-
🚀 Day 8 – Core Java | Data Types from Memory Perspective Today’s session completely changed the way I look at data types. Instead of memorizing int, float, long, we understood why data types exist. 🔑 Key Learnings: ✔ RAM is a collection of bytes ✔ Bytes → Bits → Transistors ✔ Transistors understand only 0 & 1 ✔ Real-world data must be converted into binary before storage 💡 Big insight: Data types are not “types of data” Data types are converters that transform real-world data into 0s and 1s ✔ Understood primitive data types: Integer: byte, short, int, long Real numbers: float, double char, boolean ✔ Learned why multiple integer data types exist → Memory efficiency matters → Small choices scale massively in real applications ✔ Practical understanding of: Memory allocation Data ranges Why correct data type selection matters in industry 🎯 Interview takeaway: Don’t give textbook answers. Explain concepts from memory & system perspective. This session laid the foundation for thinking like a real developer, not just writing code 🚀 #CoreJava #DataTypes #MemoryManagement #JavaFundamentals #DeveloperMindset #LearningJourney
To view or add a comment, sign in
-
𝗝𝗮𝗩𝗔 𝗗𝗮𝗧𝗮 𝗧𝗬𝗽𝗲𝗦 You work with data in Java. Your data can be one of two types: - Primitive Data Types - Non-Primitive Data Types Primitive Data Types have eight types: • byte: stores small integers from -128 to• short: stores integers from -32,768 to 32,767 • int: stores whole numbers within 32-bit range • long: stores very large whole numbers • float: stores decimal numbers with single precision • double: stores decimal numbers with double precision • char: stores a single Unicode character • boolean: stores only true or false Non-Primitive Data Types include: • String: stores a sequence of characters as an object • Array: stores multiple values of the same type • Class: blueprint used to create objects • Object: instance of a class stored in heap memory • Interface: defines method declarations without implementation • Enum: stores a fixed set of named constants Source: https://lnkd.in/dmaU9ZNz
To view or add a comment, sign in
-
💡 Trick to memorize groupingBy() in Java Lambdas Think of groupingBy just like SQL GROUP BY 👇 Collectors.groupingBy(KEY, VALUE) KEY → How you want to group Employee::getDepartment VALUE → What you want inside each group (list, count, sum, avg, nested group, custom logic, order, post-processing) 🔹 Common VALUE patterns you should remember • Store a specific field Collectors.mapping(Employee::getName, Collectors.toList()) • Count records per group Collectors.counting() • Sum numeric field Collectors.summingDouble(field) • Average numeric field Collectors.averagingDouble(field) • Nested grouping Collectors.groupingBy(key, value) • Custom grouping logic emp -> condition ? "A" : "B" • Preserve order Collectors.groupingBy(field, LinkedHashMap::new, Collectors.toList()) • Post-process result (e.g. sort) Collectors.groupingBy( field, Collectors.collectingAndThen(storage, action) ) 🧠 How to think about it 👉 Ask the same questions you ask in SQL: What is my GROUP BY column? What do I want in the SELECT clause? Do I need COUNT / SUM / AVG / ORDER BY? If you can answer these, groupingBy() becomes natural. Keep practicing — streams click only after repetition 💪
To view or add a comment, sign in
-
Pass by Value and Pass by Reference Understanding how data is passed to functions is important for writing correct and predictable code. Pass by Value: In pass by value, a copy of the variable is passed to the function. Any changes made inside the function do not affect the original variable. Example: public class Main { static void changeValue(int x) { x = 20; } public static void main(String[] args) { int a = 10; changeValue(a); System.out.println(a); } } Output will be 10 because only a copy of the value is modified. Pass by Reference: In pass by reference, the reference (address) of the variable is passed, so changes inside the function affect the original object. In Java, objects are passed by value of reference. Example: class Data { int value; } public class Main { static void changeObject(Data d) { d.value = 20; } public static void main(String[] args) { Data obj = new Data(); obj.value = 10; changeObject(obj); System.out.println(obj.value); } } Key takeaway: Java is strictly pass by value. For objects, the value being passed is the reference, which allows object data to be modified. Understanding this concept is crucial for avoiding unexpected bugs in Java programs. #Java #PassByValue #PassByReference #ProgrammingBasics #DSA #SoftwareEngineering
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
-
🚀 EagerORM — a Java ORM with explicit, predictable data access I’m sharing EagerORM, a graduation thesis project where I explored ORM internals, SQL generation, and API design - without hidden loading or proxy magic! All relationships are loaded explicitly via joins, so you always know what SQL gets executed. The first version is already published and can be found on Maven Central! 📌 Repository: https://lnkd.in/dZpwyKNb You’ll find: - Annotation-based entity & relationship mapping - Fluent SQL query builder (joins, conditions, grouping, ordering, subqueries) - CRUD, upsert, raw SQL, and PDO projections - Transaction & connection scoping - Dialect-aware SQL generation I plan to keep improving it and would really appreciate any feedback or suggestions. #java #opensource #backend #orm #sideproject #softwareengineering #learningbydoing
To view or add a comment, sign in
-
Java + DataFrames = Underrated Power Combo When people hear DataFrames, they instantly think of Python (Pandas) or R. But honestly… Java DataFrames deserve way more attention. If you're working in Java and dealing with datasets, analytics, or ETL pipelines, DataFrame-style libraries can make your life so much easier. Instead of writing endless loops and messy object mapping, you can do things like: ✅ Filter rows ✅ Group & aggregate ✅ Transform columns ✅ Clean missing values ✅ Load/export CSV, JSON, SQL Libraries worth exploring in the Java ecosystem: 🔹 Tablesaw – simple, fast, beginner-friendly 🔹 Apache Spark (Dataset API) – for big data and distributed processing 🔹 Apache Flink Table API – strong for streaming + batch 🔹 Joinery – Pandas-like style for Java developers What I like about this approach is that it brings cleaner code, faster analysis, and a more structured way to handle data… without leaving Java. The best part? Java DataFrames can fit perfectly into enterprise systems where Java is already the backbone. 📌 If you're a Java developer working with data, this is definitely worth adding to your toolkit. #Java #DataScience #BigData #SoftwareEngineering #Programming #DataAnalytics #ApacheSpark #MachineLearning #ETL #BackendDevelopment #Coding #Tech #Developer #Flink #Tablesaw #CleanCode #Analytics #DataEngineering
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
Java takes user input using the Scanner class.(•‿•)