mixing up many topics together make it look complicated , please make sure create a new class for every new topic you explain in separate eclipse in future for better understanding. thank you so much.
02:55 .. I like the confidence, he knows the answer but plays around viewer thought as when he explain immideatly after that, you can see he knows very well.
when we are using Class.forName("className") to load the class, we need to provide the fully qualified name of the class, including the package name. Then only it will load. Also thanks for the amazing explanations. I check out your videos to quickly revise java concepts for interviews.
Hi @surabhigupta9814 can you please write it down the syntax so that I can get more clarity on it, cause I am facing the exception in Thread. Thank You!
@@yourwishof.11.11 it should be package name.classname example: Class.forName("hello.Mobile"); --> my package name is hello. So by giving like this it resolves error and we get output as : in static block
You always explain what happend and how happens you never explain the real purpose why there was need of that where we are using in the real case. Code will not be remember by anyone.
wow, new courses!! very excited, thank you !!! im a amateur springboot dev, but i still scan through your videoes in this course and watch the ones which i feel i dont have enough knowledge on, and really get to know something new, like the contents of this video, the jvm and classloader explanation. thanks!! youre one of the best educators. PS: the order of static method and static block video is inverted
There are several scenarios where using a static block for initializing a static variable with additional logic or computations may be necessary or beneficial: 1. Initialization based on environment variables: You might need to initialize a static variable based on environment-specific configurations or system properties. In such cases, you may need to read environment variables or system properties and perform validation or transformation before assigning the value to the static variable. 2. Initialization requiring resource loading: If your static variable needs to be initialized with data from an external resource such as a file, database, or network resource, you may use a static block to load and process the resource data before assigning it to the static variable. 3. Dynamic initialization: Sometimes, the initialization value of a static variable may depend on runtime conditions or dynamic calculations. For example, initializing a static variable based on the current timestamp, random number generation, or other dynamic computations might require using a static block. 4. Complex initialization logic: If the initialization logic for a static variable is complex and involves multiple steps or conditions, using a static block can help organize the code and improve readability by separating the initialization logic from the variable declaration.
I don't get it even if i don't call constructor the static should work since static is a class and it does not depend on the object right🤔 Please let me know if I'm wrong in any way.
There are several scenarios where using a static block for initializing a static variable with additional logic or computations may be necessary or beneficial: 1. Initialization based on environment variables: You might need to initialize a static variable based on environment-specific configurations or system properties. In such cases, you may need to read environment variables or system properties and perform validation or transformation before assigning the value to the static variable. 2. Initialization requiring resource loading: If your static variable needs to be initialized with data from an external resource such as a file, database, or network resource, you may use a static block to load and process the resource data before assigning it to the static variable. 3. Dynamic initialization: Sometimes, the initialization value of a static variable may depend on runtime conditions or dynamic calculations. For example, initializing a static variable based on the current timestamp, random number generation, or other dynamic computations might require using a static block. 4. Complex initialization logic: If the initialization logic for a static variable is complex and involves multiple steps or conditions, using a static block can help organize the code and improve readability by separating the initialization logic from the variable declaration.
Understood everything up until now but i don't know why this is giving me headache I am not getting it. It makes code much more organized and easy to edit as all static methods and variables can be in one place and that executes first.
Thank you but you maintion on last video you will show us static method but starting of this video you said Now we know static variable and static method. i did not see a video for static methods
this is very confusing sir ,i didnt understand properly. and the code is not executing after coppying the syntax and the concept class Mobile { static String brand; String name; int price; static { brand = "apple"; System.out.println("in static block"); } public Mobile() { name = "15promax"; price = 189999; System.out.println("non static block"); } public void show() { System.out.println(brand+":"+name+":"+price); } } public class lecture39 { Mobile obj = new Mobile(); obj.name = "15promax"; obj.price = 189999; Mobile.brand = "apple"; Mobile obj1 = new Mobile(); }
But without create object still Static block is running ..Here see this code public class StaticHack { static { System.out.println("Static block"); } StaticHack(){ System.out.println("Constructor"); } public static void main(String[] args) { // StaticHack obj=new StaticHack(); } }
Because your static block is present in class StaticHack which has the main method & this class will obviously be loaded by the class loader and hence the execution of static block.
Hey hi Naveen, I have a small doubt without creating an object i call my static block it's working Example In my class have Class staticConcept{ Static{ S.o.p("hello"); } Static{ S.o.p("hi"); } P s v m (String args[]) { S.o.p("world"); } It's working without creating an object
mixing up many topics together make it look complicated , please make sure create a new class for every new topic you explain in separate eclipse in future for better understanding.
thank you so much.
02:55 .. I like the confidence, he knows the answer but plays around viewer thought as when he explain immideatly after that, you can see he knows very well.
Yes, he knows everything. He is teaching on youtube more 10 years.
Underrated channel
Thank you..this video makes sense. A static block is used to initialize static variables.
when we are using Class.forName("className") to load the class,
we need to provide the fully qualified name of the class, including the package name. Then only it will load.
Also thanks for the amazing explanations. I check out your videos to quickly revise java concepts for interviews.
thank you, you saved me
Hi @surabhigupta9814 can you please write it down the syntax so that I can get more clarity on it, cause I am facing the exception in Thread. Thank You!
@@yourwishof.11.11 it should be package name.classname example: Class.forName("hello.Mobile"); --> my package name is hello. So by giving like this it resolves error and we get output as : in static block
You always explain what happend and how happens you never explain the real purpose why there was need of that where we are using in the real case. Code will not be remember by anyone.
Exactly
Why does interest in Java keep increasing after watching this legend? 😂
wow, new courses!! very excited, thank you !!! im a amateur springboot dev, but i still scan through your videoes in this course and watch the ones which i feel i dont have enough knowledge on, and really get to know something new, like the contents of this video, the jvm and classloader explanation. thanks!! youre one of the best educators. PS: the order of static method and static block video is inverted
Every time you create object there are two steps 1) class loads 2) objs are instantiated.
you makes everything so much easier to understand and the syntax makes sense
Thank you Navin, Videos are helping me a lot to revise java concepts :)
Hi Naveen, really your knowledge on java is superb. How did you gain this knowledge? How long did it take to gain it?
Instead of creating a static block, why dont we directly initiate the static variables.
String name = "Phone";
There are several scenarios where using a static block for initializing a static variable with additional logic or computations may be necessary or beneficial:
1. Initialization based on environment variables: You might need to initialize a static variable based on environment-specific configurations or system properties. In such cases, you may need to read environment variables or system properties and perform validation or transformation before assigning the value to the static variable.
2. Initialization requiring resource loading: If your static variable needs to be initialized with data from an external resource such as a file, database, or network resource, you may use a static block to load and process the resource data before assigning it to the static variable.
3. Dynamic initialization: Sometimes, the initialization value of a static variable may depend on runtime conditions or dynamic calculations. For example, initializing a static variable based on the current timestamp, random number generation, or other dynamic computations might require using a static block.
4. Complex initialization logic: If the initialization logic for a static variable is complex and involves multiple steps or conditions, using a static block can help organize the code and improve readability by separating the initialization logic from the variable declaration.
But it's not possible.
This should be video #39. Learning about static method before static block is less confusing.
Agree
these videos are cleannnnnn 🔥
@teusko it did call static block without creation of obejct
I don't get it even if i don't call constructor the static should work since static is a class and it does not depend on the object right🤔 Please let me know if I'm wrong in any way.
good one!
Does constructor and static does not need data type ?
Thankyou !!
How do I see the built in classes like you by just resting the pointer?
Why is static block needed, when we can directly initialize static variables in class itself?
If u want to use static variable as constructor u need to create static variables inside static block I think so
Remember that its not all concepts that apply at every situation. Yours might not need static as a constructor but some other cases may
There are several scenarios where using a static block for initializing a static variable with additional logic or computations may be necessary or beneficial:
1. Initialization based on environment variables: You might need to initialize a static variable based on environment-specific configurations or system properties. In such cases, you may need to read environment variables or system properties and perform validation or transformation before assigning the value to the static variable.
2. Initialization requiring resource loading: If your static variable needs to be initialized with data from an external resource such as a file, database, or network resource, you may use a static block to load and process the resource data before assigning it to the static variable.
3. Dynamic initialization: Sometimes, the initialization value of a static variable may depend on runtime conditions or dynamic calculations. For example, initializing a static variable based on the current timestamp, random number generation, or other dynamic computations might require using a static block.
4. Complex initialization logic: If the initialization logic for a static variable is complex and involves multiple steps or conditions, using a static block can help organize the code and improve readability by separating the initialization logic from the variable declaration.
Okay sir found it the video number 40 should be 39 and 39 shoud be 40. Thanks
Understood everything up until now but i don't know why this is giving me headache I am not getting it.
It makes code much more organized and easy to edit as all static methods and variables can be in one place and that executes first.
Ok so basically static block will be first to get executed within a class irrespective of its position on which line it is.
same here
In which video we learnt about constructors?
43, the sequence is messed up
Thank you but you maintion on last video you will show us static method but starting of this video you said Now we know static variable and static method. i did not see a video for static methods
this is very confusing sir ,i didnt understand properly.
and the code is not executing after coppying the syntax and the concept
class Mobile
{
static String brand;
String name;
int price;
static
{
brand = "apple";
System.out.println("in static block");
}
public Mobile()
{
name = "15promax";
price = 189999;
System.out.println("non static block");
}
public void show()
{
System.out.println(brand+":"+name+":"+price);
}
}
public class lecture39 {
Mobile obj = new Mobile();
obj.name = "15promax";
obj.price = 189999;
Mobile.brand = "apple";
Mobile obj1 = new Mobile();
}
hi even though if i didnot create any object still static block is getting created can you explain this.
Sir but I can load static method without creating any object..
Does anyone know what tool he is using for writing?
VS code
But without create object still Static block is running ..Here see this code
public class StaticHack {
static
{
System.out.println("Static block");
}
StaticHack(){
System.out.println("Constructor");
}
public static void main(String[] args) {
// StaticHack obj=new StaticHack();
}
}
Because your static block is present in class StaticHack which has the main method & this class will obviously be loaded by the class loader and hence the execution of static block.
Respect ++
Why are you not updating VS Code? Please update VS Code.
Discord link is not working.
this video didnt make sense to me
Hey hi Naveen,
I have a small doubt without creating an object i call my static block it's working
Example
In my class have
Class staticConcept{
Static{
S.o.p("hello");
}
Static{
S.o.p("hi");
}
P s v m (String args[])
{
S.o.p("world");
}
It's working without creating an object
yes It will work at the time of class loading
because all your static blocks and main method are inside the same class
Thank you