Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when java program starts?

Recently have been touched Java classloaders and suddenly recognized that do not fully understand what happens step-by-step when someone calls

java -jar App.jar

Well I guess

  1. a new instance of JVM is created
  2. it uses ClassLoader to load main class and other classes
  3. byte-code is started to execute from main() method

But still I suppose there are many things I need to know more about it.

  • Who and how decides which classes should be loaded at startup and which once needed?

I have found two related questions but there it is not explained how to apply that to Java realities.

What happens when a computer program runs?

What happens when you run a program?

like image 378
Nikolay Kuznetsov Avatar asked Dec 18 '12 06:12

Nikolay Kuznetsov


1 Answers

•Who and how decides which classes should be loaded at startup and which once needed?

we need to understand the fundamentals of java class loading. Initially bootstrap classloader (it is implemented natively as part of the VM itself) is responsible for loading core system classes. Then there are other class loaders as well like Extension, system, user-defined(optional) class loaders which decide when and how classes should be loaded. Fundamentals of class loading

like image 75
vishal_aim Avatar answered Oct 26 '22 22:10

vishal_aim