418
Subscribers
No data24 hours
-27 days
+1230 days
Posts Archive
When is static block run?
Static blocks in Java are executed when the class is loaded into memory by the class loader. They are used to initialize static variables or perform any necessary setup tasks before the class is used.
Introduced:
Static blocks have been a part of Java since its early versions. They offer a mechanism to execute code when a class is loaded into memory by the class loader, allowing for initialization tasks to be performed before the class is used.
Issues:
Static blocks can't handle exceptions directly, so any exception thrown during their execution must be caught within the block or propagated outwards. Additionally, they can make code less readable and harder to maintain if used excessively.
Benefits:
Static blocks provide a way to initialize static variables or perform complex initialization tasks that can't be achieved through simple variable assignment. They ensure that initialization is performed only once, regardless of how many times the class is instantiated.
Conclusion:
Despite their limitations, static blocks remain a fundamental feature in Java, offering a means to execute initialization tasks at class loading time. While they may introduce complexity and require careful handling of exceptions, they provide valuable functionality for initializing static variables and performing necessary setup tasks. Overall, static blocks play an important role in Java programming, aiding in the efficient and effective initialization of classes and their associated resources.
Q. Default package of Java
The java.lang package is often considered the default package in Java because it is automatically imported into every Java program. It contains fundamental classes and interfaces that are essential for basic functionality in Java, such as Object, String, and System.
https://t.me/+eCZdcsd-ofJkYTc1
Join first 200 members
Spring boot Course
ââ
Q. What is java heap?
â˘â˘The Java heap is a portion of memory allocated to the Java Virtual Machine (JVM) for storing objects created by Java applications during runtime.
â˘â˘It's where objects are dynamically allocated and managed by the JVM's garbage collector.
â˘â˘This memory area is distinct from the stack, which is used for storing method call frames and local variables.
â˘â˘The heap size can be adjusted using JVM options to optimize performance for different types of applications.
What is the finalize () method in java
The finalize() method in Java is a special method that is automatically called by the garbage collector before an object is reclaimed. It's used for performing cleanup operations or releasing resources associated with the object before it's garbage collected.
Evolution of finalize() in Java
Intro: finalize()- a method in Java for performing cleanup operations before object reclamation.
Introduced: finalize() introduced early in Java's history for resource management.
Usage: Used to release resources or perform cleanup tasks.
Issues: Inefficient, unreliable, and not guaranteed to be called promptly.
Java 9: Deprecated finalize() method in Java 9.
Recommendation: Replace finalize() with try-with-resources or other cleanup mechanisms.
Conclusion: The deprecation of finalize() encourages more reliable and efficient resource management practices in Java.
5 Min Learn â
How to become a better software developer:
1. Admit you don't know it all
2. Practice, practice, practice
3. Take every opportunity to learn
4. Accept your peers as a valuable source of knowledge
5. Embrace failure as a way to grow
What is PermGen in java
PermGen, or Permanent Generation, is a part of the Java heap memory that is used to store class metadata, method information, and other reflective data. However, it was removed in Java 8 and replaced with Metaspace.
Evolution of PermGen in Java
Intro: PermGen - a memory section in Java storing class metadata.
Introduced: PermGen introduced in early versions of Java.
Issues: Limited size caused OutOfMemoryErrors in heavy applications.
Java 8: PermGen removed in Java 8.
Replacement: Metaspace introduced in Java 8.
Benefits: Metaspace dynamically resizes, avoiding memory errors.
Conclusion: PermGen's removal in Java 8 led to more flexible memory management with Metaspace.
Learn â
Typical java interview questions sorted by experience
Junior
* Name some of the characteristics of OO programming languages
* What are the access modifiers you know? What does each one do?
* What is the difference between overriding and overloading a method in Java?
* Whatâs the difference between an Interface and an abstract class?
* Can an Interface extend another Interface?
* What does the static word mean in Java?
* Can a static method be overridden in Java?
* What is Polymorphism? What about Inheritance?
* Can a constructor be inherited?
* Do objects get passed by reference or value in Java? Elaborate on that.
* Whatâs the difference between using == and .equals on a string?
* What is the hashCode() and equals() used for?
* What does the interface Serializable do? What about Parcelable in Android?
* Why are Array and ArrayList different? When would you use each?
* Whatâs the difference between an Integer and int?
* What is a ThreadPool? Is it better than using several âsimpleâ threads?
* What the difference between local, instance and class variables?
Mid
* What is reflection?
* What is dependency injection? Can you name a few libraries? (Have you used any?)
* What are strong, soft and weak references in Java?
* What does the keyword synchronized mean?
* Can you have âmemory leaksâ on Java?
* Do you need to set references to null on Java/Android?
* What does it means to say that a String is immutable?
* What are transient and volatile modifiers?
* What is the finalize() method?
* How does the try{} finally{} works?
* What is the difference between instantiation and initialisation of an object?
* When is a static block run?
* Why are Generics are used in Java?
* Can you mention the design patterns you know? Which of those do you normally use?
* Can you mention some types of testing you know?
Senior
* How does Integer.parseInt() works?
* Do you know what is the âdouble check lockingâ problem?
* Do you know the difference between StringBuffer and StringBuilder?
* How is a StringBuilder implemented to avoid the immutable string allocation problem?
* What does Class.forName method do?
* What is Autoboxing and Unboxing?
* Whatâs the difference between an Enumeration and an Iterator?
* What is the difference between fail-fast and fail safe in Java?
* What is PermGen in Java?
* What is a Java priority queue?
* *s performance influenced by using the same number in different types: Int, Double and Float?
* What is the Java Heap?
* What is daemon thread?
* Can a dead thread be restarted?
Source: medium.
What was the original name of Java before it was renamed due to trademark issues?
https://youtube.com/shorts/0hujZkJ9ZwA?si=9cyC0thzRinAsQeC
*
*
*
*
*
comment down Correct Answer
*
*
*
*
*
*
