In this tutorial, we will be discussing a program to understand how to use class to implement vector quantities in C++.Vector quantities are the ones which have both magnitude and direction. Here we will be implementing them using classes and then performing basic operations on them.Example Live Demo#include #include using namespace std; class Vector { private: int x, y, z; //components of the Vector public: Vector(int x, int y, int z){ this->x = x; this->y = y; this->z = z; } Vector operator+(Vector ... Read More
In this tutorial, we will be discussing a program to understand trivial classes in C++.When a class/ struct contains explicitly defaulted value inside it, then it is known as Trivial classes. Further trivial classes have their own constructor, assignment operator and destructor.Example//using the default constructor struct Trivial { int i; private: int j; }; //defining your own constructor //and then marking it as default struct Trivial2 { int i; Trivial2(int a, int b){ i = a; } Trivial2() = default; };Output(No output as we are just defining classes here and not creating object instances from them.)
In this tutorial, we will be discussing a program to understand the transform_inclusive_scan() function in C++.Example Live Demo#include #include using namespace std; namespace point_input_iterator { template OutputItrator transform_inclusive_scan(InputItrator first, InputItrator last, OutputItrator d_first, BinaryOperation binary_op, UnaryOperation unary_op){ *d_first = unary_op(*first); first++; d_first++; for (auto it = first; it != last; it++) { //calculating the prefix sum *d_first = binary_op(unary_op(*it), *(d_first ... Read More
In this tutorial, we will be discussing a program to understand thread get_id() function in C++.Thread get_id() function verifies the current state of the process and then returns the id for the current thread in execution. This function doesn’t take any parameters.Example#include #include #include using namespace std; //creating thread void sleepThread(){ this_thread::sleep_for(chrono::seconds(1)); } int main(){ thread thread1(sleepThread); thread thread2(sleepThread); thread::id t1_id = thread1.get_id(); thread::id t2_id = thread2.get_id(); cout
In this tutorial, we will be discussing a program to understand containership in C++.The parameter if a certain class contains another class is called as containership. The inside class is called contained class, while the class in which it is present is called container class.Example Live Demo#include using namespace std; class first { public: first(){ cout
In this tutorial, we will be discussing a program to understand constructors in C++.Constructors are member functions of the classes which initiates the object instance creation. They have the same name as the parent class and don’t have any return type.Default constructorsExample Live Demo#include using namespace std; class construct { public: int a, b; //default constructor construct(){ a = 10; b = 20; } }; int main(){ construct c; cout
Default constructors in Java:A constructor initializes an object when it is created. It has the same name as its class and is syntactically similar to a method. However, constructors have no explicit return type. There are two types of constructors namely −parameterized constructors − Constructors with arguments.no-arg constructors − Constructors without arguments.Example Live Demopublic class Sample{ int num; Sample(){ num = 100; } Sample(int num){ this.num = num; } public static void main(String args[]){ System.out.println(new Sample().num); System.out.println(new Sample(1000).num); } }Output100 1000Default ConstructorIt ... Read More
JShell is an interactive Java Shell tool that enables us to execute java code from the shell and instantly displays the output. JShell is the REPL(Read Evaluate Print Loop) tool that runs from the command-line. We can start a JShell by simply typing "jshell" in the command prompt, and to exit the jshell by using "/exit" command. For small snippets, we do not need to create a main() method in JShell.We can also implement the major collections like list, map and set by using this tool. In the below program, we can implement an ArrayList with various scenarios.ExampleC:\Users\User\Desktop\Java 9 QNA>jshell | Welcome to JShell ... Read More
In Java 9, Platform Logging API can be used to log messages with a service interface for consumers of those messages. An implementation of LoggerFinder has been loaded with the help of java.util.ServiceLoader API by using System ClassLoader. Based on this implementation, an application can plug in its own external logging backend without configuring java.util.logging.We can pass a class name or module to LoggerFinder so that it knows which logger to return.public class MyLoggerFinder extends LoggerFinder { @Override public Logger getLogger(String name, Module module) { // return a logger depends on name/module } }If no concrete implementation can be found, then ... Read More
StackWalker API provides a stream of information in stack traces during the execution of a program. This API requires a virtual machine to capture a snapshot of the entire stack and returns an array of elements for filtering purposes. We need to skip, drop, and limit the stack frames by using the walk() method. We can also filter a stack frame by class for getting the first matching frame, and all matching frames by using the filter() method.In the below example, we can filter a stack frame by using StackWalker API.Exampleimport java.lang.StackWalker.StackFrame; import java.util.*; import java.util.stream.*; public class StackWalkerFilterTest { ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP