Programming Articles - Page 2000 of 3366

Powers of two and subsequences in C++

sudhir sharma
Updated on 17-Apr-2020 06:41:39

220 Views

In this problem, we are given an array of N integers. Our task is to find the count of subsequences that can be formed such that if their elements are multiplied, they result in a number which is a power of two.Let’s take an example to understand the problem, Input − arr = [2, 5, 4]Output − 3Explanation − subsequences [2], [4] and [2, 4] give the desired result.To solve this problem, we need to understand the logic of power.Only those numbers with are powers of 2 will multiply to give the desired result. So, we have to consider only ... Read More

What are the rules for external declarations in JShell in Java 9?

raja
Updated on 16-Apr-2020 19:10:32

123 Views

JShell is a command-line tool introduced in Java 9, and it is Java's first official REPL tool to create a simple programming environment that reads the user's inputs, evaluates it, and prints the result.The declarations outside a class or interface (and declarations of classes and interfaces by themselves) have been created under the following rules.Rules for External Declarations:1) Access modifiers like public, protected, and private can be ignored. All declaration snippets can be accessible to all other snippets.jshell> private int i = 10; i ==> 10 jshell> System.out.println(i); 102) The modifier final can be ignored. Changes and inheritance are allowed.jshell> final class A {void m() {} } ... Read More

How can we create an instance of VarHandle in Java 9?

raja
Updated on 16-Apr-2020 14:11:28

225 Views

In general, a Variable Handle is simply typed reference to a variable. It will be an array element, an instance or static field of the class. VarHandle class can provide write and read access to variables under specific conditions. These are immutable and have no visible condition. In addition, they can't be sub-classified, and each VarHandle has a generic type T, which is the type of each variable represented by this VarHandle. The objective of VarHandle is to define a standard for calling equivalents of java.util.concurrent.atomic and sun.misc.Unsafe operations on fields and array elements.In the below example, we can use ... Read More

How to implement Flow.Publisher interface in Java 9?

raja
Updated on 16-Apr-2020 10:36:29

823 Views

A Publisher interface is a provider of an unbounded number of sequenced elements, publishing them according to the demand received from its Subscriber(s). In response to call Publisher.subscribe(Subscriber), the possible invocation sequences for methods on the Subscriber. It means that the onSubscribe() method, followed by the unbounded number of onNext() methods (as requested by Subscriber) followed by an onError() method, if there is a failure or an onComplete() method when no more elements available as long as Subscription is not canceled.Syntaxpublic interface Publisher {    public void subscribe(Subscriber

Difference between Python and Bash

Mahesh Parahar
Updated on 16-Apr-2020 06:20:19

1K+ Views

PythonPython is a programing language designed to be simple to implement and easy to understand. It is a dynamically typed language. It is not using pointers.BashBash is a command-line interpreter and is shipped by default in Linux and MacOS operating systems. It can be installed in other operating systems as well. It is default User Shell for Linux and MacOS.The following are some of the important differences between Python and Bash.Sr. No.KeyPythonBash1TypePython is a programming language mostly used in automation programming.Bash is a command-line interpreter or user shell to interpret user commands.2BasisPython is developed as an easy to implement an ... Read More

Difference between Java and Kotlin in Android with Examples

Mahesh Parahar
Updated on 16-Apr-2020 05:57:32

320 Views

Kotlin was introduced in Android development considering multiple enhancements in Kotlin w.r.t Java. For example:Less no. of Lines and easier development with the same functionality.Java: TextView displayText = (TextView) findViewById(R.id.textView); displayText.setText("Hello World"); Kotlin: textView.setText("Hello World")Compile-time handling of infamous null pointer exception.var value: String = "abc" // compilation error value = nullData class instead of POJO.data class User(val name: String, val age: Int)The following are some of the important differences between Java and Kotlin.Sr. No.KeyJavaKotlin1ExceptionsJava uses checked exceptions for exception handling.Kotlin has no checked exception. It throws compile-time errors.2Null HandlingJava has not enforced null check thus null pointer exception ... Read More

How can we implement methods of Stream API in Java 9?

raja
Updated on 15-Apr-2020 17:55:40

246 Views

Stream API provides lots of built-in functionality to help in performing operations on a collection using a stream pipeline. The API is declarative programming that makes the code precise and less error-prone. In Java 9, few useful methods have added to Stream API.Stream.iterate(): This method can be been used as stream version replacement for traditional for-loops.Stream.takeWhile(): This method can be used in a while loop that takes value while the condition is met.Stream.dropWhile(): This method can be used in a while loop that drops value while the condition is met.In the below example, we can implement the static methods: iterate(), takeWhile(), and dropWhile() methods of Stream ... Read More

What are the different startup scripts in JShell in Java 9?

raja
Updated on 15-Apr-2020 13:50:12

190 Views

JShell is an interactive Java Shell tool that executes code from the JShell and instantly displays an output. JShell is the REPL (Read-Evaluate-Print-Loop) tool that can run from the command-line prompt.In JShell, there is an option to load a script on startup that includes some special predefined options. These can be specified using the "--startup" flag passing in either a filename or one of DEFAULT, JAVASE, and PRINTING. We can use "/list -start" comamnd to see all startup snippets to be evaluated.DEFAULT: It loads the default behavior. This acts the same as if this is not specified at all.JAVASE: It imports all ... Read More

map::at() in C++ STL

Sunidhi Bansal
Updated on 15-Apr-2020 12:58:18

439 Views

In this article we will be discussing the working, syntax and examples of map::at() function in C++ STL.What is a Map in C++ STL?Maps are the associative container, which facilitates to store the elements formed by a combination of key value and mapped value in a specific order. In a map container the data is internally always sorted with the help of its associated keys. The values in the map container are accessed by its unique keys.What is a map::at()?map::at() function is an inbuilt function in C++ STL, which is defined in  header file. at() is used to access a ... Read More

map::size() in C++ STL

Sunidhi Bansal
Updated on 15-Apr-2020 12:56:27

8K+ Views

In this article we will be discussing the working, syntax and examples of map::size() function in C++ STL.What is a Map in C++ STL?Maps are the associative container, which facilitates to store the elements formed by a combination of key value and mapped value in a specific order. In a map container the data is internally always sorted with the help of its associated keys. The values in the map container are accessed by its unique keys.What is a map::size()?map::size() function is an inbuilt function in C++ STL, which is defined in  header file. size() is used to check the ... Read More

Advertisements