🚀 Day 40 – Core Java | Abstraction & Abstract Classes Today’s session focused on the fourth pillar of Object-Oriented Programming — Abstraction and how it works in Java. 🔹 What is Abstraction? Abstraction means: 👉 Hiding the implementation details and showing only the essential features. Real-world example When you drive a car: You press the accelerator You use the steering You apply brakes But you don’t know the internal engine mechanism. The internal working is hidden — this is Abstraction. Another example: Using Instagram / WhatsApp You swipe or send a message But you don’t know the internal code. You only see the features, not the implementation. 🔹 Abstract Method in Java An abstract method is an incomplete method. It contains only the method signature, not the body. Example: abstract void calculateArea(); Here: Method name → calculateArea No implementation The implementation will be provided by child classes. 🔹 Abstract Class If a class contains at least one abstract method, the class must be declared as abstract. Example: abstract class Shape { abstract void calculateArea(); } Important rule: 👉 Abstract class cannot be instantiated (object cannot be created). ❌ Not allowed Shape s = new Shape(); Because the class contains incomplete methods. 🔹 Example Used in Class We implemented Shapes example using abstraction. Parent class: Shape Child classes: Square Rectangle Circle Common behavior: acceptInput() calculateArea() displayArea() Design Shape (Abstract Class) abstract class Shape { float area; abstract void acceptInput(); abstract void calculateArea(); void displayArea() { System.out.println(area); } } Child classes override the abstract methods. Example: class Square extends Shape Each class calculates area differently. 🔹 Advantages 1️⃣ Code Reusability Common methods like displayArea() written once in parent class. 2️⃣ Better Design Abstract class defines common structure. 3️⃣ Cleaner Code Child classes implement only required logic. 🔹 Important Rules of Abstraction ✔ Abstract method → no body ✔ Class with abstract method → must be abstract ✔ Abstract class cannot create object ✔ Abstract class can contain normal methods also ✔ Abstract keyword cannot be used with variables ❌ Not allowed abstract int a; 🔹 Abstract vs Final abstract and final cannot be used together. Reason: abstract → method must be overridden final → method cannot be overridden So they contradict each other. 🔹 Key Insight Abstraction works like a hierarchy: Top level → more abstract Lower level → more concrete Example: Bird (abstract) ↓ Eagle (partially abstract) ↓ GoldenEagle / SerpentEagle (concrete) As we move down the hierarchy, abstract behavior becomes fully implemented. #Java #CoreJava #OOPS #Abstraction #AbstractClass #JavaDeveloper #ProgrammingJourney #SoftwareEngineering #LearningInPublic
Java Abstraction & Abstract Classes Explained
More Relevant Posts
-
Here is the exact matter (theory) from your image, written clearly in paragraph form (Tap Academy style, not point-wise): Abstraction in Java is the process of hiding implementation details and providing only essential features to the user. It focuses on what an object does rather than how it does it. An abstract method is an incomplete method that contains only a method signature and no body, and it is declared using the abstract keyword. An abstract class is a class that cannot be instantiated, meaning objects cannot be created for it. If a class contains at least one abstract method, then the class itself must be declared as abstract. The keywords abstract and final cannot be used together because they contradict each other. Abstract requires inheritance and method overriding, whereas final prevents overriding. The concept of abstraction can be understood with a real-world example like a car: a user can operate the steering wheel and controls without knowing how the engine works internally. Similarly, in programming, abstraction allows defining what should be done without specifying how it should be implemented. In code, abstraction is useful when a parent class provides methods that every child class must override according to its own requirement. It ensures that a common structure is followed while allowing flexibility in implementation. This helps in achieving better design and code reusability. An interface in Java is a collection of pure abstract methods and is used to achieve standardization. It acts like a contract where a class that implements the interface must provide implementations for all the abstract methods defined in it. Interfaces promote loose coupling and support polymorphism. All methods inside an interface are public and abstract by default, and variables are automatically public, static, and final. Interfaces cannot have objects created directly, but reference variables can be created. These references can point to objects of classes that implement the interface, which helps in achieving polymorphism and flexibility. A class can implement multiple interfaces, which helps achieve multiple inheritance in Java and avoids the diamond problem since interfaces do not contain method bodies. An interface can extend another interface, but it cannot implement another interface because it does not contain method definitions. A class can extend another class and also implement interfaces, but the order should be extends first and then implements. Interfaces can also contain constant variables and method declarations. An empty interface in Java is known as a marker interface or tagged interface. It is used to provide special information about a class. Examples of interfaces include Runnable, Comparable, Comparator, Set, List, Queue, and Deque. Serialization is an example of a marker interface.
To view or add a comment, sign in
-
-
Here is the exact matter (theory) from your image, written clearly in paragraph form (Tap Academy style, not point-wise): Abstraction in Java is the process of hiding implementation details and providing only essential features to the user. It focuses on what an object does rather than how it does it. An abstract method is an incomplete method that contains only a method signature and no body, and it is declared using the abstract keyword. An abstract class is a class that cannot be instantiated, meaning objects cannot be created for it. If a class contains at least one abstract method, then the class itself must be declared as abstract. The keywords abstract and final cannot be used together because they contradict each other. Abstract requires inheritance and method overriding, whereas final prevents overriding. The concept of abstraction can be understood with a real-world example like a car: a user can operate the steering wheel and controls without knowing how the engine works internally. Similarly, in programming, abstraction allows defining what should be done without specifying how it should be implemented. In code, abstraction is useful when a parent class provides methods that every child class must override according to its own requirement. It ensures that a common structure is followed while allowing flexibility in implementation. This helps in achieving better design and code reusability. An interface in Java is a collection of pure abstract methods and is used to achieve standardization. It acts like a contract where a class that implements the interface must provide implementations for all the abstract methods defined in it. Interfaces promote loose coupling and support polymorphism. All methods inside an interface are public and abstract by default, and variables are automatically public, static, and final. Interfaces cannot have objects created directly, but reference variables can be created. These references can point to objects of classes that implement the interface, which helps in achieving polymorphism and flexibility. A class can implement multiple interfaces, which helps achieve multiple inheritance in Java and avoids the diamond problem since interfaces do not contain method bodies. An interface can extend another interface, but it cannot implement another interface because it does not contain method definitions. A class can extend another class and also implement interfaces, but the order should be extends first and then implements. Interfaces can also contain constant variables and method declarations. An empty interface in Java is known as a marker interface or tagged interface. It is used to provide special information about a class. Examples of interfaces include Runnable, Comparable, Comparator, Set, List, Queue, and Deque. Serialization is an example of a marker interface.
To view or add a comment, sign in
-
-
🚀 Day 3 of my Java journey — OOP concepts! (Part 1) Today I explored Object Oriented Programming — the heart of Java! 🫀 ⚙️ Method Overloading ✅Same Class, Same method name, different parameters ✅ Example: add(int a, int b) ,add(int a, int b,int c) and add(double a, double b) ✅ Decided at compile time ✅Socho ek calculator hai — add button ek hi hai lekin tum 2 number bhi jod sakte ho, 3 number bhi! Same naam, alag parameter! 🔁 Method Overriding ✅ Child class redefines parent class method ✅ Same name, same parameters — different behaviour ✅ Decided at runtime — this is polymorphism! ✅Method Overriding — Child apna kaam khud karta hai ✅(Socho Papa kehte hain "khana khao" — matlab roti khao. Lekin beta kehta hai "khana khao" — matlab pizza khao! Same baat, alag matlab! ) ✅child apne papa ka kaam badal deta hai 🔑 this keyword ✅ Refers to the current object inside a class ✅ Used to avoid confusion between class variables and method parameters ✅this — "Main khud hoon(Intense variable,method and constructor )" 👨👩👦 super keyword ✅ Used to call parent class methods or constructor ✅ super() calls parent constructor ✅ super.methodName() calls parent method ✅ super — "Mere papa hain(parent Class)" 🧬 Inheritance ✅ Child class inherits properties and methods from parent class ✅ Single inheritance — one parent, one child ✅ Multiple inheritance via interfaces (Java does not allow multiple class inheritance directly) 💉 Dependency Injection(DI) ✅ Instead of creating objects inside a class, we pass them from outside ✅ Makes code flexible, testable and clean ✅ Used heavily in Spring Boot (next goal!) Socho tumhara ek Car hai. Car ko Engine chahiye. ✅Bina DI: Car khud engine banati hai andar — agar engine badlani ho toh poori car todna padega! ✅DI ke saath: Engine bahar se car mein daali jaati hai — engine badlo, car wahi rehti hai! ✅Galat tarika — tightly coupled ✅cheez bahar se do, andar mat banao OOP is not finished yet — Day 4 will cover more! 🔥 Day 1 ✅ | Day 2 ✅ | Day 3 ✅ | Day 4 coming... If you are on a similar Java journey, connect with me! 🙏 #Java #JavaDeveloper #OOP #ObjectOrientedProgramming #Inheritance #Polymorphism #DependencyInjection #100DaysOfCode #BackendDevelopment #TechCareer
To view or add a comment, sign in
-
🚀 Ever wondered what really happens when your Java code runs? 🤔 Let’s peel back the layers and uncover the deterministic, and highly optimized execution flow of Java code—because understanding this isn’t just academic, it’s transformational for writing efficient systems. 🔍 1. Compilation: From Human Logic to Bytecode When you write Java code, the javac compiler doesn’t convert it directly into machine code. Instead, it produces platform-independent bytecode. 👉 This is where Java’s "Write Once, Run Anywhere" promise begins—clean, structured, and universally interpretable instructions. ⚙️ 2. Class Loading: Dynamic & Lazy The ClassLoader subsystem kicks in at runtime, loading classes on demand—not all at once. This involves three precise phases: Loading → Bytecode enters memory Linking → Verification, preparation, resolution Initialization → Static variables & blocks executed 💡 This lazy loading mechanism is what makes Java incredibly memory-efficient and modular. 🧠 3. Bytecode Verification: Security First Before execution, the JVM performs rigorous bytecode verification. It ensures: No illegal memory access Proper type usage Stack integrity 👉 This step is Java’s silent guardian, preventing malicious or unstable code execution. 🔄 4. Execution Engine: Interpretation vs JIT Compilation Here’s where things get fascinating. The JVM uses: Interpreter → Executes bytecode line-by-line (fast startup) JIT Compiler (Just-In-Time) → Converts hot code paths into native machine code 🔥 The result? A hybrid execution model that balances startup speed with runtime performance. 🧩 5. Runtime Data Areas: Structured Memory Management Java doesn’t just run code—it orchestrates memory intelligently: Heap → Objects & dynamic allocation Stack → Method calls & local variables Method Area → Class metadata PC Register & Native Stack → Execution tracking 💡 This segmentation ensures predictable performance and scalability. ♻️ 6. Garbage Collection: Autonomous Memory Reclamation Java eliminates manual memory management with sophisticated garbage collectors. From Mark-and-Sweep to G1 and ZGC, the JVM continuously: Identifies unused objects Reclaims memory Optimizes allocation 👉 This results in robust, leak-resistant applications with minimal developer intervention. 💥 Why This Matters Understanding this flow isn’t just theoretical—it empowers you to: ✔ Write high-performance code ✔ Diagnose memory and latency issues ✔ Leverage JVM optimizations effectively 🔥 Java isn’t just a language—it’s a meticulously engineered execution ecosystem. So next time you run a .java file, ask yourself: 👉 Am I just coding… or truly understanding the machine beneath? #Java #JVM #Programming #SoftwareEngineering #Performance #Developers #TechInsights
To view or add a comment, sign in
-
-
Basic Java Interview Q&A ✅ 1. What is Java? Java is a high-level, object-oriented, platform-independent programming language. Its “Write Once, Run Anywhere” principle is powered by the Java Virtual Machine (JVM). ✅ 2. Key Features of Java Simple & Secure Object-Oriented Platform Independent (via JVM) Robust & Multithreaded High Performance (with JIT Compiler) ✅ 3. Difference Between JDK, JRE, and JVM JDK (Java Development Kit) → Includes compiler, tools, and JRE. JRE (Java Runtime Environment) → Contains JVM + core libraries. JVM (Java Virtual Machine) → Executes bytecode, platform-dependent. ✅ 4. Four OOP Principles in Java Encapsulation → Data hiding through classes. Inheritance → Reuse properties and methods. Polymorphism → One interface, multiple implementations. Abstraction → Hide implementation details, expose essential features. ✅ 5. Difference Between == and .equals() == → Compares memory references. .equals() → Compares actual values or content. ✅ 6. What is String Immutability? Strings in Java are immutable, meaning once created, they cannot be changed. Any modification results in a new String object in the memory pool. ✅ 7. What is the difference between Array and ArrayList? Array → Fixed size, can store primitives & objects ArrayList → Dynamic size, only stores objects, part of Collections framework ✅ 8. Types of Access Modifiers public → Accessible from anywhere. protected → Accessible within the same package and subclasses. default → Accessible only within the package. private → Accessible only within the same class. ✅ 9. What is Exception Handling? A mechanism to handle runtime errors using keywords: try, catch, finally, throw, and throws. ✅ 10. Checked vs. Unchecked Exceptions Checked → Compile-time (e.g., IOException, SQLException). Unchecked → Runtime (e.g., NullPointerException, ArithmeticException). ✅ 11. What is Garbage Collection? Automatic memory management that removes unused objects from the heap to free memory space. ✅ 12. What is the difference between Overloading and Overriding? Overloading → Same method name, different parameters (Compile-time polymorphism) Overriding → Subclass redefines parent class method (Runtime polymorphism) Follow Programming [Assignment-Project-Coursework-Exam-Report] Helper For Students | Agencies | Companies for more #Java #JavaInterview #CoreJava #OOP #BackendDevelopment #JavaProgramming #CodingInterview #100DaysOfCode
To view or add a comment, sign in
-
Standard Signature of main() Method in Java In every programming language there must be an entry point of execution from where program execution begins. In C/C++, the entry point is the main() function, which is invoked by the Operating System. OS expects 0 as exit status indicating successful program execution so the return type of main is commonly int. In Java, the entry point is also the main() method, but it is invoked by the Java Virtual Machine (JVM) instead of the OS. Since the JVM handles execution internally, there is no need to return a status code, therefore the return type of the main method is always void. In Java, every method belongs to a class, so the main method must be defined inside a class. Example: class Main { void main() { // code } } However, this method cannot be executed by the JVM because it is not accessible outside the class. To allow the JVM to access it, the method must be declared public. class Main { public void main() { // code } } In Java, methods normally belong to objects and are invoked using an object reference. If the main method were not static, the JVM would have to create an object of the class before calling it. Since main is the entry point of every program, this would add unnecessary overhead. To allow the JVM to invoke the method without creating an object, the main method is declared static. class Main { public static void main() { // code } } But this method still cannot receive data from the command line arguments. To accept input from the command line during program execution, the main method takes a parameter which is an array of strings. Each element of this array represents one argument passed from the command line. Final standard signature of the main method: class Main { public static void main(String[] args) { // code } } Here: public → allows the JVM to access the method static → allows the JVM to call the method without creating an object void → no return value required String[] args → receives command line arguments However, for a beginner writing "public static void main(String[] args)" is overwhelming. So Java developer decided to introduce simplified syntax for new comer to maintain language acceptance and popularity among all. In newer Java versions, we can write a simpler program like: void main() { System.out.println("Hello"); } Introduced in JDK 21 and finally accepted in JDK 25 (2025). The compiler automatically wraps this into a class behind the scenes. However, this feature is mainly designed for learning and small scripts, while the traditional main method remains the standard approach used in real applications. Grateful to my mentor Syed Zabi Ulla for explaining these concepts so clearly and helping me build a strong foundation in programming. #OOP #Java #Programming #ComputerScience #LearningJourney #SoftwareDevelopment
To view or add a comment, sign in
-
🔥 Core Java (Must Prepare) 1. What is the difference between == and .equals()? == → compares reference (memory location) .equals() → compares content/value 2. Why String is immutable? Security (used in DB, network, etc.) Thread-safe String pool optimization 3. What is String Pool? A memory area in heap where unique String literals are stored. Avoids duplicate objects → improves performance 4. Difference: ArrayList vs LinkedList FeatureArrayListLinkedListStructureDynamic ArrayDoubly Linked ListAccessFastSlowInsert/DeleteSlowFast 5. How HashMap works internally? Uses hashing (hashCode + equals) Stores data in buckets Collision handled using: LinkedList (Java 7) Tree (Java 8 → Balanced Tree) 6. Difference: HashMap vs ConcurrentHashMap HashMap → not thread-safe ConcurrentHashMap → thread-safe (segment locking / CAS) 🔥 OOP & Design 7. What are OOP principles? Encapsulation Inheritance Polymorphism Abstraction 8. Method Overloading vs Overriding Overloading → same method name, different parameters Overriding → runtime polymorphism (same method in subclass) 9. What is SOLID principle? S → Single Responsibility O → Open/Closed L → Liskov Substitution I → Interface Segregation D → Dependency Injection 🔥 Multithreading (VERY IMPORTANT) 10. What is Thread? Lightweight process for parallel execution 11. Runnable vs Callable Runnable → no return Callable → returns value + throws exception 12. What is Synchronization? Prevents multiple threads accessing same resource 13. What is Deadlock? When threads are waiting on each other forever 14. What is Executor Framework? Manages thread pool → improves performance 15. What is volatile keyword? Ensures visibility of changes across threads 🔥 Java 8+ (VERY IMPORTANT) 16. What is Lambda Expression? Short way to write functional code (list) -> list.size() 17. What is Functional Interface? Interface with one abstract method Example: Runnable 18. Stream API? Used for data processing (filter, map, reduce) 19. Optional class? Avoids NullPointerException 🔥 Exception Handling 20. Checked vs Unchecked Exception Checked → compile-time (IOException) Unchecked → runtime (NullPointerException) 21. Difference: throw vs throws throw → used to throw exception throws → declares exception 🔥 Memory & JVM 22. What is JVM? Executes Java bytecode 23. Heap vs Stack Heap → Objects Stack → Method calls, variables 24. What is Garbage Collection? Automatically removes unused objects 🔥 Advanced (4+ Year Level) 25. What is Serialization? Convert object → byte stream 26. transient keyword? Skips variable during serialization 27. Comparable vs Comparator Comparable → natural sorting Comparator → custom sorting 28. Fail-fast vs Fail-safe Fail-fast → throws exception (ArrayList) Fail-safe → works on copy (ConcurrentHashMap) 🔥 Real Interview Scenario Questions 29. How do you handle high traffic in Java? Caching (Redis) Thread pool Load balancing 30. How do you debug production issue? Logs (ELK) Thread dump Heap dump
To view or add a comment, sign in
-
🚀 Mastering Java Stream API – Write Cleaner, Smarter Code If you're still writing verbose loops in Java, it's time to rethink your approach. The Stream API (introduced in Java 8) is not just a feature—it’s a paradigm shift toward functional-style programming in Java. It allows you to process collections of data in a declarative, concise, and efficient way. 🔍 What is Stream API? A Stream is a sequence of elements that supports various operations to perform computations. Unlike collections, streams: Don’t store data Are immutable (operations don’t modify the source) Support lazy evaluation Enable parallel processing effortlessly ⚙️ Core Concepts 1. Stream Creation List<String> names = Arrays.asList("John", "Jane", "Jack"); Stream<String> stream = names.stream(); 2. Intermediate Operations (Lazy) filter() map() sorted() These return another stream and are not executed until a terminal operation is invoked. names.stream() .filter(name -> name.startsWith("J")) .map(String::toUpperCase); 3. Terminal Operations (Trigger Execution) forEach() collect() count() List<String> result = names.stream() .filter(name -> name.length() > 3) .collect(Collectors.toList()); 💡 Why Use Stream API? ✅ Readable & Declarative Code Focus on what to do, not how to do it ✅ Less Boilerplate Goodbye nested loops ✅ Parallel Processing names.parallelStream().forEach(System.out::println); ✅ Functional Programming Power Lambdas + Streams = Clean pipelines 🔥 Real-World Example Traditional Approach List<String> filtered = new ArrayList<>(); for (String name : names) { if (name.length() > 3) { filtered.add(name.toUpperCase()); } } Stream API Approach List<String> filtered = names.stream() .filter(name -> name.length() > 3) .map(String::toUpperCase) .collect(Collectors.toList()); 👉 Less code. More clarity. Better maintainability. ⚠️ Common Pitfalls Overusing streams can hurt readability Avoid complex nested streams Be cautious with parallel streams (thread-safety matters) 🧠 Pro Tip Think of streams as a data pipeline: Source → Intermediate Operations → Terminal Operation 📌 Final Thoughts The Stream API is a must-have skill for modern Java developers. It helps you write clean, scalable, and expressive code, especially in microservices and data-heavy applications. If you're building backend systems with Java, mastering streams is not optional—it's essential. 💬 How often do you use Stream API in your projects? Any advanced patterns you rely on? #Java #StreamAPI #BackendDevelopment #Java8 #CleanCode #FunctionalProgramming #SoftwareEngineering
To view or add a comment, sign in
-
Hii everyone, Sharing some commonly asked Java interview questions for practice: 1. Why is Java a platform independent language? 2.Why is Java not a pure object oriented language? 3.Tell us something about JIT compiler. 4. Can you tell the difference between equals() method and equality operator (==) in Java? 5.Briefly explain the concept of constructor overloading 5.Define Copy constructor in java. 6.Can the main method be Overloaded.how? 7.Explain the use of final keyword in variable, method and class 8.Do final, finally and finalize keywords have the same function? 9. When can you use super keyword and this keyword? 10. Why is the main method static in Java? 11.. Can the static methods be overridden? 13.Difference between static methods, static variables, and static classes in java. 14.What is a ClassLoader Explain its types? 15.How would you differentiate between a String, StringBuffer, and a StringBuilder? 16.Why string is immutable? 17.What do you understand by class and object? Also, give example. 18.What are the characteristics of an abstract class? 19.What is composition? 20.What is Coupling in OOP and why it is helpful? 21.Explain overloading and overriding with example? 22.Give a real-world example of polymorphism? 23.What is inheritance explain its type? 24.EXplain Encapsulation? 25.What are the differences between error and exception? 26. Using relevant properties highlight the differences between interfaces and abstract classes. 27.type of exception explain it? 28.Different bw throw and throws? 29.What are the differences between HashMap and HashTable in Java? 30.What makes a HashSet different from a TreeSet? 31.Java works as “pass by value” or “pass by reference” phenomenon? 32.Different bw ISA relationship HAS a Relationship? 33. Will the finally block get executed when the return statement is written at the end of try block and catch block as shown below? 34. Explain various interfaces used in Collection framework? 35.What is the difference between ArrayList and LinkedList? 36.What is the difference between List and Set? 37.What is the difference between Comparable and Comparator? 38. How to remove duplicates from ArrayList? 39.HashMap internal works? 40.Can you explain the Java thread lifecycle? 41. What do you understand by marker interfaces in Java? 42.types of memory in java? 43.Why is multiple inheritance not supported in java? 44.Can we override the private methods? 45.What is the difference between compile-time polymorphism and runtime polymorphism? 46.What is exception propagation? 47.volatile keyword? 48.dead lock? 49.Synchronization in java? 50.what is HashMap and weak HashMap? 51.diff b/w jdk jre jvm? 52.what is sterilization and deserialization? 53.diff HashMap and hash table? 54.wrapper class in java?
To view or add a comment, sign in
-
Why does Java let you write short s = 'a' without a cast? And why do long, float, and double need suffix letters (L, F, D) but byte, short, and char don't? Most Java developers use these rules daily without thinking about them. But if you're preparing for the OCP, this is the kind of detail that shows up in tricky questions. Let's break it down. Every numeric literal in Java has a default type: -> Integer literals like 42 default to int -> Decimal literals like 3.14 default to double That's the starting point for everything. When you need a type LARGER than the default or from a DIFFERENT family, you must tell the compiler explicitly with a suffix: long l = 2147483648L; // Without L, this overflows int float f = 3.14f; // Without f, 3.14 is double and narrowing fails The compiler can't guess your intent here, so the suffix is mandatory. But when you need a type SMALLER than int (byte, short, char), something different happens: narrowing constant assignment. The compiler sees the literal, checks its value at compile time, and if it fits in the target type, it allows the assignment automatically: byte b = 42; // 42 fits in byte (-128 to 127) -> OK short s = 'a'; // 'a' is 97, fits in short -> OK char c = 65; // 65 fits in char (0 to 65535) -> OK No cast needed. No suffix needed. But this ONLY works with compile-time constants. The moment you use a variable, the compiler loses that guarantee: int x = 42; byte b = x; // COMPILATION ERROR - x is not a constant Even though 42 obviously fits in a byte, the compiler doesn't track variable values, only constant expressions. Quick summary: -> Suffixes (L, F, D) = promote UP or switch type family -> Narrowing constants = compiler handles DOWN automatically -> Variables break the magic = cast required OCP Tip: Watch for questions mixing char literals with numeric types. Remember that 'a' is just 97 to the compiler, and narrowing rules apply the same way as with integer literals. Also watch for final variables: final int x = 42; byte b = x; compiles because final makes x a constant expression again. This is defined in JLS Section 5.2 (Assignment Contexts) and it's a recurring topic in OCP 21 certification exams. Have you encountered tricky narrowing questions in your Java certification prep? Share your experience below. 📊 Java Language Specification - JLS 5.2 Assignment Contexts (2023) https://lnkd.in/e3GDH9rw 📊 OCP Oracle Certified Professional Java SE 21 Developer Study Guide - Boyarsky & Selikoff (2024) 📊 Java Language Specification - JLS 15.29 Constant Expressions (2023) https://lnkd.in/eM_DnGYT #Java #OCP21 #JavaDeveloper #SoftwareEngineering #JavaCertification #BackendDevelopment #CodingTips #Programming
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