When class loads into JVM? / core java tutorial [w/ subs]



00:00:00 – connecting connecting classes in java
00:00:06 – application how to connect means it's
00:00:09 – very simple accessing accessing one
00:00:13 – class members from one class members
00:00:18 – from another class accessing one class
00:00:22 – members from another class is nothing
00:00:25 – but connecting classes connecting
00:00:29 – classes how can you connect two classes
00:00:32 – in one java application means we need to
00:00:35 – access one class members from another
00:00:38 – class so automatically so those two
00:00:42 – classes will communicate is nothing but
00:00:44 – connecting but remember remember in java
00:00:48 – application in java application unused
00:00:53 – classes and user classes will not be
00:00:58 – loaded into JVM will not be loaded into
00:01:03 – JVM so why means what is the waste of
00:01:06 – memory for example in a java application
00:01:09 – total 10 classes are them and you are
00:01:13 – working with only two classes and
00:01:15 – interaction between those two classes
00:01:17 – only so unnecessarily it will not load
00:01:21 – remaining eight classes into JVM it is a
00:01:23 – burden to JVM unnecessarily it has to
00:01:26 – allocate the memory fast loading process
00:01:29 – and all the things will be for how can
00:01:32 – we prove practically as a programmer as
00:01:35 – a programmer we can analyze we can
00:01:41 – analyze whether whether unused class and
00:01:46 – user class is loading into JVM or not
00:01:50 – only by defining a static block only by
00:01:57 – defining a static block so why so what
00:01:59 – is the reason very simple reason static
00:02:02 – block execute at the time of class
00:02:05 – loading automatically at the time of
00:02:09 – class loading automatically static block
00:02:12 – executed by the J
00:02:13 – so if you define a static block if it
00:02:16 – loads the class unnecessarily this means
00:02:18 – what it will execute the static blow if
00:02:20 – it is not loading unused class so static
00:02:23 – block is not executing see one example
00:02:26 – to understand clearly here here two
00:02:31 – classes we are writing so one is the
00:02:33 – first class one is a first class and one
00:02:36 – is a second class one is the second
00:02:40 – class in a second class we are writing
00:02:42 – one fun method fun method here it is a
00:02:46 – system dot out dot println this is
00:02:50 – second class fun method second class fun
00:02:54 – method and this is the first class main
00:02:56 – method first class main method and here
00:03:00 – it is you can say with any name suppose
00:03:02 – I am giving program dot Java in Java
00:03:06 – program dot Java source fell two classes
00:03:08 – are present first class and second flash
00:03:10 – but we didn't define the static block
00:03:12 – now i am defining one static block
00:03:16 – inside the first clash this is one
00:03:18 – static block here system dot out dot
00:03:23 – println println first class is loading
00:03:29 – first class is loading and the same
00:03:33 – static block we are writing inside the
00:03:36 – second class also inside the second
00:03:40 – flash so here we are writing second
00:03:44 – class is loading foursquare sees loading
00:03:48 – and second class is loading two classes
00:03:52 – I had a fine now so whenever you compile
00:03:56 – the first class file will be generated
00:04:00 – and second class file will be generated
00:04:03 – to class files will be generated first
00:04:06 – dot class and second on stress but what
00:04:09 – I have to run means what so which class
00:04:12 – contains a main method that is the
00:04:14 – starting point that we have to execute
00:04:15 – but look at this whenever I am compiling
00:04:19 – Java C program dot Java is compiled now
00:04:25 – look at this whenever I run
00:04:27 – first look at this only first class is
00:04:30 – loading and first class main method is
00:04:32 – executing second class is not loading
00:04:37 – how can you say that free second class
00:04:39 – is loading message is not printing so
00:04:42 – static block is not executing means was
00:04:45 – class is not loading into JVM because
00:04:50 – you are not using anywhere in the
00:04:52 – application if you use properly if you
00:04:56 – use properly then it will execute then
00:05:00 – it will execute okay see so means what
00:05:04 – suppose from the main method from the
00:05:08 – main method I want to access second
00:05:12 – class fun method I want to access second
00:05:17 – class fun method look at this here Here
00:05:22 – I am calling second class fun method so
00:05:26 – whenever we access the member so then
00:05:29 – only it loads the class it loads the
00:05:34 – class before executing fun method before
00:05:39 – execute fun method so unnecessarily the
00:05:44 – classes will not be loaded in gmail
00:05:47 – application also but if you give only
00:05:51 – gmail.com only login page will be loaded
00:05:54 – in box phase drafts pages will not be
00:05:57 – loaded right whenever you want to enter
00:06:00 – into that inbox face by the time only it
00:06:03 – will know so here here now whenever we
00:06:08 – compile and run compile and now run this
00:06:12 – first now look at this along with the
00:06:15 – first class along with the first class
00:06:18 – and whenever you call a second class fun
00:06:21 – method first to execute the fun method
00:06:24 – class loading is important so first
00:06:26 – class loading process at the time of
00:06:29 – class loading process is a static block
00:06:32 – is executed static block is executing
00:06:37 – and then fun method is calling
00:06:40 – fun method okay so so this is the
00:06:43 – practical example that proves right
00:06:46 – unnecessarily unusual crisis of java
00:06:49 – application will not be loaded into JVM
00:06:53 – and this is how to connect the classes
00:06:56 – in java application


Video Url:
http://youtu.be/-h43OUpzi1w

Comments

comments