✨ Today’s Class Update – Java Typecasting & Variables ✨ Today’s session was focused on understanding Typecasting and Variables in Java, which are core concepts for building a strong programming foundation. 🔹 Typecasting is the process of converting one data type into another. It is classified into: Implicit Typecasting (Widening) – Converting a smaller data type into a larger data type. This conversion is done automatically by the Java compiler. Explicit Typecasting (Narrowing) – Converting a larger data type into a smaller data type. This is not done automatically and must be performed manually by the programmer. 🔹 We also learned about Variables, which act as containers to store data. Variables are classified into: Instance Variables – Created inside a class and stored in the heap memory. JVM provides default values for these variables. Local Variables – Created inside a method and stored in the stack memory. 🔹 The session also covered Java Memory Management, where RAM is shared memory and divided into four segments: Code Segment Static Segment Heap Segment Stack Segment High-level Java code is first converted into bytecode by the compiler, and then the JVM converts it into machine code. 🔹 Finally, we discussed Pass by Value and Pass by Reference: Pass by Value – A copy of the variable’s value is passed to the method, so changes inside the method do not affect the original variable. Pass by Reference – The address of the variable is passed, and multiple reference variables can point to the same object. Overall, it was a very informative class that helped me understand how Java handles data, memory, and method calls more clearly 🚀 #Java #Typecasting #CoreJava #Variables #MemoryManagement #LearningJourney #TapAcademy #Programming
Java Typecasting & Variables: Core Concepts
More Relevant Posts
-
🛑 A Quick Java Memory Guide Understanding the Java Memory Model is non-negotiable for writing performant, bug-free code. If you don’t know where your data lives, you don’t really know Java. Here is the breakdown of Stack vs Heap: 🧠 The Stack (LIFO - Last In, First Out) · What lives here: Primitive values (int, double) and references to objects (pointers). · Scope: Each thread has its own private stack. Variables exist only as long as their method is running. · Access Speed: Very fast. · Management: Automatically freed when methods finish. 🗄️ The Heap (The Common Storage) · What lives here: The actual objects themselves (all instances of classes). · Scope: Shared across the entire application. · Access Speed: Slower than the stack due to global access. · Management: Managed by the Garbage Collector (GC). 💡 The Golden Rule: The reference is on the Stack, but the object it points to is on the Heap. Map<String, String> myMap = new HashMap<>(); (Stack: myMap) --> (Heap: HashMap object) 👇 Q1: If I declare int id = 5; inside a method, where is this value stored? A1: Stack. It's a local primitive variable, so it lives directly in the stack frame. Q2: I created an array: int[] data = new int[100];. The array holds primitives. Is the data stored on the Stack or Heap? A2: Heap. The array itself is an object in Java. The reference data lives on the Stack, but the 100 integers are stored contiguously on the Heap. Q3: What happens to memory if I pass this object reference to another method? A3: A copy of the reference is passed (passed by value). Both methods now have a pointer (on their respective stacks) to the same single object on the Heap. ♻️ Repost if you found this helpful! Follow me for more Java wisdom. #Java #Programming #SoftwareEngineering #MemoryManagement #Coding
To view or add a comment, sign in
-
🚀 Understanding Arrays in Java – Strengths & Drawbacks 📍Arrays are one of the most fundamental data structures in Java. They allow us to store multiple values under a single variable name, making code cleaner and more efficient. But like every tool, arrays come with limitations that every developer should know. 🔑 Key Points: 📌Homogeneous Data Only: Arrays can store only one type of data (e.g., all integers, all strings). 📌Fixed Size: Once declared, the size of an array cannot be changed. Adding or removing elements dynamically isn’t possible. 📌Contiguous Memory Requirement: Arrays need continuous memory blocks. If RAM cannot allocate enough contiguous space, array creation may fail. 📌 Real-Time Example: Imagine you’re building an online shopping cart system. If you use an array to store items, you must decide the cart size in advance (say 10 items). What if a customer wants to add the 11th item? ❌ The array won’t allow it. Also, you can’t mix data types (e.g., product name + price + quantity) in a single array. 👉 That’s why developers often prefer ArrayLists or Collections in Java, which overcome these limitations by allowing dynamic resizing and heterogeneous data storage. 💡 Takeaway: Arrays are great for fixed-size, homogeneous data storage, but for real-world applications where flexibility is key, Collections are the way forward. TAP Academy #Java #CoreJava #ProgrammingBasics #JavaDeveloper #LearningJourney #SoftwareDevelopment #Coding
To view or add a comment, sign in
-
🚀 Day 13— Restarting My Java Journey with Consistency Today's Learnings: 🔹 Instance Variables & Instance Methods These belong to objects and are accessed using the object reference. They help define the state and behavior of objects. 🔹 Local Variables Local variables do not get default values in Java. They must be initialized before use, otherwise the compiler throws an error. 🔹 Constructors in Java Constructors are special methods used to initialize objects at the time of creation. No return type Same name as class Example: Student s1 = new Student(); When an object is created, the constructor is automatically invoked to initialize the object. Types of constructors : • Default Constructor – No parameters • Parameterized Constructor – Accepts values to initialize object fields Important rule: If a programmer defines any constructor, Java does not create a default constructor automatically. 🔹 this Keyword this refers to the current object. It is commonly used to distinguish instance variables from local variables. 🔹 Constructor Overloading A class can have multiple constructors with different parameter lists to initialize objects in different ways. 🔹 Constructor Chaining Using this() we can call one constructor from another constructor within the same class. Important rule: The this() call must be the first statement inside a constructor. Interview Specific: 🔹 Can We Call a Constructor Manually? No. Constructors cannot be called like normal methods. They are automatically invoked when an object is created using the new keyword. 🔹 Interesting Runtime Insight When we create an object using new, Java allocates memory in the heap at runtime. But what if heap does not have enough free space, then Java will throw a runtime exception. Learning daily with Coder Army and Aditya Tandon Bhaiya and Rohit Negi Bhaiya #Day13 #Java #Consistency #BackendDevelopment #LearningJourney #SoftwareEngineering #CoderArmy
To view or add a comment, sign in
-
-
🚀 Day 1 of My Java Journey Today, I started learning the fundamentals of Java and understood some very important basic concepts. 🔹What is Java? It is a programming language is used to create an application. 🔹What is a Program? It is just an instruction which is used to create an application. For example: WhatsApp 1.____________________ ->program / instruction / code 2.____________________ ->program / instruction / code 3.____________________ ->program / instruction / code 4. ____________________ ->program / instruction / code 5.____________________ ->program / instruction / code 🔹What is a Programming Language? • A language which is used to write a program is called as programming language. • We are having programming languages such as Java, Python, C, C#, Ruby, Pearl, R etc.. 🔹What is an Application? It is a collection of programs is called as application. For example: FaceBook 1.____________________ ->program / instruction / code 2.____________________ ->program / instruction / code 3.____________________ ->program / instruction / code 4. ____________________ ->program / instruction / code 5.____________________ ->program / instruction / code 🔹Types Of Application: • Standalone Application • Web Application • Client-Server Application Grateful for the clear guidance and support from my trainer Syed Tabrez at Qsipders Vadapalani. #Day1 #Java #ProgrammingLanguage #Application #LearningJourney #SoftwareDeveloper #AspiringSoftwareDeveloper #QspidersVadapalani
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
-
-
Java Compiled Or Interpreted. Is Java a compiled or interpreted language? The standard picture of Java is of a language that’s compiled into .class files before being run on a JVM. Lot of developers can also explain that bytecode starts off by being interpreted by the JVM but will undergo just-in-time (JIT) compilation at some later point. Here, however, many people’s understanding breaks down into a somewhat hazy conception of bytecode as basically being machine code for an imaginary or simplified CPU. In fact, JVM bytecode is more like a halfway house between human-readable source and machine code. In the technical terms of compiler theory, bytecode is really a form of intermediate language (IL) rather than actual machine code. This means that the process of turning Java source into bytecode isn’t really compilation in the sense that a C++ or a Go programmer would understand it, And javac isn’t a compiler in the same sense as gcc is — it’s really a class file generator for Java source code. The real compiler in the Java ecosystem is the JIT compiler. Some people describe the Java system as “dynamically compiled.” This emphasizes that the compilation that matters is the JIT compilation at runtime, not the creation of the class file during the build process. So, the real answer to “Is Java compiled or interpreted?” is “both.” I’m building a complete Senior Java Interview Guide. If this helps you, you can support the series here #Java #JavaStreams #SoftwareEngineering #Programming #CleanCode #Interviews #interviewGuide
To view or add a comment, sign in
-
-
🔍 Deep Dive: Internals of HashMap in Java HashMap is one of the most widely used data structures in Java, but have you ever wondered how it works under the hood? Let’s break it down. 🧩 Core Structure - Internally, a HashMap is backed by an array of buckets. - Each bucket stores entries as Nodes (key, value, hash, next). - Before Java 8: collisions were handled using linked lists. - From Java 8 onwards: if collisions in a bucket exceed a threshold (default 8), the list is converted into a balanced Red-Black Tree for faster lookups. ⚙️ Hashing & Indexing - When you insert a key-value pair, the hashCode() of the key is computed. - This ensures uniform distribution of keys across buckets. 🚀 Performance - Average time complexity for put() and get() is O(1), assuming a good hash function. - Worst case (all keys collide into one bucket): - Before Java 8 → O(n) due to linked list traversal. - After Java 8 → O(log n) thanks to tree-based buckets. 🛠️ Key Design Choices - Load Factor (default 0.75): controls when the HashMap resizes. - Rehashing: when capacity × load factor is exceeded, the array doubles in size and entries are redistributed. - Null Handling: HashMap allows one null key and multiple null values. 💡 Takeaway HashMap is a brilliant example of balancing speed, memory efficiency, and collision handling. Its evolution from linked lists to trees highlights how Java adapts to real-world performance needs. What’s your favorite use case of HashMap in production systems? #Java #Collections #ScalableSystems
To view or add a comment, sign in
-
🚀 Checking Anagrams Using Java Streams Most developers are familiar with the classic Anagram problem in programming. Two strings are called anagrams if they contain the same characters with the same frequency, but possibly in a different order. Example: String input1="earth"; String input2="heart"; Instead of using the usual character counting or sorting with arrays, I tried solving this using Java Streams. 🔎 Approach 1. Convert both strings to lowercase to ignore case differences. 2. Convert each string to a stream of characters using chars(). 3. Sort the characters using sorted(). 4. Convert each character to a String using mapToObj. 5. Join them back into a sorted string. 6. Compare the final sorted strings. 7. If both sorted strings are equal, the strings are anagrams. ⚙️ Key Stream Methods Used i. chars() - Converts the string to an IntStream of characters ii. sorted() - Sorts the characters iii. mapToObj() - Converts each character to String iv. Collectors.joining() - Combines them back into a string This approach shows how Java Streams can make data transformations concise and expressive. 💻 I’ve added my Java solution in the comments below. Please let me know if there are any other approaches I could try. #Java #JavaStreams #DSA #Coding #ProblemSolving #Developers #Programming #Anagrams
To view or add a comment, sign in
-
-
Day 22 – Reference Variables in Java Today I explored an important concept in Object-Oriented Programming — Reference Variables. Unlike primitive variables, reference variables store the address of an object, not the actual value. 🔹 What is a Reference Variable? A reference variable is a non-primitive variable that refers to an object created from a class. It is declared using the class name. Syntax: ClassName referenceVariable; Initialization- referenceVariable = new ClassName(); Or both together: ClassName referenceVariable = new ClassName(); Here: ClassName → Name of the class referenceVariable → Object reference new → Keyword used to create an object ClassName() → Constructor 🔹 Example class Demo5 { int x = 100; int y = 200; } class MainClass3 { public static void main(String[] args) { Demo5 d1 = new Demo5(); System.out.println("x = " + d1.x); System.out.println("y = " + d1.y); System.out.println("modifying x & y"); d1.x = 300; d1.y = 400; System.out.println("x = " + d1.x); System.out.println("y = " + d1.y); } } Output: x = 100 y = 200 modifying x & y x = 300 y = 400 🔹 Important Observation When we write: Demo5 d1 = new Demo5(); Java performs three things: 1️⃣ Creates a reference variable (d1) 2️⃣ Creates a new object in memory 3️⃣ Stores the object reference in the variable #Java #CoreJava #JavaFullStack #OOP #Programming #BackendDevelopment #LearningInPublic #SoftwareDevelopment
To view or add a comment, sign in
-
-
#Post1 Internal working of HashMap And Hash collision 👇 When we insert a value: map.put("Apple", 10) Java performs these steps: 1️⃣ It calls hashCode() on the key. For example, Strings generate hash codes using a formula involving the prime number 31. 2️⃣ Using this hash, Java calculates the bucket index inside the internal array. Now the entry is stored inside that bucket. Example internal structure: Bucket Array [0] [1] [2] → (Apple,10) [3] [4] But what if two keys map to the same bucket? This situation is called a hash collision. Example: [2] → (Apple,10) → (Banana,20) → (Mango,30) HashMap handles collisions by storing multiple entries inside the same bucket. Before Java 8 • Entries were stored in a Linked List After Java 8 • If the bucket size grows beyond 8, the linked list is converted into a Red-Black Tree This improves search performance: O(n) → O(log n) Now let’s see what happens during get() when a bucket has multiple entries. When we call: map.get("Apple") Java performs these steps: 1️⃣ It recomputes the hashCode() of the key 2️⃣ It finds the same bucket index using (capacity - 1) & hash 3️⃣ If multiple nodes exist in that bucket, Java traverses the nodes For each node it checks: existingNode.hash == hash AND existingNode.key.equals(key) Once the correct key is found, the corresponding value is returned. Summary: Two different keys can generate the same hash, which causes a hash collision. HashMap handles collisions by storing entries as a Linked List or Red-Black Tree inside the bucket. 📌 Note HashMap is not thread safe. In the upcoming post, we will explore the thread-safe alternative to HashMap. #Java #SoftwareEngineering #BackendDevelopment #DataStructures #Programming #LearnInPublic
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