Found 9150 Articles for Object Oriented Programming

How to read the contents of a JSON file using Java?

Aishwarya Naglot
Updated on 20-Nov-2024 15:20:27

10K+ Views

JSON or JavaScript Object Notation is a lightweight text-based open standard designed for human-readable data interchange. Conventions used by JSON are known to programmers and include C, C++, Java, Python, Perl, etc. Sample JSON document − { "book": [ { "id": "01", "language": "Java", "edition": "third", "author": "Herbert Schildt" ... Read More

Is Swing thread-safe in Java?

Alshifa Hasnain
Updated on 23-Apr-2025 17:17:58

2K+ Views

No, Java Swing components are not thread-safe in Java. This means that whenever Swing components should be accessed or changed, it is done mostly by using a single thread, the EDT. Why Swing Components are not thread-safe One of the main reasons Java Swing is not thread-safe is to simplify the task of extending its components. Another reason for that Java Swing is not thread-safe due to the overhead involved in obtaining and releasing locks and restoring the state. Below are some methods given by Swing for safe operation with its UI: SwingUtilities.invokeLater(): In ... Read More

How to pass arrays as function arguments in JavaScript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

4K+ Views

Passing arrays as function argumentsIn olden days if we need to pass arrays as function arguments then apply() and null should be used. The use of null makes a code unclean. So to make code clean and also to pass an array as a function argument, the spread operator comes in to picture. By using the spread operator we don't need to use apply() function. Lets' discuss it in a nutshell.ExampleIn the following example, we have used null and apply() to pass an array as a function argument. This is an obsolete method. This method is replaced by a modern method in ... Read More

How can we create a login form in Java?

Alshifa Hasnain
Updated on 16-Apr-2025 18:54:02

33K+ Views

We can develop a login form in Java using Java Swing technology. In this example, we can create two labels username and password, two text fields for the user to enter valid credentials,  and finally, one submit button. Once the user is able to enter the valid credentials in the two text fields, we can able to see Hello admin in the login form. Setting Up the Project We’ll use Java Swing, a GUI toolkit for building desktop applications. Required Libraries are: javax.swing.* (for Swing components) java.awt.* (for layout management) ... Read More

Can re-declaring a variable destroy the value of that variable in JavaScript?

vineeth.mariserla
Updated on 29-Jun-2020 12:47:46

331 Views

Re-declaring a variable will not destroy the value of a variable, until and unless it is assigned with some other new value.If we look at the following example variables "x" and ''y'' were assigned with values 4 and 8 respectively, later on when those variables were reassigned, the old values were replaced with the new values and displayed as shown in the output.ExampleLive Demo           var x = new Number(4);       var x = 7;       var y = 8;       var y = 10;       document.write(x);     ... Read More

When will be an IllegalStateException (unchecked) thrown in Java?

Alshifa Hasnain
Updated on 06-May-2025 18:38:52

435 Views

In this article, we will learn how an IllegalStateException (unchecked) is thrown in Java. IllegalStateException is a subclass of RuntimeException. It occurs when a method is used at the wrong time or when an object is not in the right state. What is an IllegalStateException? An IllegalStateException is an unchecked exception in Java. This exception may arise in our Java program mostly if we are dealing with the collection framework of java.util.package. There are many collections, such as List, Queue, Tree, and Map, of which List and Queues (Queue and Deque) throw this IllegalStateException under particular conditions. When will ... Read More

How to create a custom unchecked exception in Java?

raja
Updated on 29-Apr-2025 19:13:28

10K+ Views

In Java, the exceptions are of two types: checked and unchecked exceptions. A checked exception is an exception that occurs at compile time; these are also called compile-time exceptions. An unchecked exception occurs at the time of execution. These are also called Runtime Exceptions. In this article, we will learn to create a custom unchecked exception in Java. We can create a custom unchecked exception by extending the RuntimeException class in Java.  What are unchecked exceptions? The unchecked exceptions inherit from the Error class or the RuntimeException class. Many programmers feel that we cannot handle these exceptions in our programs because they represent the type of errors ... Read More

Can we call Superclass’s static method from subclass in Java?

Maruthi Krishna
Updated on 29-Jun-2020 12:37:42

3K+ Views

A static method is the one which you can call without instantiating the class. If you want to call a static method of the superclass, you can call it directly using the class name.Example Live Demopublic class Sample{    public static void display(){       System.out.println("This is the static method........");    }    public static void main(String args[]){       Sample.display();    } }OutputThis is the static method........It also works, if you call a static method using an instance. But, it is not recommended. Live Demopublic class Sample{    public static void display(){       System.out.println("This is the static ... Read More

Can we call methods of the superclass from a static method in java?

Maruthi Krishna
Updated on 29-Jun-2020 12:38:24

3K+ Views

Inheritance can be defined as the process where one (parent/super) class acquires the properties (methods and fields) of another (child/sub). With the use of inheritance, the information is made manageable in a hierarchical order. The class which inherits the properties is known as a subclass and the class whose properties are inherited is called superclass.  In short, in inheritance, you can access the members (variables and methods) of the superclass using the subclass object.Example Live Democlass SuperClass {    public void display(){       System.out.println("Hello this is the method of the superclass");    } } public class SubClass extends SuperClass ... Read More

What happens if we call "super()" in a constructor without extending any class, in java?

Maruthi Krishna
Updated on 29-Jun-2020 12:41:12

3K+ Views

A super keyword is a reference of the superclass object in Java. Using this, you can invoke the instance methods constructors and, variables, of a superclass.Calling the constructor of a superclassYou can call the constructor of a superclass from the subclass’s constructor.ExampleConsider the following example, it has two classes SuperClass class and SubClass where the SubClass extends the SuperClass. The superclass has a parameterized constructor, we are invoking it from the subclass using the "super" keyword. Live Democlass SuperClass{    SuperClass(int data){       System.out.println("Superclass's constructor: "+data);    } } public class SubClass extends SuperClass{    SubClass(int data) {       ... Read More

Advertisements