Maruthi Krishna has Published 951 Articles

Can we make static reference to non-static fields in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 13:54:14

10K+ Views

A class in Java will have three kinds of variables namely, static (class), instance and, local.Local variables − These variables belong to and declared/defined within the methods/blocks/constructors. The scope of these variables lies within the method (or, block or, constructor) and will be destroyed after he execution of it.Instance variables ... Read More

What is the syntax for passing Scanner object as a parameter in a method using java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 13:43:08

4K+ Views

Until Java 1.5 to read data from the user programmers used to depend on the character stream classes and byte stream classes.From Java 1.5 Scanner class was introduced. This class accepts a File, InputStream, Path and, String objects, reads all the primitive data types and Strings (from the given source) ... Read More

How to fix "Exception in thread main" in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 13:41:17

15K+ Views

An exception is an issue (run time error) occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed.Exampleimport java.util.Scanner; public class ExceptionExample {    public static void main(String args[]) {   ... Read More

Can we declare a static variable within a method in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 13:38:47

6K+ Views

A static filed/variable belongs to the class and it will be loaded into the memory along with the class. You can invoke them without creating an object. (using the class name as reference). There is only one copy of the static field available throughout the class i.e. the value of ... Read More

How and where does String literals in Java stored in the memory?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 13:34:36

7K+ Views

Strings are used to store a sequence of characters in Java, they are treated as objects. The String class of the java.lang package represents a String.You can create a String either by using the new keyword (like any other object) or, by assigning value to the literal (like any other ... Read More

Why should you be careful about String concatenation (+) operator in loops using Java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 13:32:40

4K+ Views

Strings are used to store a sequence of characters in Java, they are treated as objects. The String class of the java.lang package represents a String.You can create a String either by using the new keyword (like any other object) or, by assigning value to the literal (like any other ... Read More

In how many ways we can concatenate Strings in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 13:30:09

262 Views

Strings are used to store a sequence of characters in Java, they are treated as objects. The String class of the java.lang package represents a String.You can create a String either by using the new keyword (like any other object) or, by assigning value to the literal (like any other ... Read More

How do we set the Java environment variable in cmd.exe?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 13:28:13

695 Views

When you install Java in your system first of all you need to set the environment variables which are path and class path.PATH− The path environment variable is used to specify the set of directories which contains executional programs.When you try to execute a program from command line, the operating ... Read More

Can we make Array volatile using volatile keyword in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 13:22:36

1K+ Views

The volatile modifier indicates the JVM that the thread accessing a volatile variable should get data always from the memory. i.e. a thread should not cache the volatile variable.Accessing a volatile variable synchronizes all the cached copied of the variables in the main memory. Volatile can only be applied to ... Read More

Where does Array stored in JVM memory in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 13:14:30

4K+ Views

Array is a container which can hold a fix number of entities, which are of the of the same type. Each entity of an array is known as element and, the position of each element is indicated by an integer (starting from 0) value known as index.Exampleimport java.util.Arrays; public class ArrayExample ... Read More

Advertisements