☕ Day 9 of my “Java from Scratch” Series – “Data Types in Java” In Java, we should tell the compiler what type of data we want to store. There are 2 main types of Data Types 👇 🔹 1️⃣ Primitive Data Types These are the basic data types — the foundation of Java. There are 8 primitive data types: 1. byte - 1 byte (1 byte = 8bits) 2. short - 2 bytes 3. int - 4 bytes 4. long - 8 bytes 5. float - 4 bytes 6. double - 8 bytes 7. char - 2 bytes 8. boolean - 1 bit 💡 In Java, everything is a class except these 8 data types. 🔹 2️⃣ Non-Primitive Data Types These are user-defined data types, and they are classes. ✅ Examples: String, Array The size of a String depends on the number of characters in it. Example: String name = "Java"; 👉 Number of characters = 4 👉 Size of each character = 2 bytes ✅ Total = 8 bytes + overhead (20–30 bytes depending on the system) 💡 Key takeaway: ➡️ Primitive data types ❌ are not classes. ➡️ Non-primitive data types ✅ are classes. 👉 Which data type do you use most often in your projects? Let me know in the comments 👇 #Java #Programming #Coding #Learning #SoftwareEngineering #JavaDeveloper #DataTypes #JavaFromScratch #InterviewQuestions #DataTypesInJava #Tech #JavaInterviewTopics #NeverGiveUp
"Exploring Data Types in Java: Primitive and Non-Primitive"
More Relevant Posts
-
Grasping the essentials! Arrays are the backbone of many Java applications. I’ve been focusing on their fixed-size nature and how zero-based indexing allows for lightning-fast data access. A strong foundation in arrays and their dimensionality is key to optimizing code. Excited to put this knowledge into practice! 💡 ➡️ In Java, an Array is a fundamental data structure used to store a fixed-size, sequential collection of elements of the same data type. Think of an array as a perfectly organized row of mailboxes . Each mailbox holds one piece of data, and you access it instantly using its unique, numbered position, which is called the index (starting from 0). Key properties: Fixed Size: Its length is set at creation and cannot change. Homogeneous: All elements must be of the same type (e.g., all int or all String). Zero-Indexed: Accessing elements is done using an index starting at 0. Types of Arrays Arrays are categorized by the number of indices needed to access an element: 1. Single-Dimensional Arrays (1D Arrays) Structure: A simple list or linear arrangement of data. Access: Requires only one index to pinpoint an element. Example: Storing a list of test scores: int[] scores = {90, 85, 95}; 2. Multi-Dimensional Arrays These are arrays whose elements are themselves arrays, allowing for complex, grid-like structures. ✅ Two-Dimensional (2D) Arrays: ▪️ Structure: Represents data in rows and columns (like a spreadsheet or a matrix). ▪️ Access: Requires two indices ([row][column]) to access an element. ▪️ Example: Modeling a game board or a coordinate grid. ✅ Jagged Arrays: ▪️ Structure: A type of multi-dimensional array where the length of each row can be different. This is useful when data doesn't naturally fit into a perfect rectangle. #SoftwareDevelopment #JavaDeveloper #TechSkills #Learning #JavaArrays #ZeroIndexing #MemoryManagement #DataStructures #TapAcademy #Coding #Techskills
To view or add a comment, sign in
-
-
🔹 Variables in Java : A variable is a container that holds data which can be changed during program execution. Types of variables : 1) Local variable 2) Static variable 3) Instance variable Syntax: datatype variableName = value; Example : int age = 20; String name = "Guru"; double salary = 45000.50; 👉 Rules for variables: - Must start with a letter, $, or _ (not a digit). - Cannot use keywords (like class, int). - Java is case-sensitive (Age and age are different). 🔹 Data Types in Java : Java is a statically-typed language, so each variable must have a data type. 1. Primitive Data Types (8 types) : 👉 Data Type and Size : byte = 1 byte short = 2 byte int = 4 byte long = 8 byte float = 4 byte double = 8 byte char = 2 byte boolean = 1 bit 2. Non-Primitive Data Types : - String → "Hello Java" - Arrays → int[] arr = {1,2,3}; - Classes & Objects 🔹 Operators in Java : Operators are special symbols that perform operations on variables and values. 1. Arithmetic Operators : + Addition - Subtraction * Multiplication / Division % Modulus (remainder) 2. Relational (Comparison) Operators : == Equal to != Not equal to > Greater than < Less than >= Greater than or equal <= Less than or equal 3. Logical Operators : && Logical AND || Logical OR ! Logical NOT 4. Assignment Operators : = Assign += Add and assign -= Subtract and assign *= Multiply and assign /= Divide and assign %= Modulus and asshshift 5. Unary Operators : ++ Increment -- Decrement + Positive - Negative ! Logical NOT 6. Conditional (Ternary) Operator : variable = (condition) ? value_if_true : value_if_false; 7. Bitwise Operators : & AND | OR ^ XOR ~ NOT << Left shift >> Right shift >>> Unsigned right shift #Corejava #Java #learningjava #Programming #Coding #Fortunecloud #Cravita
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
-
-
☀️ 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
-
-
Decoding Data: A Simple Guide to Java Data Types 📊 Understanding data types is foundational for writing effective and efficient Java code. They tell the compiler what kind of values a variable can hold and what operations can be performed on it. In Java, data types are broadly categorized into two groups: Primitive and Non-Primitive (Reference) types. Let's break them down! 1. Primitive Data Types (The Building Blocks) These are the most basic data types, directly supported by the language. They hold simple values and are always stored in memory where the variable is declared (on the stack). Numbers: byte, short, int, long: For whole numbers (integers) of increasing size. (int is the most commonly used!) float, double: For numbers with decimal points (floating-point numbers). (double is generally preferred for precision.) Characters: char: For single characters, like 'A', 'b', or '5'. Booleans: boolean: For true or false values. Essential for logic and control flow! 2. Non-Primitive Data Types (The References / Objects) Also known as "Reference Types," these are more complex. They don't store the actual values directly but rather references (memory addresses) to objects that store the data. They are created by the programmer or defined by Java. String: A sequence of characters (e.g., "Hello, World!"). While it looks like a primitive, String is actually a class in Java and thus a non-primitive type. Arrays: A collection of values of the same data type (e.g., int[] numbers = {1, 2, 3};). Classes & Interfaces: These are custom data types you define yourself (e.g., Car, Employee). They allow you to create complex objects that encapsulate data and behavior. Why does this matter? Choosing the right data type helps optimize memory usage, prevent errors, and ensures your program behaves as expected. For instance, using an int for an age makes more sense than a double. What data type do you find yourself using most often? Share your thoughts! #Java #Programming #DataTypes #SoftwareDevelopment #TechBasics #CodingTips #Developers
To view or add a comment, sign in
-
-
📌Understanding Java Arrays — The Foundation of Data Handling Today, I revised the fundamentals of Java Arrays, one of the most essential concepts in Java programming and interviews. 🔹 What is an Array in Java? A Java array is a fixed-size, indexed data structure used to store multiple values of the same data type. Arrays are stored in continuous memory locations and allow fast (O(1)) element access. ➜ Example: int[] marks = new int[10]; char[] letters = new char[15]; String[] names = new String[20]; 🔹 Array Structure Arrays use zero-based indexing Each element is stored at a specific index Accessing elements is extremely fast ➜Example: int[] arr = {21, 15, 37, 53, 17}; Memory view: Index: 0 1 2 3 4 Values: 21 15 37 53 17 🔹 Array Declaration (Two Ways) int[] arr; int arr[]; 🔹 Types of Arrays in Java ✔ 1. One-Dimensional Arrays Ideal for simple linear data: int[] scores = {10, 20, 30}; ✔ 2. Multidimensional Arrays Arrays inside arrays → used for matrices, tables, grids. 2D Array: int[][] matrix = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }; 3D Array: Used in simulations, 3D structures, games: int[][][] cube = new int[3][3][3]; ✔ 3. Jagged Arrays (Irregular Arrays) Rows can have different lengths. int[][] jagged = { {1, 2}, {3, 4, 5}, {6, 7, 8, 9} }; 🔹 Why Arrays Matter? Foundation for Data Structures (Lists, Maps, Matrices) Faster access compared to collections Used in interviews for logic & memory questions Understanding arrays is the first step toward mastering Java data structures. #Java #Programming #Arrays #DSA #BackendDevelopment #LearningInPublic #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