Vikyath Ram has Published 173 Answers

Get first and last elements from Vector in Java

Vikyath Ram

Vikyath Ram

Updated on 30-Jul-2019 22:30:24

The first element in the Vector can be obtained using the java.util.Vector.firstElement() method. The last element in the Vector can be obtained using the java.util.Vector.lastElement() method. Neither of these methods requires any parameters.A program that demonstrates this is given as follows:Example Live Demoimport java.util.Vector; public class Demo { ... Read More

Make a class final in Java

Vikyath Ram

Vikyath Ram

Updated on 30-Jul-2019 22:30:24

A class can be made final by using the final keyword. The final class cannot be inherited and so the final keyword is commonly used with a class to prevent inheritance.A program that demonstrates a final class in Java is given as follows:Example Live Demofinal class A {    private int ... Read More

How to import all classes in Java?

Vikyath Ram

Vikyath Ram

Updated on 30-Jul-2019 22:30:24

All the classes in a package can be imported using the import statement along with the character *. For example - All the classes in the package java.util can be imported using import java.util.*;A program that demonstrates this in Java is given as follows:Example Live Demoimport java.util.*; public class Demo { ... Read More

SortedMap Interface in Java Programming

Vikyath Ram

Vikyath Ram

Updated on 30-Jul-2019 22:30:23

The SortedMap interface extends Map. It ensures that the entries are maintained in an ascending key order. Several methods throw a NoSuchElementException when no items are in the invoking map. A ClassCastException is thrown when an object is incompatible with the elements in a map. A NullPointerException is thrown if ... Read More

Static methods vs Instance methods in Java

Vikyath Ram

Vikyath Ram

Updated on 30-Jul-2019 22:30:23

In Java as we know that the behavior of any variable/method is defined by the keyword that is used in front of its declaration name. So one of the non-access modifiers is Static which can be used along with method as well as with variable. Static methods as name states ... Read More

Swapping Characters of a String in Java

Vikyath Ram

Vikyath Ram

Updated on 30-Jul-2019 22:30:23

For swapping characters of a string in Java we can use string builder which is mutable so we need not to take care of new object creation during swapping. In this we would create a method which swap characters of string based on location of swapping characters.This method will take ... Read More

Python program to generate all possible valid ID address from given string

Vikyath Ram

Vikyath Ram

Updated on 30-Jul-2019 22:30:23

String is given. String contains only digit. Our task is to check all possible valid IP address combinations. Here first we check the length of the string then split by ".". Then we check the different combination of ".". Example Input : "255011123222" It's not a valid IP ... Read More

Should a constructor always have the same name as the class in java?

Vikyath Ram

Vikyath Ram

Updated on 30-Jul-2019 22:30:22

Yes, the constructor should always have the same name as the class. Constructor looks like method but it is not. It does not have a return type and its name is same as the class name. Mostly it is used to instantiate the instance variables of a class. If the ... Read More

Differences between | and || operators in Java

Vikyath Ram

Vikyath Ram

Updated on 30-Jul-2019 22:30:21

| is a bitwise operator and compares each operands bitwise.It is a binary OR Operator and copies a bit to the result it exists in either operands.Assume integer variable A holds 60 and variable B holds 13 then  (A | B) will give 61 which is 0011 1101.Whereas || is ... Read More

What does abstract modifier in Java do?

Vikyath Ram

Vikyath Ram

Updated on 30-Jul-2019 22:30:20

An abstract keyword is used to declare methods abstract methods and abstract classes. Once a method is declared abstract we should not specify body for those. Example public abstract class Sample{ public abstract demo(){ } } Error Sample.java:2: error: invalid method ... Read More

Advertisements