Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 2470 of 3366
3K+ Views
Given an array of size 2X2 and the challenge is to print the sum of all the corner elements stored in an array.Assume a matrix mat[r][c], with some row “r” and column “c” starting row and column from 0, then its corner elements will be; mat[0][0], mat[0][c-1], mat[r-1][0], mat[r-1][c-1]. Now the task is to get these corner elements and sum those corner elements i.e., mat[0][0] + mat[0][c-1] + mat[r-1][0] + mat[r-1][c-1], and print the result on the screen.ExampleInput: Enter the matrix elements : 10 2 10 2 3 4 10 4 10 Output: sum of matrix is ... Read More
379 Views
Given four variables a, b, c, d with predefined values that will print the given bracket depending upon the variable used.Where variable, a for (( b for () c for )( d for ))The task is to use all the given brackets and print the balanced bracket expression, if we cannot form a balanced bracket expression then print -1. In case of multiple answers we can print any of the multiple answers which can be formed using the given brackets.ExampleInput: a = 3, b = 2, c = 4, d = 3 Output : (((((()()()()())))))()()To achieve this result we can, ... Read More
333 Views
Given an array a[] with elements and the task is to print the last occurrences of the given elements in the list. Here we not only have to remove the duplicate elements but also we have to maintain the order of the occurrences of the elements in an array as per the last time they have occurred.Like we have an array of 6 elements also containing some duplicate values i.e., {1, 3, 2, 3, 1, 2} so the result should be in form of 3 1 2.ExampleInput: a[]={4, 2, 2, 4, 1, 5, 1} Output : 2 4 5 1AlgorithmSTART ... Read More
482 Views
The task is to print the nodes starting from the end of the linked list without using extra space which means there shouldn’t be any extra variable instead the head pointer pointing the first node will be moved.ExampleInput: 10 21 33 42 89 Output: 89 42 33 21 10There can be many solutions to print the linked list in reverse order, like recursive approach (use extra space), reverse the linked list(requires modification in the given Linked List), pushing the elements on a stack and then pop and display the elements one by one(requires space O(n)), but these solutions seem to ... Read More
4K+ Views
An invokeLater() method is a static method of the SwingUtilities class and it can be used to perform a task asynchronously in the AWT Event dispatcher thread. The SwingUtilities.invokeLater() method works like SwingUtilities.invokeAndWait() except that it puts the request on the event queue and returns immediately. An invokeLater() method does not wait for the block of code inside the Runnable referred by a target to execute.Syntaxpublic static void invokeLater(Runnable target)Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public class InvokeLaterTest extends Object { private static void print(String msg) { String name = Thread.currentThread().getName(); System.out.println(name + ": " + msg); } ... Read More
5K+ Views
The sleep() method is a static method of Thread class and it makes the thread sleep/stop working for a specific amount of time. The sleep() method throws an InterruptedException if a thread is interrupted by other threads, that means Thread.sleep() method must be enclosed within the try and catch blocks or it must be specified with throws clause. Whenever we call the Thread.sleep() method, it can interact with the thread scheduler to put the current thread to a waiting state for a specific period of time. Once the waiting time is over, the thread changes from waiting state to runnable state. Syntax public ... Read More
3K+ Views
The join() Method In Java, a join() is a final method of the Thread class, and it can be used to join the start of a thread's execution to the end of another thread's execution so that a thread will not start running until another thread has ended. If the join() method is called on a thread instance, the currently running thread will be blocked until the thread instance has finished its execution. The join() method in Java is important in multithreading because it allows one thread to wait for the completion of another thread before continuing execution. Syntax Following is ... Read More
2K+ Views
In Java, overriding is a technique used to provide a specific implementation of a method that is already defined in a superclass (i.e., parent class), allowing a subclass (i.e., child class) to modify or extend the behavior of that method. Purpose of Overriding the finalize() Method The purpose of a finalize() method can be overridden for an object to include the cleanup code or to dispose of the system resources that can be done before the object is garbage collected. If we are overriding this method, then we need to call the finalize() method explicitly. The finalize() method can be ... Read More
1K+ Views
A JButton is a subclass of AbstractButton and it can be used for adding platform-independent buttons to a GUI application. A JButon can generate an ActionListener interface when the button is pressed or clicked, it can also generate the MouseListener and KeyListener interfaces. We can implement the rollover effect when the mouse moves over a JButton by overriding the mouseEntered() method of the MouseListener interface.Syntaxvoid mouseEntered(MouseEvent e)Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public class RollOverButtonTest extends JFrame { private JButton button; public RollOverButtonTest() { setTitle("RollOverButton Test"); button = new JButton("Rollover Button"); button.addMouseListener(new MouseAdapter() { ... Read More
5K+ Views
This article explains several strategies to avoid deadlock in Java, including a brief introduction to deadlock, strategies, and respective examples. Deadlock in Java In case of multi-threading, a deadlock is a programming situation where two or more threads are holding resources needed by other threads and are blocked forever, waiting for each other (to release the required resource). A deadlock condition will occur with at least two threads and two or more resources.How To Avoid Deadlock in Java? Following is a list of strategies to avoid the deadlock in Java: ... Read More