5 JAVA ERRORS you should learn today ( NoClassDefFoundError) | JVM architecture - ClassLoader

Опубликовано: 09 Октябрь 2024
на канале: Selenium Express
6,405
259

An important java interview question is “ how classes loaded into the memory by the java class loader “. An interviewer further may ask the difference between static vs dynamic class loading in java. But if you are an experienced java developer, there may be multiple questions could be asked on an error called NoClassDefFoundError. The NoClassDefFoundError and ClassNotFoundError are very common in any java application but the scenarios where they occurs makes them tricky to catch and debug, because there are a lot of associated errors exists.eg : ExceptionIninitializerError , LinkageError , NoSuchMethodError etc. Learning about these errors surely helps a java developer to become more efficient while coding.

Timestamp
——————
00:00:00 - Intro
00:02:50 - NoClassDefFoundError
00:06:37 - java bytecode ( javac )
00:08:41 - static class loading ( new keyword )
00:11:56 - a static block in java
00:14:43 - class loading during inheritance
00:15:22 - ExceptionIninitializerError
00:18:00 - JVM architecture - Class Loader subsystems
00:19:47 - Application Class Loader
00:21:50 - Linking Vs Initialization
00:26:45 - Static class loading during Association
00:29:58 - Java Errors , Throwable and Exception Handling
00:35:07 - NoClassDefFoundError & ExceptionIninitializerError : A sweet relationship
00:39:18 - Java linkage error example
00:42:29 - java.lang.noclassdeffounderror [ Missing dependency ]
00:56:44 - java.lang.noclassdeffounderror [ Spring framework jar conflict ]
01:06:08 - nosuchmethoderror in java
01:11:03 - dynamic class loading java
01:12:38 - static class loading advantages
01:13:54 - ClassNotFoundError
01:17:32 - When dynamic class loading should be used
01:21:24 - newIntance() deprecated method alternative
01:23:33 - Outro

NoClassDefFoundError
——————
NoClassDefFoundError Occurs if the classloader attempts to load the class definition , but that could not be found. It is also possible that if Jvm / class loader already attempted to load the class before, but could not do so because of a static block / variable failure ( exceptionininitializererror). In that case , if you try to initialise the same class again and try to load it , that could result into a NoClassDefFoundError. This occurs as the jvm assumes that as the class loading failed earlier and resulted into a exceptionininitializererror, if it tries to load the class again it should fail. That’s why it directly throws a NoClassDefFoundError.

The NoClassDefFoundError occurs during the static class loading it’s absolutely wrong to thing that this error only occurs if the .class file is missing.

ClassNotFoundError
—————————
When we try to load a class dynamically during runtime and if the class definition is not available to the runtime system, in that case the ClassNotFoundError exception is thrown. We use the class.forName() method to load a class in runtime and forName() throws a ClassNotFoundError as a checked exception.


linkageerror
———————
When the class loaded to the memory, it goes through a linking process where the .class files are verified, the static blocks are initialised and method references are resolved. If any of these fails, it results a linkage error.

NoSuchMethodError
——————————-
When we compile our code, .class files are generated which further loaded to the memory during the runtime. But imagine a scenario when you build and generate your .class files using an older version a jar but during runtime , a newer version of the same jar is available. There is a high possibility is that the methods which were available in the previous version of a class is missing or changed in the current version so the linking couldn’t be happen during the runtime. This can result a NoSuchMethodError.

For more free/paid courses visit
https://www.seleniumexpress.com

LINKS AND FREE LEARNING RESOURCES
========
Watch my new mock interview series for java developers
   • Java interview questions and answers ...  

Watch my new Hello spring boot series
   • Spring Vs Spring Boot - Why Spring Bo...  

Watch Spring boot Hot topics
   • @Reposicotry Vs @Service | Spring Boo...  

spring core
   • Spring framework tutorial for beginne...  

spring mvc
   • Spring MVC course introduction || Und...  

spring mvc intermediate
   • [INTERMEDIATE] Spring MVC Course Prev...  

Spring JDBC
   • Spring JDBC Course Preview || Let’s t...  

SPRING SECURITY COURSE[NEW]
   • Spring Security Course Preview | Lear...  

Email support : [email protected]

you can ping me on my Facebook page
  / seleniumexpress  

Make sure to join my private Facebook page (Ask me here)
“SeleniumExpress - Support"
  / 187000222361579  

Subscribe to my youtube channel

   / @seleniumexpress  

Follow me on Insta
  / selenium_express