While learning more about constructors in Java, the idea of a default constructor also became clearer. A default constructor is automatically provided by Java when no constructor is written in a class. Things that became clear : • if a class does not define any constructor, Java automatically creates a default constructor • the default constructor has no parameters • it mainly helps create objects without requiring initialization values • instance variables get their default values if they are not explicitly initialized • once a constructor is written manually, Java no longer provides the default one automatically A simple example shows how it works : class Student { int rollNo; String name; } public class Test { public static void main(String[] args) { Student s = new Student(); System.out.println(s.rollNo); System.out.println(s.name); } } Here, even though no constructor is written, Java still allows object creation by providing a default constructor. Understanding this behaviour helps explain why objects can still be created even when constructors are not explicitly defined. #java #oop #programming #learning #dsajourney
Lakhyadeep Sen’s Post
More Relevant Posts
-
🚀 Starting My Java Learning Journey – Day 6 🔹 Topic: Loops in Java Loops in Java are used to execute a block of code repeatedly until a certain condition is met. Java mainly provides three types of loops: 1️⃣ for Loop Used when the number of iterations is known. Example: public class Main { public static void main(String[] args) { for(int i = 1; i <= 5; i++) { System.out.println(i); } } } 2️⃣ while Loop Used when the number of iterations is not known beforehand. Example: public class Main { public static void main(String[] args) { int i = 1; while(i <= 5) { System.out.println(i); i++; } } } 3️⃣ do-while Loop The do-while loop executes the code at least once even if the condition is false. Example: public class Main { public static void main(String[] args) { int i = 1; do { System.out.println(i); i++; } while(i <= 5); } } 💡 Key Point: Loops help automate repetitive tasks and make programs more efficient. #Java #JavaLearning #Programming #BackendDevelopment #CodingJourney #JavaLoops
To view or add a comment, sign in
-
🚀 Before Learning Spring Boot, Understand Java Annotations Annotations in Java are used to provide metadata about the code, such as information about classes, methods, or variables. They do not directly change the program logic but help the compiler and frameworks understand how the code should be processed. Java also provides meta-annotations, which define how other annotations behave. Two important ones are: • @Target – Specifies where an annotation can be applied (class, method, field, parameter, etc.) • @Retention – Defines how long the annotation is available (source, class, or runtime) Annotations can also be understood in different ways: ✔ Compile-time annotations – Example: @Override, checked by the compiler during compilation. ✔ Runtime annotations – Example: @Deprecated, which can also be accessed at runtime using reflection. ✔ Target-based annotations – Example: @FunctionalInterface, which is applied at the interface level to ensure the interface has only one abstract method. Since Spring Boot is heavily annotation-driven, understanding Java annotations makes it easier to grasp concepts like dependency injection, configuration, and component scanning. Building strong fundamentals always makes learning frameworks much smoother. What was the first Java annotation you learned? 👇 #Java #SpringBoot #BackendDevelopment #Programming #LearningInPublic
To view or add a comment, sign in
-
Day 40 of Learning Java: Method Overloading Instead of creating different method names for similar tasks, we can use the same method name but change the parameters — and Java figures out which one to call. -So what exactly is Method Overloading? It’s when multiple methods in the same class have: ✔ Same name ✔ Different parameter list That’s it. Simple idea, but very powerful. -Ways to overload a method • Change the type of parameters • Change the number of parameters • Change the order of parameters Example- Think of a login system: Login using username + password Login using mobile + password Both are login actions, right? So instead of writing different method names, we just overload: login(String username, String password) login(long mobile, String password) Same method name → different ways to use it -Another relatable one Payment systems 👇 COD UPI Card Net Banking Instead of: paymentByUPI(), paymentByCard()… We can just do: payment() payment(String upi) payment(long card) payment(String user, String pass) - Important things I learned • Just changing return type won’t work (it gives error) • Overloading happens at compile time • Works with static, private, and even final methods • Yes, even main() can be overloaded (but JVM only runs the standard one) #Java #LearningInPublic #100DaysOfCode #Programming #OOP #CodingJourney
To view or add a comment, sign in
-
-
🚀 Starting My Java Learning Journey – Day 13 ♦Topic: Exception Handling in Java Exception Handling is used to handle runtime errors so that the program does not crash abruptly. It helps in maintaining the normal flow of the program. ✅ Types of Exceptions 1)Checked Exceptions → Checked at compile time 2) Unchecked Exceptions → Occur at runtime ✅ Keywords Used in Exception Handling ✔ try → block where code is written ✔ catch → handles the exception ✔ finally → always executes (optional) ✔ throw → used to explicitly throw an exception ✔ throws → declares exceptions ✅ Example Program public class Main { public static void main(String[] args) { try { int result = 10 / 0; // may cause exception System.out.println(result); } catch (ArithmeticException e) { System.out.println("Cannot divide by zero"); } finally { System.out.println("Execution completed"); } } } Output: Cannot divide by zero Execution completed 💡 Key Points: ✔ Prevents program crash ✔ Helps handle runtime errors ✔ Improves program reliability #Java #JavaLearning #Programming #BackendDevelopment #CodingJourney #ExceptionHandling
To view or add a comment, sign in
-
While learning Java, I realized something important: 👉 Writing code is easy 👉 Handling failures correctly is what makes you a good developer So here’s my structured understanding of Exception Handling in Java 👇Java Exception Handling — the part most tutorials rush through. If you're writing Java and your only strategy is wrapping everything in a try-catch(Exception e) and hoping for the best, this is for you. A few things worth understanding properly: 1. Checked vs Unchecked isn't just trivia Checked exceptions (IOException, SQLException) are compile-time enforced — the language is telling you these failure modes are expected and you must plan for them. Unchecked exceptions (RuntimeException and its subclasses) signal programming bugs — they shouldn't be caught and hidden, they should be fixed. 2. finally is a contract, not a suggestion That block runs regardless of what happens. Use it for resource cleanup. Better yet, use try-with-resources in modern Java — it handles it automatically. 3. Rethrowing vs Ducking "Ducking" means declaring throws on a method and letting the caller deal with it. Rethrowing means catching it, maybe wrapping it with more context, and throwing again. Know when each makes sense. 4. Custom exceptions add clarity A PaymentDeclinedException tells the next developer (and your logs) far more than a generic RuntimeException with a message string. The image attached gives a clean visual overview — bookmarking it might save you a Google search or two. TAP Academy kshitij kenganavar What's your go-to rule for exception handling in production systems? #Java #SoftwareDevelopment #CleanCode #JavaDeveloper #BackendEngineering #TechEducation #100DaysOfCode
To view or add a comment, sign in
-
-
Another concept that appears while studying class initialization in Java is the instance block. It behaves differently from static blocks and is tied to object creation rather than class loading. Things that became clear : • an instance block runs every time an object of the class is created • it executes before the constructor • it can be used to perform common initialization steps for objects • unlike static blocks, instance blocks run for each object created • they are part of the object initialization process A simple structure shows the execution flow : class Demo { { System.out.println("Instance block executed"); } Demo() { System.out.println("Constructor executed"); } public static void main(String[] args) { Demo d = new Demo(); } } When the object is created, the instance block executes first and then the constructor runs. Understanding this order helps in seeing how Java prepares an object step by step during creation. #java #oop #programming #learning #dsajourney
To view or add a comment, sign in
-
🚀 Understanding Strings in Java – A Fundamental Concept for Every Developer While learning Java, one of the most important topics to understand is Strings and how Java manages them in memory. 🔹 A String is a sequence of characters enclosed in double quotes, like "JAVA". 🔹 In Java, Strings are treated as objects and stored in the heap memory. 📌 Key Concepts I Learned: ✅ Immutable vs Mutable Strings Immutable: Cannot be changed after creation (e.g., names, date of birth). Mutable: Values that may change, like passwords or email IDs. ✅ String Pool & Memory Allocation Constant Pool → Created without new keyword (String s = "JAVA";) Non-Constant Pool → Created using new keyword (new String("JAVA")) Duplicate literals share the same memory reference in the pool. ✅ String Comparison Methods in Java == → Compares memory reference equals() → Compares actual string value compareTo() → Compares character by character equalsIgnoreCase() → Compares values ignoring case 💡 Example Insight: Two "JAVA" literals may refer to the same memory location, but new String("JAVA") always creates a new object. Understanding these fundamentals helps write efficient and optimized Java programs. 📚 Currently exploring more core Java concepts and strengthening my programming foundation in TAP Academy . #Java #Programming #JavaDeveloper #Coding #SoftwareDevelopment #LearningJava #CoreJava #Developers
To view or add a comment, sign in
-
-
🚀 Understanding Exception Handling in Java Exception handling is a powerful mechanism in Java that helps manage runtime errors and ensures smooth program execution without abrupt termination. 🔹 Common Types of Exceptions: ArrayIndexOutOfBoundsException – occurs when accessing an invalid index in an array NegativeArraySizeException – occurs when an array is created with a negative size ArithmeticException – occurs during illegal mathematical operations (like division by zero) InputMismatchException – occurs when the input type does not match the expected data type 🔹 Single Try with Multiple Catch Blocks: In Java, a single try block can be followed by multiple catch blocks to handle different types of exceptions separately. This improves code readability and error handling efficiency. 🔹 Generic Catch Block: The final catch block can act as a generic handler (usually Exception e) to catch any exceptions that are not handled by previous catch blocks. ⚠️ Important Rule: The generic catch block must always be placed last, otherwise it will cause a compile-time error, since it would override all other specific exceptions. 💡 Proper exception handling not only prevents crashes but also makes your applications more robust and user-friendly. #Java #ExceptionHandling #Programming #Coding #Developers #Learning #Tech #TapAcademy
To view or add a comment, sign in
-
-
🚀 Starting My Java Learning Journey – Day 9 🔹 Topic: Method Overloading in Java Method Overloading is a feature in Java that allows a class to have multiple methods with the same name but different parameters. It helps improve code readability and flexibility. 📌 Ways to Achieve Method Overloading 1️⃣ Different number of parameters 2️⃣ Different data types of parameters 📌 Example Program public class Main { // Method with two int parameters static int add(int a, int b) { return a + b; } // Method with three int parameters static int add(int a, int b, int c) { return a + b + c; } public static void main(String[] args) { System.out.println(add(5, 10)); System.out.println(add(5, 10, 15)); } } Output: 15 30 💡 Key Points: ✔ Method overloading allows multiple methods with the same name ✔ Methods must differ in number or type of parameters ✔ Helps make programs more flexible and readable #Java #JavaLearning #Programming #BackendDevelopment #CodingJourney #MethodOverloading
To view or add a comment, sign in
-
🚀 Day 27 | Core Java Learning Journey 📌 Topic: Vector & Stack in Java Today, I learned about Vector and Stack, two important Legacy Classes in Java that are part of the early Java library and later became compatible with the Java Collections Framework. 🔹 Vector in Java ✔ Vector is a legacy class that implements the List interface ✔ Data structure: Growable (Resizable) Array ✔ Maintains insertion order ✔ Allows duplicate elements ✔ Allows multiple null values (not "NILL" ❌ → correct term is null ✔) ✔ Can store heterogeneous objects (different data types using Object) ✔ Synchronized by default (thread-safe, but slower than ArrayList) 📌 Important Methods of Vector • add() – add element • get() – access element • remove() – delete element • size() – number of elements • capacity() – current capacity of vector 💡 Note: Due to synchronization overhead, ArrayList is preferred in modern Java. 🔹 Stack in Java ✔ Stack is a subclass (child class) of Vector ✔ It is also a Legacy Class ✔ Data structure: LIFO (Last In, First Out) 📌 Core Methods of Stack • push() – add element to top • pop() – remove top element • peek() – view top element without removing 📌 Additional Useful Methods • isEmpty() – check if stack is empty • search() – find element position 💡 Note: In modern Java, Deque (ArrayDeque) is preferred over Stack for better performance. 📌 Key Difference: Vector vs Stack ✔ Vector → General-purpose dynamic array ✔ Stack → Specialized for LIFO operations 💡 Understanding these legacy classes helps in learning how Java data structures evolved and why modern alternatives are preferred today. Special thanks to Vaibhav Barde Sir for the guidance! #CoreJava #JavaLearning #JavaDeveloper #Vector #Stack #JavaCollections #Programming #LearningJourney
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