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

 

[java]

 

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);

}

[/java]

 

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

About How To Use Keyword Static In Java

Project Name: How To Use Keyword Static
Language/s Used: JAVA
Database: None
Type: Desktop Application
Developer: IT SOURCECODE
Updates: 0
How To use Keyword Static In Java– Project Information

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

E-Mail: [email protected]

Facebook: facebook.com/RyyanSalem

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

 

 

Leave a Comment