7.16 How to use Static Block in Java Tutorial

///7.16 How to use Static Block in Java Tutorial

7.16 How to use Static Block in Java Tutorial

FavoriteLoadingAdd to favorites

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.

Java468x60

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

By |2020-11-09T10:26:45+00:00November 9th, 2020|Java Video Tutorials|34 Comments

34 Comments

  1. Pulkit Sharma November 9, 2020 at 10:26 am - Reply

    But we can initialize the static variable at the time of declaration itlself? Why we need stattic block

  2. Karri Naga SatyaNarayana Reddy November 9, 2020 at 10:26 am - Reply

    sachin tendulkar: made batting look so easy ..
    navin reddy: made java look so easy

  3. senura chamuth November 9, 2020 at 10:26 am - Reply

    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

  4. vasa geetha madhuri November 9, 2020 at 10:26 am - Reply

    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

  5. vasa geetha madhuri November 9, 2020 at 10:26 am - Reply

    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

  6. Abhishek Abhi November 9, 2020 at 10:26 am - Reply

    Then we can write out code in static only no sir? Why we can write in public static void main?

  7. Abdel DE November 9, 2020 at 10:26 am - Reply

    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)

  8. Elite D Susobhan November 9, 2020 at 10:26 am - Reply

    why you make videos with bad sound

  9. Max Karaev November 9, 2020 at 10:26 am - Reply

    You need to keep your voice level constant! buddy. I tried to watch this but couldnt.

  10. Elite D Susobhan November 9, 2020 at 10:26 am - Reply

    bad sound in this particular video

  11. Anirudh Bhardwaj November 9, 2020 at 10:26 am - Reply

    Thank you

  12. jebrann saoudi November 9, 2020 at 10:26 am - Reply

    dislike for the annoying sound in the background

  13. Abhishek Sengupta November 9, 2020 at 10:26 am - Reply

    Can't we directly initialize a static member without using static block?

  14. Samira November 9, 2020 at 10:26 am - Reply

    Thank you Telusko. You have done a great job!I learned a lot.

  15. Tanmay Kumar November 9, 2020 at 10:26 am - Reply

    sir the volume in the video is a bit on the lower side

  16. sunny sharma November 9, 2020 at 10:26 am - Reply

    Navin sir you r awesome๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜€apun ko programming smj arahi ha ab ๐Ÿ˜„๐Ÿ˜„Thank you so much

  17. Mohit mishra November 9, 2020 at 10:26 am - Reply

    can we do multiplication like 10*5 without using any arithmetic operator?

  18. neelu sahai November 9, 2020 at 10:26 am - Reply

    we can initialize static variable in main method too.

  19. JW W November 9, 2020 at 10:26 am - Reply

    thank you, it is very helpful

  20. india good November 9, 2020 at 10:26 am - Reply

    somebody is ringing bell.

  21. Amita Shah November 9, 2020 at 10:26 am - Reply

    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??

  22. Grid Osei November 9, 2020 at 10:26 am - Reply

    Bad tutorial

  23. Mayank Maheshwari November 9, 2020 at 10:26 am - Reply

    Would be better if you can increase your pitch a bit. With my laptop volume full, still I am facing issues in hearing!

  24. sapna vats November 9, 2020 at 10:26 am - Reply

    We can also initialize a static variable without using static block in a normal fashion. So what is the requirement of static block?

  25. Nitin Sharma November 9, 2020 at 10:26 am - Reply

    Lol..someone is doing pooja in the background..desi will relate..nice tuts btw..

  26. prasad sardesai November 9, 2020 at 10:26 am - Reply

    You made java very easy for me
    Thanks ๐Ÿ™

  27. Sirasit Thitirattanakorn November 9, 2020 at 10:26 am - Reply

    Great Tutorial !!

  28. Souvik Pal November 9, 2020 at 10:26 am - Reply

    @ 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 ????????????????????????????

  29. Karan Kampasi November 9, 2020 at 10:26 am - Reply

    cant we initialize static variable s with "hello world" during its declaration?

  30. J P November 9, 2020 at 10:26 am - Reply

    constructor only works on instance variable is wrong buddy. constructor also works on static variable.we can do it without static block using constructor.

  31. Payal Sasmal November 9, 2020 at 10:26 am - Reply

    Can we create a method within a static block?

  32. SQE Automation November 9, 2020 at 10:26 am - Reply

    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?

  33. Harisankar L November 9, 2020 at 10:26 am - Reply

    nice

  34. Daakshayani Allu November 9, 2020 at 10:26 am - Reply

    shouldnot we assign the value for s =helloworld without using staticblock

Leave A Comment

*