Narasimha Murthi has Published 23 Articles

Can we override final methods in Java?

Narasimha Murthi

Narasimha Murthi

Updated on 30-Jun-2020 07:12:47

993 Views

Overriding is a one of the mechanisms to achieve polymorphism. This is the case when we have two classes where, one inherits the properties of another using the extends keyword and, these two classes same method including parameters and return type (say, sample).Since it is inheritance. If we instantiate the ... Read More

What are the main shift operators provided by Java? Explain with an example?

Narasimha Murthi

Narasimha Murthi

Updated on 29-Jun-2020 15:05:55

75 Views

Java provides three shift operators namely −Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand.Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand.Shift right zero fill ... Read More

What is the use of StringBuffer class can anyone explain with an example?

Narasimha Murthi

Narasimha Murthi

Updated on 29-Jun-2020 15:02:48

58 Views

The java.lang.StringBuffer class is a thread-safe, mutable sequence of characters. Following are the important points about StringBuffer −A string buffer is like a String, but can be modified.It contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls.They are ... Read More

In how many ways can I compare Strings in Java explain with example?

Narasimha Murthi

Narasimha Murthi

Updated on 29-Jun-2020 15:01:58

103 Views

We can compare Strings in Java using the compareTo() method and the == operator.comapareTo() method − The compareTo() method compares two strings lexicographically.The comparison is based on the Unicode value of each character in the strings. The character sequence represented by this String object is compared lexicographically to the character ... Read More

What is the significance of the StringTokenizer class of the Java? Explain with an example?

Narasimha Murthi

Narasimha Murthi

Updated on 29-Jun-2020 15:01:27

153 Views

The java.util.StringTokenizer class allows an application to break a string into tokens.This class is a legacy class that is retained for compatibility reasons although its use is discouraged in new code.Its methods do not distinguish among identifiers, numbers, and quoted strings.This class methods do not even recognize and skip comments.Example Live ... Read More

Java.util.StringJoiner in Java8

Narasimha Murthi

Narasimha Murthi

Updated on 29-Jun-2020 15:00:44

90 Views

This class is used Join a sequence of characters separating using the delimiter.Examplepublic class StringJoinerSample {    public static void main(String[] args){       StringJoiner sj = new StringJoiner(", ");       sj.add("Krishna");       sj.add("Raju");       sj.add("Satish");       sj.add("Pruthvi");       System.out.println(sj);    } }OutputKrishna, Raju, Satish, Pruthvi

Explain the equals() method of the Object, String and, StringBuffer classes.

Narasimha Murthi

Narasimha Murthi

Updated on 29-Jun-2020 15:00:03

3K+ Views

To compare two objects the object class provides a method with name equals(), this method accepts an object and compares it with the current object. If the references of these two objects are equal, then it returns true else this method returns false.ExampleIn the following example we have a class ... Read More

What is the difference between object and reference in java?

Narasimha Murthi

Narasimha Murthi

Updated on 29-Jun-2020 14:58:28

8K+ Views

A class in a blue print/user defined datatype in java that describes the behavior/state that the object of its type support.Examplepublic class Student {    String name "Krishna";    int age = 20;    void greet() {       System.out.println("Hello how are you");    } }An object is an ... Read More

How many times finalize method will be invoked? who invokes finalize() method in Java?

Narasimha Murthi

Narasimha Murthi

Updated on 29-Jun-2020 14:57:55

815 Views

The finalize() method belongs to the Object class. Right before closing an object, the garbage collector makes sure that there are no more references to it and, calls the finalize() method on it.Therefore, once you override the finalize() method in it, you can do all the cleanup activity like closing ... Read More

Can we pass objects as an argument in Java?

Narasimha Murthi

Narasimha Murthi

Updated on 29-Jun-2020 14:57:14

8K+ Views

Yes, you can pass objects as arguments in Java. Consider the following example: Here we have a class with name EmployeeExampleIn the following Java example, we a have a class with two instance variables name and age and a parameterized constructor initializing these variables.We have a method coypObject() which accepts ... Read More

Advertisements