🧩 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
Java Data Types, Type Casting, and Pass by Value/Reference Explained
More Relevant Posts
-
🔹 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
-
-
🚀 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
-
-
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
-
-
🧠 Inside Java’s Map: How It Really Works! Ever wondered what happens under the hood when you put a key-value pair into a Map in Java? 🤔 Let’s peel back the layers and see how the magic happens! ⚙️ 🔍 What is a Map? A Map in Java stores data as key-value pairs — where each key is unique and maps to a specific value. Common implementations include: HashMap LinkedHashMap TreeMap ConcurrentHashMap But the real star of the show is HashMap — the most commonly used one! 🌟 ⚙️ How HashMap Works Internally When you call: map.put("Apple", 10); Here’s what happens step by step 👇 ➡️ Hashing the Key The hashCode() of the key ("Apple") is computed. The hash value is processed (via a hashing algorithm) to find the bucket index in the underlying array. ➡️ Storing in a Bucket Each bucket is a linked list (or tree after Java 8). If no key exists in that bucket, a new Node is created and stored there. ➡️ Handling Collisions If two keys map to the same bucket, they form a linked list (chaining). In Java 8+, if the list grows beyond 8 elements, it’s converted into a balanced Red-Black Tree — improving lookup time from O(n) to O(log n)! ➡️ Retrieval During get(key), Java again computes the hash and goes to the right bucket. It compares keys using equals() to find the exact match. 🧩 Key Methods Used hashCode() → Generates hash for locating the bucket equals() → Ensures uniqueness of keys resize() → Expands the array when load factor (default 0.75) is exceeded 💡 Fun Fact: HashMap’s design balances speed, memory efficiency, and collision handling — a masterpiece of data structure engineering! 📘 In short: HashMap = Array + Linked List + Red-Black Tree + Hashing = ⚡Fast Key-Value Lookup #Java #HashMap #DataStructures #JavaDeveloper #Coding #SoftwareEngineering #Internals #Performance
To view or add a comment, sign in
-
☕ Java Variables, Data Types & Type Conversion — Where Data Finds Its Identity In today’s Java session, I explored how data gets its personality — how it’s stored, labeled, and transformed behind the scenes. Every variable in Java is like giving a name to a piece of memory. The data type decides the size of that space and the kind of value it can hold — a number, a character, or a simple true/false. It’s structure meeting logic. 💡 Primitive Data Types — the core building blocks of Java: Integers: byte, short, int, long → for whole numbers in different ranges. Floating-Point: float, double → for decimal or fractional values. Character: char → holds a single symbol or letter. Boolean: boolean → represents truth values — true or false. 💡 Non-Primitive (Reference) Types — created by developers to manage more complex data. They include classes, arrays, and interfaces — storing references (memory addresses) instead of direct values. Their default value is null. Then comes the magic of Type Conversion — Java’s way of transforming one type into another: ➡️ Widening (Automatic) — Java promotes smaller types to larger ones, like int → double, safely and smoothly. ➡️ Narrowing (Explicit) — When we take control and manually shrink a type: double score = 89.7; int finalScore = (int) score; // returns 89 What stood out to me is how beautifully Java blends safety, precision, and control — ensuring every value knows exactly what it is and where it belongs. 🚀 #Java #LearningJourney #Programming #DataTypes #TypeConversion #Coding #SoftwareDevelopment #DataScience
To view or add a comment, sign in
-
-
☕ 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
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
-
-
⚙️ 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
-
-
🚀 Day 102: Mastered Java Fundamentals — Data Types, String, Arithmetic & Logical Operators Today I focused on strengthening the core of Java — the building blocks that every backend/Java developer must master. 🔹 1. Data Types in Java Java is statically typed, meaning every variable must have a type. ✅ There are 8 primitive data types: TypeSizeExamplebyte1 bytebyte b = 10;short2 bytesshort s = 1000;int4 bytesint age = 21;long8 byteslong views = 100000L;float4 bytesfloat pi = 3.14f;double8 bytesdouble price = 89.99;char2 byteschar grade = 'A';boolean1 bitboolean isActive = true; 👉 Non-primitive types like String, Arrays, Classes store references instead of direct values. 🔹 2. String in Java Strings are not primitive — they are objects from the String class. ✨ Why are they special? Immutable (cannot be changed after creation) Stored in String Constant Pool to improve memory efficiency Thread-safe and used heavily in Java internals Common methods: name.length(); name.toUpperCase(); name.charAt(0); name.contains("Java"); 🔹 3. Arithmetic Operators Basic mathematical operations in Java: OperatorMeaning+Addition-Subtraction*Multiplication/Division%Remainder++ / --Increment / Decrement 🔹 4. Logical Operators Used in conditions and decision-making: OperatorMeaning&&Logical AND (true if both conditions are true)`!NOT (reverses the value) Example: if(age >= 18 && hasLicense) { System.out.println("You can drive!"); } ✅ Mastering these concepts builds a strong foundation for: OOP concepts Collections Exception Handling Spring Boot & Backend development Learning fundamentals pays off later. The deeper your basics → the stronger your code. #Java #Day102 #LearningInPublic #BackendDevelopment #100DaysOfCode #JavaDeveloper #DSA #ProgrammingJourney
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