Maruthi Krishna

Maruthi Krishna

500 Articles Published

Articles by Maruthi Krishna

Page 11 of 50

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

Maruthi Krishna
Maruthi Krishna
Updated on 02-Jul-2020 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 primitive datatype).Public class Sample{    Public static void main(String args[]){       String str1 = "Hello";       String str2 = "how are you";    } }Strings are immutable in Java i.e. once you create a String literal it cannot be modified.StorageSince all the String values we define ...

Read More

In how many ways we can concatenate Strings in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 02-Jul-2020 394 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 primitive datatype).String stringObject = new String("Hello how are you"); String stringLiteral = "Welcome to Tutorialspoint";Concatenating StringsYou can concatenate Strings in Java in the following ways −Using the "+" operator: Java Provides a concatenation operator using this, you can directly add two String literalsExampleimport java.util.Scanner; public class StringExample {    public ...

Read More

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

Maruthi Krishna
Maruthi Krishna
Updated on 02-Jul-2020 1K+ 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 system searches for the specified program in the current directly, if available, executes it.In case the programs are not available in the current directory, operating system verifies in the set of directories specified in the ‘PATH’ environment variable.You need to set path for compiler (javac.exe) and JVM(java.exe), which exists in ...

Read More

Can we make Array volatile using volatile keyword in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 02-Jul-2020 2K+ 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 instance variables, which are of type object or private. A volatile object reference can be null.Examplepublic class MyRunnable implements Runnable {    private volatile boolean active;    public void run() {       active = true;       while (active) { // line 1         ...

Read More

Where does Array stored in JVM memory in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 02-Jul-2020 5K+ 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 {    public static void main(String args[]) {       Number integerArray[] = new Integer[3];       integerArray[0] = 25;       integerArray[1] = 32;       integerArray[2] = 56;       System.out.println(Arrays.toString(integerArray));    } }Output[25, 32, 56]Arrays are two types −Single dimensional arrays: Normal ...

Read More

Can we store objects in an array in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 02-Jul-2020 11K+ Views

Array is a container which can hold a fix number of items and these items should be of the same type. Most of the data structures make use of arrays to implement their algorithms. Following are the important terms to understand the concept of Array.Element: Each item stored in an array is called an element.Index: Each location of an element in an array has a numerical index, which is used to identify the element.Storing Objects in an arrayYes, since objects are also considered as datatypes (reference) in Java, you can create an array of the type of a particular class ...

Read More

Can you change size of Array in Java once created?

Maruthi Krishna
Maruthi Krishna
Updated on 02-Jul-2020 9K+ Views

An array is a data structure/container/object that stores a fixed-size sequential collection of elements of the same type. The size/length of the array is determined at the time of creation.The position of the elements in the array is called as index or subscript. The first element of the array is stored at the index 0 and, the second element is at the index 1 and so on.Each element in an array is accessed using an expression which contains the name of the array followed by the index of the required element in square brackets.For example, if an array of 6 ...

Read More

What is an anonymous array and explain with an example in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 02-Jul-2020 2K+ Views

An array is a data structure/container/objectthat stores a fixed-size sequential collection of elements of the same type. The size/length of the array is determined at the time of creation.The position of the elements in the array is called as index or subscript. The first element of the array is stored at the index 0 and, the second element is at the index 1 and so on.Each element in an array is accessed using an expression which contains the name of the array followed by the index of the required element in square brackets.For example, if an array of 6 elements ...

Read More

How to convert integer set to int array using Java?

Maruthi Krishna
Maruthi Krishna
Updated on 02-Jul-2020 11K+ Views

A collection object in Java is the one which stores references of other objects in it. The java.util package provides the classes and interfaces for collections. There are four main collection interfaces namely Set Lists, Queues, Maps.Set − The set object is a collection which stores group of elements, it grows dynamically and it does not allow duplicate elements.HashSet and LinkedHashSet are the classes that implements Set interface. You can create a Set object by implementing either of these classes.Exampleimport java.util.HashSet; public class SetExample {    public static void main(String args[]) {       //Instantiating the HashSet       ...

Read More

Are the constructors in an object invoked when de-serialized in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 02-Jul-2020 1K+ Views

In Java, serialization is a concept using which we can write the state of an object into a byte stream so that we can transfer it over the network (using technologies like JPA and RMI).To serialize an object −Make sure the class implements the Serializable interface.Create a FileOutputStream object representing the file (abstract path) of the file to which the object is to be stored.Create a ObjectOutputStream object by passing the above created FileOutputStream object.Write the object to the file using the writeObject() method.To de-serialize an objectCreate a FileInputStream object representing the file that contains the serialized object.Read the object ...

Read More
Showing 101–110 of 500 articles
« Prev 1 9 10 11 12 13 50 Next »
Advertisements