Java Articles

Page 112 of 450

CopyOnWriteArrayList Class in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 5K+ Views

Class declarationpublic class CopyOnWriteArrayList    extends Object implements List, RandomAccess, Cloneable, SerializableCopyOnWriteArrayList is a thread-safe variant of ArrayList where operations which can change the ArrayList (add, update, set methods) creates a clone of the underlying array.CopyOnWriteArrayList is to be used in a Thread based environment where read operations are very frequent and update operations are rare.Iterator of CopyOnWriteArrayList will never throw ConcurrentModificationException.Any type of modification to CopyOnWriteArrayList will not reflect during iteration since the iterator was created.List modification methods like remove, set and add are not supported in the iteration. This method will throw UnsupportedOperationException.null can be added to the ...

Read More

Difference between super() and this() in Java

Vikyath Ram
Vikyath Ram
Updated on 11-Mar-2026 8K+ Views

Following are the notable differences between super() and this() methods in Java. super()this()Definitionsuper() - refers immediate parent class instance.this() - refers current class instance.InvokeCan be used to invoke immediate parent class method.Can be used to invoke current class method.Constructorsuper() acts as immediate parent class constructor and should be first line in child class constructor.this() acts as current class constructor and can be used in parametrized constructors.OverrideWhen invoking a superclass version of an overridden method the super keyword is used.When invoking a current version of an overridden method the this keyword is used.Exampleclass Animal {    String name;    Animal(String name) { ...

Read More

Difference between super() and this() in Java

Vikyath Ram
Vikyath Ram
Updated on 11-Mar-2026 8K+ Views

Following are the notable differences between super() and this() methods in Java. super()this()Definitionsuper() - refers immediate parent class instance.this() - refers current class instance.InvokeCan be used to invoke immediate parent class method.Can be used to invoke current class method.Constructorsuper() acts as immediate parent class constructor and should be first line in child class constructor.this() acts as current class constructor and can be used in parametrized constructors.OverrideWhen invoking a superclass version of an overridden method the super keyword is used.When invoking a current version of an overridden method the this keyword is used.Exampleclass Animal {    String name;    Animal(String name) { ...

Read More

How to initialize and compare strings?

Vikyath Ram
Vikyath Ram
Updated on 11-Mar-2026 260 Views

Following example compares two strings by using str compareTo (string), str compareToIgnoreCase(String) and str compareTo(object string) of string class and returns the ascii difference of first odd characters of compared strings.Examplepublic class StringCompareEmp{    public static void main(String args[]) {       String str = "Hello World";       String anotherString = "hello world";       Object objStr = str;       System.out.println( str.compareTo(anotherString) );       System.out.println( str.compareToIgnoreCase(anotherString) );       System.out.println( str.compareTo(objStr.toString()));    } }OutputThe above code sample will produce the following result.-32 0 0String compare by equals()This method compares this ...

Read More

How to initialize and compare strings?

Vikyath Ram
Vikyath Ram
Updated on 11-Mar-2026 260 Views

Following example compares two strings by using str compareTo (string), str compareToIgnoreCase(String) and str compareTo(object string) of string class and returns the ascii difference of first odd characters of compared strings.Examplepublic class StringCompareEmp{    public static void main(String args[]) {       String str = "Hello World";       String anotherString = "hello world";       Object objStr = str;       System.out.println( str.compareTo(anotherString) );       System.out.println( str.compareToIgnoreCase(anotherString) );       System.out.println( str.compareTo(objStr.toString()));    } }OutputThe above code sample will produce the following result.-32 0 0String compare by equals()This method compares this ...

Read More

Can we overload the main method in Java?

radhakrishna
radhakrishna
Updated on 11-Mar-2026 3K+ Views

Yes, we can overload the main method in Java, but When we execute the class JVM starts execution with public static void main(String[] args) method. Example public class Sample{ public static void main(){ System.out.println("This is the overloaded main method"); } public static void main(String args[]){ Sample obj = new Sample(); obj.main(); } } Output This is the overloaded main method

Read More

Single dimensional array in Java

V Jyothi
V Jyothi
Updated on 11-Mar-2026 1K+ Views

Following is a simple example of a single dimensional array.Examplepublic class Tester {    public static void main(String[] args) {       double[] myList = {1.9, 2.9, 3.4, 3.5};       // Print all the array elements       for (double element: myList) {          System.out.print(element + " ");       }    } }Output1.9 2.9 3.4 3.5

Read More

How to determine the OS the computer is running using Java?

Sreemaha
Sreemaha
Updated on 11-Mar-2026 251 Views

The System class of java.lang package provides a method named getProperty() this method accepts one of the following string parameters an returns the respective property. java.class.path − If you pass this value as a parameter, the getProperty() method returns the current classpath. java.home − If you pass this value as a parameter, the getProperty() method returns the current Installation directory of the JRE. java.vendor − If you pass this value as a parameter, the getProperty() method returns the current vendor name of the JRE. java.vendor.url − If you pass this value as a parameter, the getProperty() method returns the ...

Read More

What are method local inner classes in Java?

Prabhas
Prabhas
Updated on 11-Mar-2026 2K+ Views

In Java, we can write a class within a method and this will be a local type. Like local variables, the scope of the inner class is restricted to the method.A method-local inner class can be instantiated only within the method where the inner class is defined. The following program shows how to use a method-local inner class.Examplepublic class OuterClass {    public void display(){       int num = 23;       class Inner{          public void print() {             System.out.println("This is method inner class "+num);       ...

Read More

Can you extend a static inner class in Java?

Giri Raju
Giri Raju
Updated on 11-Mar-2026 2K+ Views

A static inner class is a nested class which is a static member of the outer class. It can be accessed without instantiating the outer class, using other static members. Just like static members, a static nested class does not have access to the instance variables and methods of the outer class. You can extend static inner class with another inner class. Example public class SampleClass { static abstract class Test{ int num = 300; public abstract void display(); } ...

Read More
Showing 1111–1120 of 4,498 articles
« Prev 1 110 111 112 113 114 450 Next »
Advertisements