Ways to Create an Object in Java (new, clone, Reflection, Deserialization) | BearStack
BearStack
0:00 / 0:00
Ways to Create an Object in Java (new, clone, Reflection, Deserialization) | BearStack
44 просмотра · 8 дн. назад
BearStack
18 подписчиков
44 просмотра · 8 дн. назад
How many ways can you create an object in Java? If you only say the "new" keyword in a Java interview, you're missing out!
In this video, we break down the 4 different ways to create an object in Java with a practical, step-by-step code example in Eclipse—and see which methods actually call the class constructor and which ones create a brand-new object in memory WITHOUT invoking the constructor!
💻 Source Code on GitHub:
https://github.com/bearStack-beer/Jav...
📌 What You'll Learn in This Video:
1️⃣ Creating an object using the `new` keyword (Calls Constructor)
2️⃣ Creating an object using `Object.clone()` and the `Cloneable` marker interface (No Constructor called!)
3️⃣ Creating an object dynamically using the Java Reflection API (`getDeclaredConstructor().newInstance()`)
4️⃣ Creating an object using Deserialization (`Serializable` & `ObjectInputStream`) (No Constructor called!)
🔔 Subscribe to BearStack for more Core Java tutorials, coding interview questions, and backend engineering breakdowns!
💬 Drop a comment below: Which Java interview topic should we cover next?
#Java #CoreJava #JavaInterviewQuestions #JavaProgramming #ObjectOrientedProgramming #CodingInterview #SpringFramework #LearnJava #BearStack