

Printing Something without any statement in Main Method.
Static Blocks are called before main Method.
Static Blocks are called as soon as your class is loaded in JVM.
Static block is a block of code which is preceded by the static keyword. Static block are also called
initialization block .It can be used to print something without any statement in Main Method.
Static Blocks are called before main Method.
Static Blocks are called as soon as your class is loaded in JVM.
Check out our website:
Follow Telusko on Twitter:
Follow on Facebook:
Telusko :
Navin Reddy :
Follow Navin Reddy on Instagram:
Subscribe to our other channel:
Navin Reddy :
Telusko Hindi :
subscribe to the channel and learn Programming in easy way.
Java Tutorial for Beginners:
C Tutorial Playlist :
Android Tutorial for Beginners Playlist :
XML Tutorial :
Design Patterns in Java :
Socket Programming in Java :
Spring MVC Tutorial :
OpenShift Tutorial for Beginners :
Spring Framework with Maven :
Sql Tutorial for Beginners :
String Handling in Java :
Array in Java :
Java Servlet :
Exception Handling in Java :
source
But we can initialize the static variable at the time of declaration itlself? Why we need stattic block
sachin tendulkar: made batting look so easy ..
navin reddy: made java look so easy
public class A {
static int x;
A() {
System.out.println("Constructor");
}
static { x = 7; System.out.println("Static 1");}
{x = 8; System.out.println("Static 2");}
public static void main(String[] args) {
System.out.println(x);
A a = new A();
System.out.println(x);
}
}
how this happnd
whats the output
public class Main
{
static String s="";
static{
s="hello world";
}
public static void main(String[] args) {
System.out.println(s);
}
static{
s="";
}
static{
s="abcd";
}
static {
s="efgh";
}
}
first guess and try it in compiler
whats the output
public class Main
{
static String s="";
static{
s="hello world";
}
public static void main(String[] args) {
System.out.println(s);
}
static{
s="";
}
static{
s="abcd";
}
static {
s="efgh";
}
}
first guess and try it in compiler
Then we can write out code in static only no sir? Why we can write in public static void main?
Hello;
I do really appreciate your tutorials but i have a short question
In this video you said that constructors only works on instances variables but in the last video about counting number of objects we used a class variable to count number of objects ( static int i)
why you make videos with bad sound
You need to keep your voice level constant! buddy. I tried to watch this but couldnt.
bad sound in this particular video
Thank you
dislike for the annoying sound in the background
Can't we directly initialize a static member without using static block?
Thank you Telusko. You have done a great job!I learned a lot.
sir the volume in the video is a bit on the lower side
Navin sir you r awesome๐๐๐๐apun ko programming smj arahi ha ab ๐๐Thank you so much
can we do multiplication like 10*5 without using any arithmetic operator?
we can initialize static variable in main method too.
thank you, it is very helpful
somebody is ringing bell.
Simple question .first without writing any static string both static block executed 1st & then main,& after using static string first main get executed then static block why??
Bad tutorial
Would be better if you can increase your pitch a bit. With my laptop volume full, still I am facing issues in hearing!
We can also initialize a static variable without using static block in a normal fashion. So what is the requirement of static block?
Lol..someone is doing pooja in the background..desi will relate..nice tuts btw..
You made java very easy for me
Thanks ๐
Great Tutorial !!
@ 5:30 you said we cannot use constructor for manipulating static variables , but as constructor is non – static member method we can access a static variable within a non-static member function, isn't it ????????????????????????????
cant we initialize static variable s with "hello world" during its declaration?
constructor only works on instance variable is wrong buddy. constructor also works on static variable.we can do it without static block using constructor.
Can we create a method within a static block?
One question: Main is also a static method which belong to a class then how how come it is executing 2nd after the static block which also belong to a class and not object .Why main is not executing 1st?
nice
shouldnot we assign the value for s =helloworld without using staticblock