🚀 Java Series – Day 17 📌 File Handling in Java (I/O) 🔹 What is it? File handling in Java allows us to read from and write to files using input and output streams. 🔹 Why do we use it? It helps in storing and retrieving data from external sources like text files, logs, or configuration files. For example: In a real-world application, we use file handling to store user data, logs, or system configurations. 🔹 Example: import java.io.*; public class Main { public static void main(String[] args) { try { BufferedReader reader = new BufferedReader(new FileReader("test.txt")); String data = reader.readLine(); System.out.println("Read: " + data); reader.close(); } catch (IOException e) { System.out.println(e.getMessage()); } } } 💡 Key Takeaway: File handling is essential for data persistence and real-world application development. What do you think about this? 👇 #Java #JavaIO #FileHandling #JavaDeveloper #Programming #BackendDevelopment
Java File Handling Basics
More Relevant Posts
-
Day 8/100 — Mastering Strings in Java 🔤 Today I explored one of the most important topics in Core Java: Strings. Every Java developer should clearly understand these three concepts: 1️⃣ Immutability In Java, a String object cannot be changed after it is created. Any modification actually creates a new object in memory. 2️⃣ String Pool Java optimizes memory using the String Pool. When we create strings using literals, Java stores them in a special memory area and reuses them. 3️⃣ equals() vs == • equals() → compares the actual content of two strings • == → compares memory references (whether both variables point to the same object) 💻 Challenge I practiced today: Reverse a String using charAt() method. Example logic: String str = "Java"; String reversed = ""; for (int i = str.length() - 1; i >= 0; i--) { reversed += str.charAt(i); } System.out.println(reversed); Small concepts like these build strong Java fundamentals. Consistency is key in this 100 Days of Code journey 🚀 #Java #CoreJava #JavaLearning #Strings #Programming #DeveloperJourney #100DaysOfCode
To view or add a comment, sign in
-
-
TOPIC: Serialization and Deserialization in Java: 🔶 Serialization (Left Side) Converting a Java object into a byte stream (sequence of bytes) 👉 What happens: You start with a Java Object (like a class instance with data). Using classes like ObjectOutputStream, Java converts that object into binary data (0s and 1s). This data is stored in a file or sent over a network. 👉 Why we use it: Save object state into a file (persistence) Send objects over network (like in distributed systems) 👉 In short: ➡️ Object → Byte Stream 🔷 Deserialization (Right Side) Converting byte stream back into a Java object 👉 What happens: You take the serialized data (binary file). Using ObjectInputStream, Java reconstructs it back into the original object. 👉 Why we use it: Read saved data from file Receive objects from network 👉 In short: ➡️ Byte Stream → Object 🔁 Middle Flow (Connection) The arrows show that: Serialization sends data out Deserialization brings it back 💡 Simple Real-Life Example Serialization = Packing your items into a box 📦 Deserialization = Unpacking the box back into usable items 🎁 ⚠️ Important Points Class must implement Serializable interface ObjectOutputStream → for serialization ObjectInputStream → for deserialization If a class is not serializable → NotSerializableException occurs #java #Codegnan #Serialization #DeSerialization My gratitude towards my mentor #AnandKumarBuddarapu #SakethKallepu #UppugundlaSairam
To view or add a comment, sign in
-
-
what is array in Java ?? An array in Java is a container that holds a fixed number of values of the same data type. It helps store and manage multiple values using a single variable. 💡 Why Arrays Matter Efficient way to store multiple values Easy access using index positions Foundation for many advanced data structures like lists, stacks, and queues 📍 Simple Example in Java Java public class ArrayExample { public static void main(String[] args) { int[] numbers = {10, 20, 30, 40, 50}; for(int i = 0; i < numbers.length; i++) { System.out.println(numbers[i]); } } } 🔎 Key Points to Remember ✔ Array index starts from 0 ✔ Array size is fixed after creation ✔ All elements must be of the same data type
To view or add a comment, sign in
-
. Understanding ForkJoinPool in Java (Simple Concept) When working with large datasets or CPU-intensive tasks in Java, processing everything in a single thread can be slow. This is where ForkJoinPool becomes very useful. ForkJoinPool is a special thread pool introduced in Java 7 that helps execute tasks in parallel using the Divide and Conquer approach. The idea is simple: • Fork – Break a big task into smaller subtasks • Execute – Run these subtasks in parallel threads • Join – Combine the results of all subtasks into the final result One of the most powerful features of ForkJoinPool is the Work-Stealing Algorithm. If a thread finishes its task early and becomes idle, it can steal tasks from other busy threads. This keeps the CPU efficiently utilized and improves performance. Common Use Cases • Parallel data processing • Large array computations • Sorting algorithms (like Merge Sort) • Parallel streams in Java • CPU-intensive calculations Important Classes • ForkJoinPool – Manages worker threads • RecursiveTask – Used when a task returns a result • RecursiveAction – Used when a task does not return a result In fact, when we use Java Parallel Streams, internally Java often uses ForkJoinPool to process tasks in parallel. Understanding ForkJoinPool is very helpful for writing high-performance multithreaded applications in Java. #Java #ForkJoinPool #Multithreading #JavaConcurrency #BackendDevelopment #JavaDeveloper #SoftwareEngineering
To view or add a comment, sign in
-
♻️ Ever wondered how Java manages memory automatically? Java uses Garbage Collection (GC) to clean up unused objects — so developers don’t have to manually manage memory. Here’s the core idea in simple terms 👇 🧠 Java works on reachability It starts from GC Roots: • Variables in use • Static data • Running threads Then checks: ✅ Reachable → stays in memory ❌ Not reachable → gets removed 💡 Even objects referencing each other can be cleaned if nothing is using them. 🔍 Different types of Garbage Collectors in Java: 1️⃣ Serial GC • Single-threaded • Best for small applications 2️⃣ Parallel GC • Uses multiple threads • Focuses on high throughput 3️⃣ CMS (Concurrent Mark Sweep) • Runs alongside application • Reduces pause time (now deprecated) 4️⃣ G1 (Garbage First) • Splits heap into regions • Balanced performance + low pause time 5️⃣ ZGC • Ultra-low latency GC • Designed for large-scale applications ⚠️ One important thing: If an object is still referenced (even accidentally), it won’t be cleaned → which can lead to memory issues. 📌 In short: Java automatically removes unused objects by checking whether they are still reachable — using different GC strategies optimized for performance and latency. #Java #Programming #JVM #GarbageCollection #SoftwareDevelopment #TechConcepts
To view or add a comment, sign in
-
-
🚀 Java Series — Day 5: Executor Service & Thread Pool Creating threads manually is easy… But managing them efficiently? That’s where real development starts ⚡ Today, I explored Executor Service & Thread Pool — one of the most important concepts for building scalable and high-performance Java applications. 💡 Instead of creating new threads again and again, Java allows us to reuse a pool of threads — saving time, memory, and system resources. 🔍 What I Learned: ✔️ What is Executor Service ✔️ What is Thread Pool ✔️ Difference between manual threads vs thread pool ✔️ How it improves performance & resource management 💻 Code Insight: import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class Demo { public static void main(String[] args) { ExecutorService executor = Executors.newFixedThreadPool(3); for (int i = 1; i <= 5; i++) { int task = i; executor.execute(() -> { System.out.println("Executing Task " + task + " by " + Thread.currentThread().getName()); }); } executor.shutdown(); } } ⚡ Why it matters? 👉 Better performance 👉 Controlled thread usage 👉 Avoids system overload 👉 Used in real-world backend systems 🌍 Real-World Use Cases: 💰 Banking & transaction processing 🌐 Web servers handling multiple requests 📦 Background task processing systems 💡 Key Takeaway: Don’t create threads blindly — manage them smartly using Executor Service for scalable and production-ready applications 🚀 📌 Next: CompletableFuture & Async Programming 🔥#Java #Multithreading #ExecutorService #ThreadPool #BackendDevelopment #JavaDeveloper #100DaysOfCode #CodingJourney #LearnInPublic
To view or add a comment, sign in
-
-
🚀 Java Revision Journey – Day 18 Today I revised the List Interface and ArrayList in Java, which are fundamental for handling ordered data collections. 📝 List Interface Overview The List interface (from java.util) represents an ordered collection where: 📌 Key Features: • Maintains insertion order • Allows duplicate elements • Supports index-based access • Allows null values (depends on implementation) • Supports bidirectional traversal using ListIterator 💻 Common Implementations • ArrayList • LinkedList 👉 Example: List<Integer> list = new ArrayList<>(); ⚙️ Basic List Operations • Add → add() • Update → set() • Search → indexOf(), lastIndexOf() • Remove → remove() • Access → get() • Check → contains() 🔁 Iterating a List • For loop (using index) • Enhanced for-each loop 📌 ArrayList in Java ArrayList is a dynamic array that can grow or shrink as needed. 💡 Features: • Maintains order • Allows duplicates • Fast random access • Not thread-safe 🛠️ Constructors • new ArrayList<>() • new ArrayList<>(collection) • new ArrayList<>(initialCapacity) ⚡ Internal Working (Simplified) Starts with default capacity Stores elements in an array When capacity exceeds → resizes automatically (grows dynamically) 💡 Understanding List and ArrayList is essential for managing dynamic data efficiently in Java applications. Continuing to strengthen my Java fundamentals step by step 💪 #Java #JavaLearning #ArrayList #Collections #JavaDeveloper #BackendDevelopment #Programming #JavaRevisionJourney 🚀
To view or add a comment, sign in
-
-
Learn how to sort collections in Java using Comparable and Comparator, and choose the right approach for clean and efficient ordering.
To view or add a comment, sign in
-
Learn how to sort collections in Java using Comparable and Comparator, and choose the right approach for clean and efficient ordering.
To view or add a comment, sign in
-
💡 Choosing GC in Java: What You Control vs What You Don’t While diving into JVM internals, I found a key concept about Garbage Collection (GC) that’s often misunderstood 👇 👉 In Java, we can choose which Garbage Collector to use But… 👉 We cannot control when it actually runs 🔍 Which GC is used by default? ✔ Before Java 8 → Parallel GC (Throughput Collector) ✔ Java 9 and above → G1 GC (Garbage First) ✅ ⚙️ How to choose a GC? (JVM Commands) 👉 Run your program like this: java -XX:+UseSerialGC MyProgram java -XX:+UseParallelGC MyProgram java -XX:+UseG1GC MyProgram java -XX:+UseZGC MyProgram 🧠 Basic Functionality of Popular GCs 🔹 Parallel GC (Throughput GC) ✔ Uses multiple threads for garbage collection ✔ Focuses on maximum throughput (performance) ❌ Causes Stop-The-World (STW) pauses 👉 Best for applications where speed > pause time 🔹 G1 GC (Garbage First) ✔ Divides heap into regions instead of generations ✔ Collects regions with maximum garbage first ✔ Provides low and predictable pause times 👉 Best for large-scale and modern applications 💡 Even if you call: System.gc(); ❌ It does NOT guarantee GC ✔ It’s just a request — JVM may ignore it 🔑 Key Takeaways: ✔ We control the type of GC (policy) ✔ JVM controls execution (timing & behavior) ✔ GC runs based on memory usage & internal algorithms ✔ Forcing GC can hurt performance 🚀 Interview Insight: “System.gc() is a suggestion, not a command.” Understanding this changed how I see JVM — it's highly optimized and smarter than manual control. 👉 We choose the GC, but JVM decides its execution. #Java #JVM #GarbageCollection #BackendDevelopment #JavaDeveloper #Programming #InterviewPreparation
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
https://github.com/raushansingh7033/core-java