
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 33676 Articles for Programming

3K+ Views
Here we will see how to start some third-party application like notepad or anything using C++ program. This program is very simple, we can use command prompt command to do this task.We will pass the application name inside the system() function. This will open it accordingly.Example#include using namespace std; int main() { cout >> "Opening Nodepad.exe" >> endl; system("notepad.exe"); }Output

153 Views
To check if the second item is selected i.e. index 1, use the method isSelectedIndex():list.isSelectedIndex(1);Above, we have set the list with string values:String sports[]= { "Squash", "Fencing", "Cricket", "Football", "Hockey", "Rugby"}; JList list = new JList(sports);The following is an example to check if the second item is selected in JList:Examplepackage my; import java.awt.event.*; import java.awt.*; import javax.swing.*; class SwingDemo extends JFrame { static JFrame frame; static JList list; public static void main(String[] args) { frame = new JFrame("JList Demo"); SwingDemo s = new SwingDemo(); JPanel panel = ... Read More

32K+ Views
Here we will see how to check how many digits are there in an integer in C++. At first we will see the traditional rule, then a shorter method and finally another approach to find the digit count. For example, given a single integer (which can be positive, negative, or zero): //Example 1 Input: 12345 Output: 5 //Example 2 Input: -789 Output: 3 Note: The minus sign (if present) is not counted as a digit. Determining how many digits there are in an integerWe can count the number of digits in an integer using different methods ... Read More

3K+ Views
Here we will see how to get the memory usage statistics under Linux environment using C++.We can get all of the details from “/proc/self/stat” folder. Here we are taking the virtual memory status, and the resident set size.Example#include #include #include #include #include using namespace std; void mem_usage(double& vm_usage, double& resident_set) { vm_usage = 0.0; resident_set = 0.0; ifstream stat_stream("/proc/self/stat", ios_base::in); //get info from proc directory //create some variables to get info string pid, comm, state, ppid, pgrp, session, tty_nr; string tpgid, flags, minflt, cminflt, majflt, cmajflt; string ... Read More

757 Views
To check if there are any selected items, use the following:boolean res = !list.isSelectionEmpty();The value of res would be TRUE IF we have a selected item in the JList.The following is an example to check if there are any selected items in JList:Examplepackage my; import java.awt.event.*; import java.awt.*; import javax.swing.*; class SwingDemo extends JFrame { static JFrame frame; static JList list; public static void main(String[] args) { frame = new JFrame("JList Demo"); SwingDemo s = new SwingDemo(); JPanel panel = new JPanel(); String sports[]= {"Squash", ... Read More

383 Views
In C++, we can overload the functions. But sometimes the overloading is not done. In this section, we will see what are the different cases, in which we cannot overload the functions.When function signatures are same, only the return type is different, then we cannot overload the function.int my_func() { return 5; } char my_func() { return 'd'; }When the member functions have the same name and same parameter list in a class, then they cannot be overloaded.class My_Class{ static void func(int x) { //Something } void func(int x) { ... Read More

2K+ Views
Let’s say the following is our List with string elements:List leagues = Arrays.asList("BBL", "IPL", "MLB", "FPL", "NBA", "NFL");Now, create a stream and filter elements that end with a specific letter:Stream stream = leagues.stream().filter(leagueName -> leagueName.endsWith("L"));Now, use Objects::nonnull for non-null values:List list = stream.filter(Objects::nonNull).collect(Collectors.toList());The following is an example to filter non-null value in Java:Exampleimport java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; import java.util.stream.Stream; public class Demo { public static void main(String[] args) { List leagues = Arrays.asList("BBL", "IPL", "MLB", "FPL", "NBA", "NFL"); Stream stream = leagues.stream().filter(leagueName -> leagueName.endsWith("L")); List list = ... Read More

1K+ Views
Let’s say we have a String List with an empty value. Here, we have empty array elements before Football and after Squash:List sports = Arrays.asList("", "Football", "Cricket", "Tennis", "Squash", "", "Fencing", "Rugby");Now filter the empty string values. At first, we have used Predicate to negate values:Stream stream = sports.stream(); Predicate empty = String::isEmpty; Predicate emptyRev = empty.negate(); stream.filter(emptyRev).collect(Collectors.toList()));The following is an example to filter empty string values from a List:Exampleimport java.util.Arrays; import java.util.List; import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; public class Demo { public static void main(String[] args) { List sports = Arrays.asList("", "Football", "Cricket", "Tennis", ... Read More

531 Views
Let us see how to generate random numbers using C++. Here we are generating a random number in range 0 to some value. (In this program the max value is 100).To perform this operation we are using the srand() function. This is in the C library. The function void srand(unsigned int seed) seeds the random number generator used by the function rand.The declaration of srand() is like below −void srand(unsigned int seed)It takes a parameter called seed. This is an integer value to be used as seed by the pseudorandom number generator algorithm. This function returns nothing.To get the number ... Read More

516 Views
Let’s say the following is the String List:List list = new ArrayList(); list.add("Tom"); list.add("John"); list.add("David"); list.add("Paul"); list.add("Gayle"); list.add("Narine"); list.add("Joseph");Now, let’s say you need to filter elements beginning with a specific letter. For that, use filter() and startsWith():long res = list .stream() .filter((s) -> s.startsWith("J")) .count();We have also counted the elements above after filtering using count().The following is an example to count element after filtering in Java:Exampleimport java.util.ArrayList; import java.util.List; public class Demo { public static void main(final String[] args) { List list = new ArrayList(); list.add("Tom"); list.add("John"); ... Read More