How to create timer using C++11?

Tapas Kumar Ghosh
Updated on 16-Jun-2025 17:01:42

2K+ Views

The term "timer" is used to define the time based operations on hours, minutes, and seconds. Here, we can use the chrono library of C++ that helps to set the different timer operations like countdown, delayed, current time, etc. In this article, we will learn how to create a timer using C++. Timer Properties There are various properties to consider for building a timer in C++ program: Integer: int (milliseconds to wait until to run code). Boolean: bool (If this is true, it returns instantly, and run the code after specified ... Read More

Scope Resolution Operator vs this pointer in C++

Tapas Kumar Ghosh
Updated on 16-Jun-2025 17:00:00

498 Views

Both scope resolution operator and 'this' pointer are used for different purposes in the C++ programs. The scope resolution operator is used to access static or class members whereas this pointer is used to access object members when there is a local variable with the same name. Scope Resolution Operator in C++ The concept of scope resolution operator (::) is used in Object-Oriented Programming (OOPs) and namespace standard that can used to access something belongs to a specific scope, such as a class or namespace. Syntax It's syntax is as follows: :: Example In this program, we use ... Read More

Undefined Behaviour in C and C++

Tapas Kumar Ghosh
Updated on 16-Jun-2025 16:53:18

386 Views

In C/C++, undefined behavior refers to unexpected program output. When we write any program based on C or C++, sometimes we do not get the output as expected. This may be due to undefined behavior which cannot be predictable. For reference, sometimes it will show correct result, sometimes it will give the wrong result, and sometimes it may crash. Common Examples of Undefined Behavior in C/C++ Now, we have list of example that shows undefined behavior in C/C++ programs: Divide by Zero Using Uninitialized Variable NULL Pointer ... Read More

What is the C++ equivalent of sprintf?

Tapas Kumar Ghosh
Updated on 16-Jun-2025 16:48:56

3K+ Views

The sprintf() function of C library equivalent to C++ that is used to create strings with a specified format like custom text with numbers or names. In C++, we can perform the same operation as in C with the help of ostringstream.C++ std::ostringstreamThe ostringstream is known for the output string stream and is defined under header file. This is used to build the string by writing some text into it. Syntax i. Following is the basic syntax of sprint() function in C: int sprintf(char *str, const char *format, ...); ii. Here, we show the syntax of C++ function ... Read More

How to use the collect() method in Stream API in Java 9?

Alshifa Hasnain
Updated on 16-Jun-2025 16:42:10

2K+ Views

In this article, we will learn to use the collect() method in the Stream API in Java 9. Java Stream API collect() Method In Java, the collect() method in the Stream API collects all objects from a stream object and stores them in a type of collection. The user has to provide what type of collection the results can be stored. We specify the collection type using the Collectors Enum. There are different types, and different operations can be present in the Collectors Enum. Syntax The following is the syntax for the collect() method declaration: R collect(Collector

Difference between EnumMap and HashMap in Java

Alshifa Hasnain
Updated on 16-Jun-2025 16:40:48

935 Views

In this article, we will learn about the EnumMap and HashMap in Java. First, we will know about EnumMap, the syntax of EnumMap, and an example after that will learn about HashMap, the syntax of HashMap, and an example. At the end, we will see a table showing the difference between EnumMap and HashMap. What is EnumMap? EnumMap is introduced in JDK 5. It is designed to use an Enum as a key in the Map. It is an implementation of the Map interface. All of the keys in the EnumMap should be of the same enum type. Keys cannot be ... Read More

What is Unified JVM Logging in Java 9?

Alshifa Hasnain
Updated on 16-Jun-2025 16:36:39

539 Views

In this article, we will learn about the unified JVM logging in Java 9. Logging in the JVM is a great tool for performing root cause analysis, and it is a part of the JDK(Java Development Kit). Starting from JDK 9, the JVM maintainers chose to rebuild the way the JVM logs things. What is Unified JVM Logging? Java 9 can provide a common logging system for JVM components with a detailed level. By using a new command-line option: -Xlog for all logging settings, and unified JVM logging, gives us an easy-to-configure tool to do a root cause analysis (RCA) ... Read More

How to access each stack element of StackWalker in Java 9?

Alshifa Hasnain
Updated on 16-Jun-2025 16:35:18

253 Views

In this article, we will learn to access each stack element of StackWalker in Java 9. We will learn about the StackWalker API and its methods, and use of getStackTrace() method for accessing each stack element. StackWalker API StackWalker API allows easy filtering and lazy access to execute tasks within any method. It is an efficient API for obtaining stack trace information in Java 9. StackWalker API is an alternative to Thread.getStackTrace() or Throwable.getStackTrace() and SecurityManager.getClassContext(). This API targets a mechanism to traverse and materialize required stack frames, allowing efficient lazy access to additional stack frames when required. The following ... Read More

What is the use of the toEpochSecond() method in Java 9?

Alshifa Hasnain
Updated on 16-Jun-2025 16:33:50

875 Views

In this article, we will learn about the use of the toEpochSecond() method in Java 9. First, we will learn about the LocalDate class, its methods, then we will know about the Epoch Time and the toEpochSecond() method with its uses and example in Java. LocalDate Class The LocalDate class is a part of java.time package. LocalDate class represents a date without a time-zone in the ISO-8601 calendar system, such as 2020-10-14. This class represents a date in the format yyyy-MM-dd. The following are some of the common methods of the LocalDate Class getDayOfMonth(): This ... Read More

When to use the delayedExecutor() method of CompletableFuture in Java 9?

Alshifa Hasnain
Updated on 16-Jun-2025 16:32:44

4K+ Views

In this article, we will learn to use the delayedExecutor() method of CompletableFuture in Java 9. We're gonna know about the delayedExecutor() method and also the CompletableFuture class, as this method belongs to this class, and we're gonna know the uses of the delayedExecutor() method along with an example. CompletableFuture Class The CompletableFuture Class was introduced in Java 8. CompletableFuture is a class in java.util.concurrent package that implements the Future and CompletionStage Interface. CompletableFuture provides a powerful and flexible way to write asynchronous, non-blocking code. It supports delays and timeouts. The delayedExecutor() Method The delayedExecutor() method has been added ... Read More

Advertisements