Maruthi Krishna has Published 952 Articles

Why "this" keyword cannot be used in the main method of java class?

Maruthi Krishna

Maruthi Krishna

Updated on 05-Aug-2019 12:42:03

940 Views

The static methods belong to the class and they will be loaded into the memory along with the class. You can invoke them without creating an object. (using the class name as reference).Examplepublic class Sample{    static int num = 50;    public static void demo(){       System.out.println("Contents ... Read More

Can we use "this" keyword in a static method in java?

Maruthi Krishna

Maruthi Krishna

Updated on 05-Aug-2019 12:17:53

5K+ Views

The static methods belong to the class and they will be loaded into the memory along with the class. You can invoke them without creating an object. (using the class name as reference).Examplepublic class Sample{    static int num = 50;    public static void demo(){       System.out.println("Contents ... Read More

How to resolve javac is not recognized as an internal or external command in java?

Maruthi Krishna

Maruthi Krishna

Updated on 05-Aug-2019 11:52:10

2K+ Views

When you compile a program if you see this error it indicates that either you have not installed Java in your system properly or, you haven’t set the Path variable.The Path variable − The path environment variable is used to specify the set of directories which contains executional programs.When you ... Read More

Java program to verify whether a given element exists in an array.

Maruthi Krishna

Maruthi Krishna

Updated on 05-Aug-2019 11:26:59

813 Views

You can find whether a particular exists in a given array using any of the search algorithms. Here, we will see examples for linear search and binary search.Linear searchIterate through the array.Compare each element with the required element.import java.util.Scanner; public class ArraySearch {    public static void main(String[] args) { ... Read More

ArrayIndexOutOfBounds Vs ArrayStoreException in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Aug-2019 14:40:57

266 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 ... Read More

What are the drawbacks of the arrays in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Aug-2019 14:16:04

2K+ 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 ... Read More

How do you find continuous sub array whose sum is equal to a given number in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Aug-2019 14:12:53

1K+ Views

To find continuous sub array whose sum is equal to a given number −Iterate through the array.At each element add the next n elements one by one, when the sum equals to the required value print the sub array.Exampleimport java.util.Arrays; import java.util.Scanner; public class sub_arrays {    public static void ... Read More

How do you separate zeros from non-zeros in an integer array using Java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Aug-2019 14:09:27

2K+ Views

To separate zeros from non-zeros in an integer array, and push them to the end, you need to rearrange it array by assigning all the nonzero elements to its positions, sequentially, starting from zero. Then, from last position of the array to its end populate it with zeros.ExampleFollowing Java program ... Read More

Are the values of static variables stored when an object is serialized in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Aug-2019 13:58:39

803 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 ... Read More

How to find the missing number in a given Array from number 1 to n in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Aug-2019 13:38:27

15K+ Views

If a single number is missing in an integer array that contains a sequence of numbers values, you can find it basing of the sum of numbers or, basing on the xor of the numbers.Based on the sum of the numbers −The sum of n sequential numbers will be [n*(n+1)]/2. ... Read More

Advertisements