How to use Keyword Static in Java Tutorial using NetBeans IDE


This tutorial is all about How to use Keyword Static in Java Tutorial using NetBeans IDE. In this tutorial you will learn how the keyword static. static members belong to the class instead of a specific instance. means that only one instance of a static field exists [1] even if you create a million instances of the class or you don’t create any. It will be shared by all instances.

Since static methods also do not belong to a specific instance, they can’t refer to instance members (how would you know which instance Hello class you want to refer to?). static members can only refer to static members. Instance members can, of course access static members.

So if you have a variable: private staticint i = 0; and you increment it ( i++ ) in one instance, the change will be reflected in all instances

. This tutorial uses NetBeans IDE. Please follow all the steps below to complete this tutorial.


How to use Keyword Static in Java Tutorial using NetBeans IDE steps


The first step is to

Create your project by clicking file at the top of your project and then click new project, you can name your project whatever you want. After creating a project, you may now create your own class by right clicking the Source Packages and the clicking New Java Class




static String  yourvariable = “”;

static {

yourvariable = “This is the content”;


public static void main (String [] args) {

System.out.println(“The value of your variable is “+yourvariable);




Then you’re done. Run your project and see if it works.



For questions or any other concerns or thesis/capstone creation with documentation, you can contact me through the following:

E-Mail: [email protected]


Contact No.: +639098911050

Ryan A. Salem

BSIT Graduate, soon to be MIT.

Java Developer / System Developer

Related topic(s) that you make like:

1.) Common String Methods in Java Tutorial using Netbeans IDE
2.) Simple Restaurant Management System using Java



Looking for more source code? Type your keyword here here!


Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.