@@ -33,25 +33,14 @@ Available in the resources for the course
3333- ** 1 . Why is Java so popular?**
3434 - Java is popular for several reasons:
3535
36- -
37- 1. **Platform Independence**: Java programs can run on any device that has the Java Virtual Machine (JVM),
38- making it
39- highly portable.
40- -
41- 2. **Object-Oriented**: Java's object-oriented nature allows for modular programs and reusable code.
42- -
43- 3. **Robust and Secure**: Java has strong memory management, exception handling, and security features.
44- -
45- 4. **Rich API**: Java provides a vast standard library that simplifies many programming tasks.
46- -
47- 5. **Community Support**: Java has a large and active community, providing extensive resources and support.
48- -
49- 6. **Performance**: Java's performance has improved significantly with Just-In-Time (JIT) compilers and
50- other
51- optimizations.
52- -
53- 7. **Enterprise Use**: Java is widely used in enterprise environments, particularly for server-side
54- applications.
36+ 1. **Platform Independence**: Java programs can run on any device that has the Java Virtual Machine (JVM),
37+ making it highly portable.
38+ 2. **Object-Oriented**: Java's object-oriented nature allows for modular programs and reusable code.
39+ 3. **Robust and Secure**: Java has strong memory management, exception handling, and security features.
40+ 4. **Rich API**: Java provides a vast standard library that simplifies many programming tasks.
41+ 5. **Community Support**: Java has a large and active community, providing extensive resources and support.
42+ 6. **Performance**: Java's performance has improved significantly with Just-In-Time (JIT) compilers and other optimizations.
43+ 7. **Enterprise Use**: Java is widely used in enterprise environments, particularly for server-side applications.
5544- ** 2 . What is platform independence?**
5645 Platform independence refers to the ability of a programming language or software to run on various types of computer
5746 systems without modification. In the context of Java, platform independence is achieved through the use of the Java
@@ -143,27 +132,25 @@ Available in the resources for the course
143132 The two ways of creating Wrapper class instances in Java are using constructors and using static factory methods. Here
144133 are the differences:
145134
146- -
147- 1. **Using Constructors**:
148- Each wrapper class has a constructor that takes a primitive type or a `String` as an argument. \
149- Example:
150- ```java
151- Integer intObj1 = new Integer(10);
152- Integer intObj2 = new Integer("10");
153- ```
154- -
155- 2. **Using Static Factory Methods**:
156- Wrapper classes provide static factory methods like `valueOf` to create instances.\
157- Example:
158- ```java
159- Integer intObj1 = Integer.valueOf(10);
160- Integer intObj2 = Integer.valueOf("10");
161- ```
135+ 1. **Using Constructors**:
136+ Each wrapper class has a constructor that takes a primitive type or a `String` as an argument. \
137+ Example:
138+ ```java
139+ Integer intObj1 = new Integer(10);
140+ Integer intObj2 = new Integer("10");
141+ ```
142+ 2. **Using Static Factory Methods**:
143+ Wrapper classes provide static factory methods like `valueOf` to create instances.\
144+ Example:
145+ ```java
146+ Integer intObj1 = Integer.valueOf(10);
147+ Integer intObj2 = Integer.valueOf("10");
148+ ```
162149 **Differences**:
163- - **Performance**: Static factory methods are generally preferred over constructors because they can cache
164- frequently requested values, improving performance.
165- - **Readability**: Using `valueOf` is often more readable and expressive.
166- - **Deprecation**: Some constructors in wrapper classes are deprecated in favor of static factory methods.
150+ - **Performance**: Static factory methods are generally preferred over constructors because they can cache
151+ frequently requested values, improving performance.
152+ - **Readability**: Using `valueOf` is often more readable and expressive.
153+ - **Deprecation**: Some constructors in wrapper classes are deprecated in favor of static factory methods.
167154- **11 . What is auto boxing?**
168155 Autoboxing in Java is the automatic conversion that the Java compiler makes between the primitive types and their
169156 corresponding object wrapper classes. For example, converting an `int` to an `Integer`, a `double` to a `Double`, and
@@ -495,21 +482,21 @@ Available in the resources for the course
495482 - `Dog` is the subclass that inherits the `eat()` method from `Animal` and also has its own method `bark()`.
496483 - In the `Main` class, an instance of `Dog` can call both `eat()` and `bark()` methods.
497484
498- - **33 . What is method overloading?**
485+ - **33. What is method overloading?**
499486 Method overloading in Java is a feature that allows a class to have more than one method with the same name, provided
500487 their parameter lists are different. This means that the methods must differ in the type, number, or order of their
501488 parameters. Method overloading is a compile-time polymorphism technique, enabling different methods to perform similar
502489 operations with varying inputs. It enhances code readability and reusability by allowing the same method name to be
503490 used for different tasks, based on the arguments passed. Overloaded methods can have different return types, but this
504491 alone is not enough for overloading; the parameter list must be different.
505- - **34 . What is method overriding?**
492+ - **34. What is method overriding?**
506493 Method overriding in Java is a feature that allows a subclass to provide a specific implementation of a method that is
507494 already provided by its superclass. When a method in a subclass has the same name, return type, and parameters as a
508495 method in its superclass, it is said to override the superclass method . Method overriding is a runtime polymorphism
509496 technique, enabling a subclass to provide its own implementation of a method inherited from a superclass. This allows
510497 for more specific behavior to be defined in the subclass, while still maintaining a common interface with the
511498 superclass. Method overriding is used to achieve dynamic polymorphism in Java.
512- - **35 . Can super class reference variable can hold an object of sub class?**
499+ - **35. Can super class reference variable can hold an object of sub class?**
513500 Yes, a superclass reference variable can hold an object of a subclass in Java. This is known as polymorphism and is a
514501 key feature of object-oriented programming. When a superclass reference variable holds an object of a subclass, it can
515502 only access the methods and fields that are defined in the superclass. If the subclass has additional methods or
@@ -2710,24 +2697,27 @@ public class Dog implements Animal {
27102697 ```java
27112698 import java.io.*;
27122699
2700+ @Slf4j
27132701 public class Main {
27142702 public static void main (String [] args ) {
27152703 try (ObjectOutputStream out = new ObjectOutputStream (new FileOutputStream (" object.ser" ))) {
27162704 Parent parent = new Parent ();
27172705 parent. child = new Child ();
27182706 out. writeObject(parent);
27192707 } catch (IOException e) {
2720- e . printStackTrace( );
2708+ log . error( " Error serializing object " , e );
27212709 }
27222710 }
27232711 }
27242712
27252713 class Parent implements Serializable {
2714+ @Serial
27262715 private static final long serialVersionUID = 1L ;
27272716 Child child;
27282717 }
27292718
27302719 class Child implements Serializable {
2720+ @Serial
27312721 private static final long serialVersionUID = 1L ;
27322722 }
27332723 ```
@@ -3945,10 +3935,10 @@ public class Dog implements Animal {
39453935 allowing them to run concurrently and perform tasks in parallel.
39463936
39473937 Some key reasons for using threads in Java include:
3948- - ** Concurrency ** : Threads enable multiple tasks to be executed concurrently, improving performance and
3938+ - ** Concurrency ** : threads enable multiple tasks to be executed concurrently, improving performance and
39493939 responsiveness
39503940 of applications.
3951- - ** Parallelism ** : Threads allow tasks to be executed
3941+ - ** Parallelism ** : threads allow tasks to be executed
39523942- ** 186 . How do you create a thread? ** \
39533943 There are two main ways to create a thread in Java :
39543944 - ** Extending the `Thread ` class** : You can create a thread by extending the `Thread ` class and overriding the
0 commit comments