Articles on Trending Technologies

Technical articles with clear explanations and examples

What is scatternet?

Moumita
Moumita
Updated on 27-Apr-2020 6K+ Views

A scatternet is a type of Bluetooth network that is formed by the interconnection between two or more individual Bluetooth networks, called piconets. The devices in the scattered should be Bluetooth enabled so that they can communicate wirelessly over a short range of within 10m radius using ultra-high frequency (UHF) radio waves.In a scatternet, there must be at least two piconets. The nodes in a scatternet may be of three types −Master Node − It is the primary station in each piconet that controls the communication within that piconet.Slave Node − A slave is a secondary station in a piconet ...

Read More

How to declare reference types in JShell in Java 9?

raja
raja
Updated on 24-Apr-2020 238 Views

JShell is an interactive tool in Java 9 that allows user inputs, evaluates it, and prints output to the user.Unlike a value type, a reference type doesn't store its value directly. Instead, it will store the address where a value is stored. It means that a reference type contains a pointer to another memory location that holds the data. The reference types are String, arrays, class, and delegates.In the below code snippet, when we create a new instance of Animal, it can be created on the heap memory. The new Animal() creates an object on the Heap. Animal@73846619, the object is ...

Read More

How to initialize an array in JShell in Java 9?

raja
raja
Updated on 24-Apr-2020 556 Views

JShell is a command-line tool used to evaluate simple statements, expressions, classes, methods, variables, etc.. and prints the output immediately to the user.An array in Java is also an object. We need to declare an array and then created. In order to declare a variable that holds an array of integers, we can mention like int[] array. In an array, the index starts from 0 to (length of array - 1).In the below code snippet, we can use an index to find the specific element from the array. It will be done by using an indexing operator: []. The expression marks[0] maps ...

Read More

How to create wrapper objects in JShell in Java 9?

raja
raja
Updated on 24-Apr-2020 332 Views

Each primitive type in Java has a corresponding built-in wrapper class, and these wrapper classes are also immutable. Integer, Float, Double, Byte, and etc.. are some of the built-in wrapper classes. The main incentive of using such wrappers in our code is accessing type information about the corresponding primitive type, Auto-Boxing feature, where a primitive data is automatically promoted to an object reference type, and moving primitive type data around data structures.We can create an instance of Wrapper Classes by using a new operator, and also use the valueOf() method within types such as Integer to create a wrapper object. ...

Read More

Boolean.Parse() Method in C#

AmitDiwan
AmitDiwan
Updated on 24-Apr-2020 2K+ Views

The Boolean.Parse() method in C# is used to convert the specified string representation of a logical value to its Boolean equivalent.SyntaxFollowing is the syntax −public static bool Parse (string val);Above, the parameter value is a string containing the value to convert.ExampleLet us now see an example to implement the Boolean.Parse() method −using System; public class Demo {    public static void Main(){       bool b;       b = bool.Parse("FALSE");       Console.WriteLine("After parsing = "+b);    } }OutputThis will produce the following output −After parsing = FalseExampleLet us see another example −using System; public class ...

Read More

How to show reflection frames of StackFrame in Java 9?

raja
raja
Updated on 24-Apr-2020 216 Views

A standard API has been provided in Java 9 using java.lang.StackWalker class. This class designed to be efficient by allowing lazy access to the stack frames. A couple of other options allow in a stack trace that includes implementation and/or reflection frames, and it can be useful for debugging purposes. For instance, we add SHOW_REFLECT_FRAMES option to StackWalker instance upon creation, so that frames for reflective methods are printed as well.In the below example, we can able to show reflection frames of StackFrameExampleimport java.lang.StackWalker.Option; import java.lang.StackWalker.StackFrame; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.List; import java.util.stream.Collectors; public class ReflectionFrameTest {    public static ...

Read More

How to skip certain classes in StackFrame in Java 9?

raja
raja
Updated on 24-Apr-2020 276 Views

StackWalker API has been introduced in Java 9, and it gives a snapshot of the stack trace of current thread at any given point of time and has methods to walk over it. The advantage of using StackWalker class over Thread::getStackTrace() is to filter or skip certain classes and get the instance of declaring the class itself and get either short stack trace or full stack trace instead of pulling the complete stack trace itself.In the below example, we can use java.util.stream.Stream.skip() method to skip Stack Frames.Exampleimport java.lang.StackWalker.*; import java.util.Optional; import java.util.List; import java.util.stream.Collectors; import java.lang.StackWalker.StackFrame; public class StackWalkerSkipTest {    public ...

Read More

How to define a switch statement in JShell in Java 9?

raja
raja
Updated on 23-Apr-2020 227 Views

JShell is based on the REPL (Read-Evaluate-Print-Loop) introduced in Java 9. This tool can be used to execute simple statements, evaluate it, and prints the result.A switch statement can test multiple conditions just like an else clause and handles the default possibility. The default clause can be executed when none of the cases match, and a break statement can be used to break out of switch after a successful match.In the below code snippet, we can define the switch statement in JShell.Snippet-1jshell> int i = 10; i ==> 10 jshell> switch(i) { ...> case 1 ...

Read More

How to use intermediate stream operations in JShell in Java 9?

raja
raja
Updated on 23-Apr-2020 375 Views

JShell is a tool introduced in Java 9, and it accepts simple statements like expressions, variables, methods, classes, etc.. as input and produces immediate results.A Stream is a sequence of values. An intermediate stream operation is an operation that takes a stream. For instance, it can be applied to a lambda expression and produces another stream of elements as its result.The most popular intermediate stream operations are mentioned below:1) sorted(): This method preserves the elements of the consumed stream as a result but also puts them in natural sorted order.2) distinct(): This method returns a stream retaining only unique elements of the input ...

Read More

How to implement java.time.LocalDate using JShell in Java 9?

raja
raja
Updated on 22-Apr-2020 767 Views

JShell is a REPL (Read-Eval-Print-Loop) interactive tool introduced in Java 9 that takes input, evaluates it, and returns output to a user.java.util.LocalDate class provides a number of methods to retrieve Date information: Day/Month/Year and related attributes Date meta-information: Classification-related information such as whether a leap year, etc. LocalDate class is immutable, and we can use different methods provided to add and subtract days, months, and years. Each of these returns a new instance of LocalDate.In the below two code snippets, we can able to print different operations using LocalDate class.Snippet-1jshell> import java.time.*; jshell> LocalDate today = LocalDate.now() today ==> 2020-04-22 jshell> today.getYear() $3 ==> ...

Read More
Showing 50611–50620 of 61,248 articles
Advertisements