Java – Global variable examples

In Java, there is no global keyword, but we can use public static variable to referring a global variable. For example : MagicUtils.java package com.mkyong.example; public class MagicUtils { public static final String NAME = "mkyong"; // global public static final int LUCKY_NUMBER = 7; // global } JavaExample.java package com.mkyong.example; public class JavaExample { …

Read more

Java Static keyword example

The static keyword in Java is a modifier used to create memory efficient code. It helps in managing the memory occupied by objects, variables and method definitions. The static keyword makes sure that there is only one instance of the concerned method, object or variable created in memory. It is used when one needs to …

Read more