How to Access Variable From Another Class in Java?

In this article, we will learn how to access variable from another class in java. There are two ways to get variables from another class. Create an object of another class in the main class Extend another class in the main class Let us take a look at both these methods one by one with the help of sample programs. Method 1: Create Object of Another Class in Main Class In the following example, to access the variable ‘a’ of

Read more

How to Get Filename Without Extension in Java

This article will talk about how to get filename without extension in Java language. The file utility method helps you to get rid of the file extension from the file name. Here is an example. Program:


Explanation: We take a file named ‘myfile’ with the extension ‘.java’. Next, we check whether the filename contains ‘.’ or not. If it contains ‘.’, then go to the else part and get filename without an extension using substring() function. This

Read more

Java Global Variables

In this article, we will see what is a global variable and how we can use this in our Java programs. In Java, all the functions and data members are declared inside a class and every declaration has to be done inside it. If we declare them outside the class, then they would not be accessible by the object of that class. Therefore, in Java, there is no such precise concept of global variables because these are described at the

Read more
1 2