
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
Found 9150 Articles for Object Oriented Programming

407 Views
For this, use preventDefault() in JavaScript. Following is the JavaScript code −Example Live Demo Document Press Me to see logs Press Me to see logs in console Nothing will happen $(function(){ $("a:not([href='#'])").click(function(event){ event.preventDefault(); console.log("You have pressed me!!!!!"); }); }); To run the above program, save the file name anyName.html(index.html) and right click on the file. Select the option Open with live server in VS code editor.OutputIf you click the two links, Press Me ... Read More

324 Views
For this, you need to use keyDown as well as preventDefault(). Following is the JavaScript code −Example Live Demo Document const pressEnter = (event) => { if (event.key === "Enter") { event.preventDefault(); } }; document.getElementById("disableDefaultTime").addEventListener("keydown", pressEnter); To run the above program , just save the file name anyName.html(index.html) and right click on the file and select the option open with live server in VSCode editor.OutputFollowing is the output. When you press Enter key nothing will be displayed.You need to use keyDown to get time as in the below screenshot −

14K+ Views
In order to disable future dates, you need to use maxDate and set the current date. Following is the JavaScript code −Example Live Demo Document The selected date is as follows: $(document).ready(function () { var currentDate = new Date(); $('.disableFuturedate').datepicker({ format: 'dd/mm/yyyy', autoclose:true, endDate: "currentDate", maxDate: currentDate }).on('changeDate', function (ev) { $(this).datepicker('hide'); }); $('.disableFuturedate').keyup(function () { ... Read More

397 Views
To find the maximum and minimum element’s position in a list, the Java program is as follows −Example Live Demoimport java.util.*; import java.util.Arrays; import java.util.Collections; public class Demo{ public static int index_val(int my_arr[], int t){ if (my_arr == null){ return -1; } int len = my_arr.length; int i = 0; while (i < len){ if (my_arr[i] == t){ return i; } else { ... Read More

602 Views
To iterate over a Stream with Indices in Java 8, the code is as follows −Example Live Demoimport java.util.stream.IntStream; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; public class Demo{ public static void main(String[] args){ String[] my_array = { "T", "h", "i", "s", "s", "a", "m", "p", "l", "e" }; AtomicInteger my_index = new AtomicInteger(); System.out.println("The elements in the string array are :"); Arrays.stream(my_array).map(str -> my_index.getAndIncrement() + " -> " + str).forEach(System.out::println); } }OutputThe elements in the string array are : 0 -> T 1 -> h 2 -> i 3 ... Read More

1K+ Views
In this article, we will learn to print unique values from a List in Java. This program will use a loop-based approach to identify and display only the values that appear once, skipping any duplicates. This approach is helpful when working with datasets where you want to remove repeated items and focus on distinct entries. Problem Statement Write a program in Java to print unique values from a list. Below is a demostration of the same − Input 55, 67, 99, 11, 54, 55, 88, 99, 1, 13, 45 Output The distinct elements in the array are 55 67 99 11 ... Read More

738 Views
Finding close matches to a string from a list of words is a common problem in string manipulation and pattern recognition. This article demonstrates two effective approaches for solving this problem in Java. The first approach utilizes string encoding to identify similar patterns, while the second approach leverages the Levenshtein Distance algorithm to find approximate matches. String Encoding Approach The string encoding approach is a clever technique where each string is transformed into a unique encoded format. Strings with the same encoded pattern are considered matches HashMap A HashMap in Java is a collection that stores key-value pairs, where keys ... Read More

982 Views
In this article, we will learn to remove duplicate words from a given sentence in Java. The first method uses Java Streams to remove duplicates and join the words back into a sentence using the distinct() and Collectors.joining() methods. The second method uses a Set to automatically filter out duplicate words and a StringJoiner to combine the words back into a sentence. Both methods will give a sentence with only unique words. Different approaches Following are the different approaches to remove all duplicate words from a given sentence − Using Java Streams ... Read More

5K+ Views
To sort words of sentence in ascending order, the Java code is as follows −Example Live Demoimport java.util.*; public class Demo{ static void sort_elements(String []my_str, int n){ for (int i=1 ;i= 0 && temp.length() < my_str[j].length()){ my_str[j+1] = my_str[j]; j--; } my_str[j+1] = temp; } } public static void main(String args[]){ String []my_arr = {"This", "is", "a", "sample"}; int len = my_arr.length; sort_elements(my_arr,len); System.out.print("The sorted array is : "); for (int i=0; i

828 Views
To split the Even and Odd elements into two different lists, the Java code is as follows −Example Live Demoimport java.util.Scanner; public class Demo{ public static void main(String[] args){ int n, j = 0, k = 0; Scanner s = new Scanner(System.in); System.out.println("Enter the number of elements required :"); n = s.nextInt(); int my_arr[] = new int[n]; int odd_vals[] = new int[n]; int even_vals[] = new int[n]; System.out.println("Enter the elements of the array(even and add numbers) ... Read More