📘 Java Learning – Collections Framework (Part 8: SortedMap, TreeMap, Hashtable & Properties) 🗺️🚀 Continuing my Java Collections journey, today I explored Map implementations where ordering, synchronization, and configuration matter. 🔰 SortedMap (I) • Child interface of Map • Stores entries in sorted order of keys (not values) • Sorting can be: • Natural order • Custom order (Comparator) 📌 Key methods: • firstKey(), lastKey() • headMap(), tailMap(), subMap() • comparator() 🔰 TreeMap (C) • Underlying data structure: Red-Black Tree • Entries sorted based on keys • Duplicate keys ❌, duplicate values ✅ • Values can be heterogeneous & non-comparable 📌 Key rules: • Natural sorting → keys must be homogeneous & Comparable • Custom sorting → handled by Comparator 📌 Null behavior: • modern Java, TreeMap does NOT allow null keys • After that → NullPointerException • Null values allowed anytime 📌 Constructors: TreeMap t1 = new TreeMap(); // Natural sorting TreeMap t2 = new TreeMap(Comparator c); // Custom sorting TreeMap t3 = new TreeMap(Map m); TreeMap t4 = new TreeMap(SortedMap m); 🧪 Short Example: TreeMap tm = new TreeMap(); tm.put(3, "Java"); tm.put(1, "Spring"); tm.put(2, "Boot"); tm.put("1", "Program") //ClassCastException tm.put(null, "Demo") // NullPointerException System.out.println(tm); // {1=Spring, 2=Boot, 3=Java} 🔰 Hashtable (C) • Legacy Map class • Fully synchronized → thread-safe • No null key or null value allowed • Slower due to synchronization 📌 Constructors: Hashtable h1 = new Hashtable(); Hashtable h2 = new Hashtable(int capacity); Hashtable h3 = new Hashtable(int capacity, float loadFactor); Hashtable h4 = new Hashtable(Map m); 🧪 Short Example: Hashtable ht = new Hashtable(); ht.put(1, "Java"); ht.put(2, "Spring"); System.out.println(ht); 🔰 Properties (C) • Child class of Hashtable • Used for external configuration • Keys and values must be String • Common use: DB URL, username, password, config values 📌 Advantage: • Change configuration without recompiling code • Only redeployment needed → minimal business impact 📌 Constructor: Properties p = new Properties(); 📌 Important methods: • getProperty() • setProperty() • load(), store() 🧪 Short Example: Properties p = new Properties(); p.setProperty("user", "admin"); p.setProperty("url", "localhost"); System.out.println(p.getProperty("user")); ⭐ Key Takeaways • SortedMap → Sorted keys • TreeMap → Sorted + navigable Map • Hashtable → Thread-safe legacy Map • Properties → Externalized configuration Understanding Maps deeply helps build scalable, configurable, and maintainable Java applications 💡 Building strong Java fundamentals, one collection at a time ☕💻 #Java #CoreJava #CollectionsFramework #SortedMap #TreeMap #Hashtable #Properties #JavaCollections #LearningJourney
Java Collections Framework: SortedMap, TreeMap, Hashtable & Properties Explained
More Relevant Posts
-
📘 Java Learning – Collections Framework (Final Part: Collections Class & Arrays Class) 🚀🎯 Wrapping up my Java Collections journey with two powerful utility classes from java.util package: 👉 Collections class 👉 Arrays class These classes provide utility methods for sorting, searching, reversing, and converting data structures efficiently. 🔰 Collections Class A utility class that provides methods for Collection implemented classes. 📌 Sorting a List Collections.sort(List l); // Natural sorting Collections.sort(List l, Comparator c); // Custom sorting ✔ Elements must be homogeneous & Comparable (for natural sorting) ✔ Null elements not allowed (NullPointerException) 📌 Searching in a List Collections.binarySearch(List l, Object obj); Collections.binarySearch(List l, Object key, Comparator c); ⚠ Important Rules: • List must be sorted before searching • Uses Binary Search algorithm • Successful search → returns index • Unsuccessful search → returns insertion point • Must use same Comparator used for sorting 📌 Reversing a List Collections.reverse(List l); // Reverses list Collections.reverseOrder(); // Returns Comparator (descending) ✔ reverse() → works on List ✔ reverseOrder() → returns Comparator 🔰 Arrays Class Utility class for array operations (primitive & object arrays). 📌 Sorting Arrays Arrays.sort(int[] arr); // Primitive (natural order) Arrays.sort(Object[] arr); // Natural order Arrays.sort(Object[] arr, Comparator c); // Custom sorting ✔ Primitive arrays → only natural sorting ✔ Object arrays → natural or custom sorting 📌 Searching in Arrays Arrays.binarySearch(int[] arr, key); Arrays.binarySearch(Object[] arr, key); Arrays.binarySearch(Object[] arr, key, Comparator c); ✔ Same rules as Collections.binarySearch() 🔰 Converting Array to List List list = Arrays.asList(Object[] arr); ⚠ Important: • Creates a List view, not independent list • Changes in list reflect in array & vice versa • Cannot change size (add/remove → UnsupportedOperationException) • Replacement allowed but type must match (else ArrayStoreException) 🧪 Combined Example Integer[] arr = {30, 10, 20}; Arrays.sort(arr); // Sorting array System.out.println(Arrays.toString(arr)); // [10, 20, 30] int index = Arrays.binarySearch(arr, 20); System.out.println(index); // 1 List list = Arrays.asList(arr); Collections.reverse(list); System.out.println(list); // [30, 20, 10] ⭐ Final Takeaways • Collections → Utility methods for List • Arrays → Utility methods for Arrays • Always sort before binarySearch • asList() creates a fixed-size list view This completes my Java Collections Framework journey 🎯 Understanding these utilities makes data handling more efficient and interview-ready 💡 Building strong Java fundamentals, one collection at a time ☕💻 #Java #CoreJava #CollectionsFramework #CollectionsClass #ArraysClass #JavaCollections #LearningJourney
To view or add a comment, sign in
-
Day 7 – Queue, Deque & PriorityQueue in Java Collections (Backend Developer Learning Series) Today I revised Queue, Deque, and PriorityQueue from the Java Collection Framework — important data structures used in task scheduling, message queues, and backend processing systems. 📌 What is Queue? Queue is a sub-interface of Collection defined in the java.util package. Queue follows the FIFO principle (First In First Out). ➡ Elements are inserted from the rear (tail) ➡ Elements are removed from the front (head) Example: Insert → 10 20 30 40 Remove → 10 (first inserted element) ⚙ Queue Implementations Some commonly used Queue classes: ✔ LinkedList ✔ PriorityQueue ✔ ArrayDeque 📌 Important Queue Methods 1️⃣ offer() q.offer(40); Adds an element to the rear of the queue. 2️⃣ poll() q.poll(); Removes and returns the head element. 3️⃣ peek() q.peek(); Returns the head element without removing it. 📌 What is Deque? Deque stands for Double Ended Queue. It allows insertion and deletion from both ends. ✔ Insert from front and rear ✔ Remove from front and rear Deque is defined in java.util package. ⚙ Deque Implementations ✔ ArrayDeque ✔ LinkedList 📌 Important Deque Methods Insert Methods offerFirst() offerLast() addFirst() addLast() Remove Methods pollFirst() pollLast() removeFirst() removeLast() Access Methods peekFirst() peekLast() getFirst() getLast() 📌 ArrayDeque ArrayDeque is a class that implements the Deque interface. Key Points ✔ Introduced in JDK 1.6 ✔ Uses resizable array internally ✔ Faster than Stack in many cases ✔ Default capacity = 16 📌 PriorityQueue PriorityQueue is another implementation of the Queue interface. Unlike normal queues, elements are ordered based on priority instead of insertion order. ✔ Default sorting → Natural order (Ascending) ✔ Uses Heap data structure internally ✔ Does NOT allow null values 💻 Example Program – PriorityQueue import java.util.*; public class PriorityQueueExample { public static void main(String[] args) { PriorityQueue<Integer> pq = new PriorityQueue<>(); pq.offer(30); pq.offer(10); pq.offer(50); pq.offer(20); System.out.println(pq); while(!pq.isEmpty()) { System.out.println(pq.poll()); } } } Output 10 20 30 50 Elements are removed in priority order (ascending) PriorityQueue is used in: ✔ Task priority scheduling ✔ Load balancing ✔ Path finding algorithms ✔ CPU scheduling 🧠 Key Learning Queue → FIFO data processing Deque → Flexible queue with operations from both ends PriorityQueue → Processes elements based on priority Understanding these structures helps build efficient backend processing systems. #Java #BackendDeveloper #JavaCollections #Queue #Deque #PriorityQueue #SpringBoot #LearningInPublic #SoftwareEngineering
To view or add a comment, sign in
-
🚀 Day 31 | Core Java Learning Journey 📌 Topic: HashMap & Map Implementations (Internal Working + Concepts) Today, I deep-dived into how HashMap actually works internally along with LinkedHashMap, TreeMap, and Hashtable. This helped me understand not just usage, but the logic behind performance. 🔹 What is HashMap? ✔ HashMap is a class that implements Map interface ✔ Stores data in key-value pairs ✔ Allows one null key and multiple null values ✔ Not synchronized (not thread-safe) 🔹 Internal Working of HashMap ✔ Default initial capacity = 16 (bucket size) ✔ Data is stored in buckets (array of nodes) ✔ Each key’s hashCode() is used to find bucket index ✔ Formula: index = hash(key) & (n - 1) ✔ If two keys have same bucket index → Collision occurs 👉 Collision Handling: • Uses Linked List (before Java 8) • Uses Linked List + Balanced Tree (after Java 8) • If bucket size > 8 → converts into Red-Black Tree • If reduced → converts back to Linked List ✔ Load Factor = 0.75 (default) ✔ When threshold exceeds → resizing (rehashing) happens 🔹 Important Concepts ✔ Bucket → Each index of internal array ✔ Hashing → Converting key into integer hash ✔ Collision → Multiple keys at same index ✔ Rehashing → Increasing size & redistributing data 🔹 LinkedHashMap ✔ Extends HashMap ✔ Maintains insertion order ✔ Uses doubly linked list internally ✔ Slightly slower than HashMap 🔹 TreeMap ✔ Implements NavigableMap ✔ Stores keys in sorted order (natural/custom comparator) ✔ Uses Red-Black Tree internally ✔ Does NOT allow null key 🔹 Hashtable ✔ Legacy class (introduced before collections framework) ✔ Thread-safe (synchronized) ✔ Does NOT allow null key or value ✔ Slower due to synchronization 🔹 Key Differences ✔ HashMap → Fastest, no ordering ✔ LinkedHashMap → Maintains insertion order ✔ TreeMap → Sorted data ✔ Hashtable → Thread-safe but slower 📌 When to Use What? ✅ Use HashMap → Best performance, general use ✅ Use LinkedHashMap → Order matters ✅ Use TreeMap → Sorted output required ✅ Use Hashtable → Thread-safe (but prefer ConcurrentHashMap in modern Java) 💡 Key Takeaway: Understanding internal working of HashMap (buckets, hashing, collisions, rehashing) helps write optimized and scalable code instead of just using it blindly. Special thanks to Vaibhav Barde Sir for the guidance! #CoreJava #JavaLearning #JavaDeveloper #HashMap #LinkedHashMap #TreeMap #Hashtable #JavaCollections #Programming #LearningJourney
To view or add a comment, sign in
-
-
Day 6 – TreeSet in Java Collections | Sorted Set | Custom Sorting (Backend Developer Learning Series) Today I revised TreeSet, one of the important implementations of the Set interface in Java Collection Framework. TreeSet is very useful when we need unique elements along with automatic sorting. 📌 What is TreeSet? TreeSet is a class that implements the NavigableSet interface, which extends SortedSet. It is available in the java.util package. TreeSet was introduced in JDK 1.2 as part of the Collection Framework. ⚙ Underlying Data Structure TreeSet internally uses a Red-Black Tree. Because of this, elements are stored in sorted order. Sorting happens using: Natural sorting (Comparable) Custom sorting (Comparator) ✨ Characteristics of TreeSet ✔ Duplicate values are NOT allowed ✔ Elements are stored in sorted order ✔ Insertion order is NOT maintained ✔ Null values are NOT allowed ✔ Heterogeneous objects are not allowed ✔ It is not index based 📊 Example Program – TreeSet with Integer import java.util.*; public class TreeSetExample { public static void main(String[] args) { TreeSet<Integer> t = new TreeSet<>(); t.add(10); t.add(50); t.add(9); t.add(12); t.add(45); t.add(55); t.add(1); System.out.println(t); } } TreeSet with Custom Object If we want to store custom objects in TreeSet, the object must implement: Comparable interface or use Comparator Example fields: ticketNo price source destination **Sorting can be done based on price, ticket number, or destination. Practice Java Programs (Based on TreeSet) 1️⃣ Add integer objects to TreeSet and display sorted output. 2️⃣ Write a program to store String values in TreeSet and display them in sorted order. 3️⃣ Write a program to store Integer values in TreeSet in descending order. 4️⃣ Write a program to remove duplicates using TreeSet. 5️⃣ Create a Ticket class and store objects in TreeSet sorted by price. 6️⃣ Write a program to check if an element exists in TreeSet using contain(); 7️⃣ Write a program to display first and last element of TreeSet. 8️⃣ Write a program to remove the highest element from TreeSet. Method: pollLast() 9️⃣ Write a program to store custom objects in TreeSet using Comparator. 🔟 Write a program to convert ArrayList → TreeSet to remove duplicates and sort data. #Java #BackendDeveloper #JavaCollections #TreeSet #Set #SpringBoot #LearningInPublic #SoftwareEngineering
To view or add a comment, sign in
-
📘 Java Learning – Collections Framework (Part 9: Queue, PriorityQueue, NavigableSet & NavigableMap) 🚦🚀 Continuing my Java Collections series, today I explored collections used for ordering, prioritizing, and navigation of data. 🔰 Queue (I) • Child interface of Collection • Used to hold objects prior to processing • Generally follows FIFO (First In First Out) • From Java 1.5, LinkedList implements Queue • LinkedList-based Queue always follows FIFO 📌 Important Queue Methods • offer() → add element • peek() → returns head (null if empty) • element() → returns head (Exception if empty) • poll() → remove & return head (null if empty) • remove() → remove & return head (Exception if empty) 🧪 Example Queue q = new LinkedList(); q.offer(10); q.offer(20); System.out.println(q.poll()); // 10 🔰 PriorityQueue (C) • Used to process objects based on priority • Priority can be: • Default natural sorting • Custom sorting (Comparator) • Duplicate objects ✅ • Insertion order ❌ • Null insertion ❌ 📌 Sorting Rules • Natural order → objects must be homogeneous & Comparable • Comparator → no such restriction 📌 Constructors PriorityQueue q1 = new PriorityQueue(); PriorityQueue q2 = new PriorityQueue(int capacity); PriorityQueue q3 = new PriorityQueue(int capacity, Comparator c); PriorityQueue q4 = new PriorityQueue(Collection c); PriorityQueue q5 = new PriorityQueue(SortedSet s); 🧪 Example Queue pq = new PriorityQueue(); pq.offer(20); pq.offer(10); pq.offer(30); System.out.println(pq); // Order NOT guaranteed 🔰 NavigableSet (I) • Child interface of SortedSet • Provides navigation support for TreeSet 📌 Important Methods • ceiling(e) → ≥ e • higher(e) → > e • floor(e) → ≤ e • lower(e) → < e • pollFirst(), pollLast() • descendingSet() 🧪 Example NavigableSet ns = new TreeSet(); ns.add(10); ns.add(20); ns.add(30); System.out.println(ns.ceiling(15)); // 20 🔰 NavigableMap (I) • Child interface of SortedMap • Provides navigation methods for TreeMap 📌 Important Methods • ceilingKey() • higherKey() • floorKey() • lowerKey() • pollFirstEntry() • pollLastEntry() • descendingMap() 🧪 Example NavigableMap nm = new TreeMap(); nm.put(1, "Java"); nm.put(3, "Spring"); nm.put(2, "Boot"); System.out.println(nm.floorKey(2)); // 2 ⭐ Key Takeaways • Queue → FIFO processing • PriorityQueue → priority-based processing • NavigableSet → navigation on sorted sets • NavigableMap → navigation on sorted maps Understanding these collections helps in efficient data processing and retrieval 💡 Building strong Java fundamentals, one collection at a time ☕💻 #Java #CoreJava #CollectionsFramework #Queue #PriorityQueue #NavigableSet #NavigableMap #JavaCollections #LearningJourney
To view or add a comment, sign in
-
🔹 Polymorphism in Java: One Interface, Multiple Behaviors Polymorphism is one of the fundamental pillars of Object-Oriented Programming (OOP) in Java, introduced and popularized by Oracle Corporation. The term polymorphism is derived from two Greek words: poly (many) and morph (forms). It allows a single entity (method, object, or reference) to exhibit multiple behaviors depending on the context. In simple words, polymorphism enables one method or object to perform different tasks based on the situation, thereby enhancing flexibility and scalability in software design. --- 🔹 Types of Polymorphism in Java 1️⃣ Compile-time Polymorphism (Method Overloading) Also known as static polymorphism, it occurs when multiple methods share the same name but differ in parameters. class Calculator { int add(int a, int b) { return a + b; } double add(double a, double b) { return a + b; } } ✔ The method is decided at compile time. --- 2️⃣ Runtime Polymorphism (Method Overriding) Also known as dynamic polymorphism, it occurs when a subclass provides a specific implementation of a method declared in the parent class. class Animal { void sound() { System.out.println("Animal makes sound"); } } class Dog extends Animal { void sound() { System.out.println("Dog barks"); } } public class Test { public static void main(String[] args) { Animal a = new Dog(); a.sound(); } } ✔ The method is decided at runtime based on the object. --- 🔹 Key Advantages of Polymorphism ✅ Enhances code reusability ✅ Improves flexibility and extensibility ✅ Supports dynamic method binding ✅ Promotes clean and maintainable code ✅ Enables loose coupling in applications --- 🔹 Real-World Example Think of a payment system: - Payment can be made via Credit Card, UPI, or Net Banking - The same method "pay()" behaves differently depending on the payment type This is polymorphism in action. --- 🔹 Interview Questions on Polymorphism Q1. What is polymorphism in Java? Q2. What is the difference between method overloading and method overriding? Q3. Can we achieve polymorphism using interfaces? Q4. What is dynamic method dispatch? Q5. Is polymorphism possible without inheritance? --- 🔹 Conclusion Polymorphism is a powerful OOP concept that allows Java applications to become more dynamic, flexible, and scalable. It plays a crucial role in achieving abstraction, extensibility, and efficient code architecture. Mastering polymorphism is essential for writing professional-grade Java applications and cracking technical interviews. #Java #OOP #Polymorphism #Programming #SoftwareDevelopment #JavaDeveloper
To view or add a comment, sign in
-
🚀 Day 33 | Core Java Learning Journey 📌 Topic: File Handling in Java Today, I explored File Handling in Java — how applications store and retrieve data from files. This is a very important concept for building real-world applications where data persistence is required. 🔹 What is File Handling? ✔ File Handling is used to store data permanently in files ✔ It allows Java applications to read, write, and modify files ✔ Available through the java.io package 🔹 Why We Use File Handling? ✔ To store data permanently (even after program ends) ✔ To read existing data from files ✔ To build data-driven applications ✔ Used in logging, reports, configs, etc. 🔹 Important Classes in java.io.* ✔ File → Represents file or directory ✔ FileWriter → Writes data to file (character stream) ✔ FileReader → Reads data from file ✔ BufferedWriter → Efficient writing (faster) ✔ BufferedReader → Efficient reading (line by line) ✔ FileInputStream → Reads binary data ✔ FileOutputStream → Writes binary data ✔ InputStreamReader → Converts byte stream → character stream 🔹 Steps to Work with Files ✔ Step 1: Import package • import java.io.*; ✔ Step 2: Create File Object • File file = new File("test.txt"); ✔ Step 3: Write Data • FileWriter fw = new FileWriter(file); • fw.write("Hello Students"); ✔ Step 4: Read Data • FileReader fr = new FileReader(file); ✔ Step 5: Close Resources • Always close streams → fw.close(), fr.close() 🔹 Important Methods ✔ createNewFile() → Creates new file ✔ exists() → Checks file existence ✔ delete() → Deletes file ✔ write() → Writes data ✔ read() → Reads single character ✔ readLine() → Reads line (BufferedReader) ✔ flush() → Clears buffer and forces write ✔ close() → Closes stream 🔹 Key Concepts ✔ Buffered Streams → Faster performance ⚡ ✔ Character Streams → FileReader, FileWriter ✔ Byte Streams → FileInputStream, FileOutputStream ✔ Exception Handling → Must handle IOException ✔ Try-with-resources → Recommended (auto close) ✅ 🔹 Example (Best Practice) ✔ Using try-with-resources: • try (FileWriter fw = new FileWriter("test.txt")) { fw.write("Hello Students"); } 🔹 Store & Fetch Data ✔ Store → Using FileWriter / BufferedWriter ✔ Fetch → Using FileReader / BufferedReader ✔ Supports both text and binary data 📌 When to Use File Handling? ✅ When saving user data locally ✅ When working with logs or reports ✅ When database is not required ✅ When handling configuration files 💡 Key Takeaway: File Handling is essential for data persistence in Java. Understanding streams and proper resource management helps build efficient and reliable applications. Special thanks to Vaibhav Barde Sir for the guidance! #CoreJava #JavaLearning #JavaDeveloper #FileHandling #JavaIO #Programming #LearningJourney
To view or add a comment, sign in
-
-
🚀 Java Collections Deep Dive: Mastering the ArrayList ✔️ If you are working with data in Java, the ArrayList is likely your most-used tool. But knowing the methods is only half the battle—you also need to know how to handle them safely! 📦 1. Essential ArrayList Methods ✔️ The ArrayList is a dynamic array that provides a massive range of built-in functionality: 🔸 add(element): Add a single element. 🔸 get(index): Retrieves the element at a specific position. 🔸set(index, element): Replaces the element at a specific index. 🔸 remove(index/object): Deletes a specific element or an element at a certain index. 🔸 contains(element): Checks if a single element exists in the list. 🔸 containsAll(collection): Checks if the list contains a group of elements. 🔸 indexOf(element): Finds the first occurrence of an item. 🔸 lastIndexOf(element): Finds the last occurrence of an item. 🔸 size(): Returns the number of elements. 🔸 addAll(collection): Merges another collection into your list. 🔸 clear(): Wipes the entire list clean. 🔸 isEmpty(): A quick boolean check to see if the list is empty. 🛡️ 2. The Role of Generics <T> ✔️ Before Generics, lists could hold any object, which often led to runtime crashes. ✔️By using Generics, we enforce Type Safety. ✔️ Example: ArrayList<String> ensures that only Strings can be added. The compiler checks this for you, so you don't have to worry about ClassCastException later. ⚠️ 3. The ConcurrentModificationException Trap ➡️ Have you ever tried to remove an element while looping through a list using a for-each loop? ❌ CRASH! You’ll get a ConcurrentModificationException. This happens because Java doesn't allow the list's structure to change while it is being traversed by a standard loop. 🔄 4. The Solution: Using an Iterator ✔️ To overcome the crash above, we use an Iterator. It is an object that allows us to traverse the list and modify it safely. 🔹 hasNext(): Checks if there is a next element. 🔹 next(): Returns the next element. 🔹remove(): Safely removes the current element from the list. 💻 The "Interview Special" ➡️ import java.util.*; public class ArrayListMastery { public static void main(String[] args) { ArrayList<String> skills = new ArrayList<>(); skills.add("Java"); skills.add("Spring Boot"); skills.add("Microservices"); skills.add("Java"); System.out.println("Get Index 1: " + skills.get(1)); System.out.println("Contains Java? " + skills.contains("Java")); System.out.println("Last Index: " + skills.lastIndexOf("Java")); //The Interview "Trick": Safe Removal using Iterator // Overcomes ConcurrentModificationException Iterator<String> it = skills.iterator(); while (it.hasNext()) { if (it.next().equals("Java")) { it.remove(); } } System.out.println("Final List: " + skills); } } #Java #CodingInterview #SoftwareEngineering #JavaCollections
To view or add a comment, sign in
-
🚀 Java Revision Journey – Day 12 Today I revised the BigInteger class in Java, which is used to perform calculations involving very large integer values that exceed the limits of primitive data types such as int and long. 🔖 BigInteger Class: The BigInteger class, available in the java.math package, allows Java programs to work with integers of virtually unlimited size. Unlike primitive data types that have fixed memory limits, BigInteger can handle extremely large numbers and perform precise mathematical operations without overflow. 🔖 Why BigInteger is Needed: Primitive data types like int (32-bit) and long (64-bit) have a maximum range. When computations exceed these limits, overflow occurs and results become incorrect. The BigInteger class overcomes this limitation by providing a way to perform large integer calculations reliably. 🔖 Initialization of BigInteger: There are several ways to create a BigInteger object in Java: • Using the new keyword BigInteger a = new BigInteger("12345"); • Passing a String variable String b = "43215"; BigInteger a = new BigInteger(b); • Using the valueOf() static method BigInteger a = BigInteger.valueOf(34567); 🔖 Common Methods of BigInteger: The BigInteger class provides many built-in methods to perform arithmetic operations and value conversions. • add() – Performs addition • subtract() – Performs subtraction • multiply() – Performs multiplication • divide() – Performs division • remainder() / mod() – Finds remainder • pow() – Calculates power of a number • sqrt() – Computes square root • abs() – Returns absolute value • max() / min() – Finds maximum or minimum value • intValue(), longValue(), doubleValue() – Converts BigInteger to primitive types • toString() – Converts BigInteger to String representation 🔖 Practice Problems Using BigInteger: To better understand the usage of this class, I practiced implementing problems such as: • Factorial of very large numbers • Fibonacci series with large values • Prime number checking with large integers 💻 The BigInteger class is widely used in applications that require precise large-number computations, such as cryptography, financial systems, scientific calculations, and competitive programming. Continuing to strengthen my Java fundamentals step by step. #Java #JavaLearning #JavaDeveloper #OOP #BackendDevelopment #Programming #JavaRevisionJourney
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