This example demonstrates how do I turn on Flash light programatically in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.javaimport android.content.Context; import android.content.DialogInterface; import android.content.pm.PackageManager; import android.hardware.camera2.CameraAccessException; import android.hardware.camera2.CameraManager; import android.os.Bundle; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.widget.CompoundButton; import android.widget.ToggleButton; public class MainActivity extends AppCompatActivity { private CameraManager mCameraManager; private String mCameraId; private ToggleButton toggleButton; ... Read More
A Java class file has a ".class" extension and contains the Java bytecode. This class file can be executed by the Java Virtual Machine (JVM). A ".class" file is created as a result of successful compilation by the Java compiler from the ".java" file. Each class in the .java file is compiled into a separate class file if the ".java " file has more than one class.Exampleclass A { A() { System.out.println("This is class A"); } } class B { B() { System.out.println("This is class B"); } } class C { ... Read More
SSL certificates are a very crucial part of the website. They play a key role in securing the exchange of information on both client and server sides by activating an HTTPS secure connection. In the below article with the PowerShell, we will get the certificate validity date (starting and expiry date) for the certificate using PowerShell.To achieve this, we need to make httpwebrequest but before that, we will ignore SSL warning by the below command.[Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }And then we wil make the HTTP web request by calling a .Net class.$url = "https://www.microsoft.com/" $req = [Net.HttpWebRequest]::Create($url)When we check the ... Read More
Whenever you need to create an object which cannot be changed after initialization you can define an immutable object. There are no specific rules to create immutable objects, the idea is to restrict the access of the fields of a class after initialization.A Set is an interface in collection framework, which does not allow duplicate values.Method to convert a set to immutableYes, Java provides a method named unmodifiableSet() in the Collections class. This method accepts a collection object as a parameter and returns an unmodifiable i.ie immutable form of it.ExampleIn the following Java program, we have created a HashSet object ... Read More
When a value is assigned to a variable that is less than the minimum allowed value for that variable, then an underflow occurs. There is no exception thrown by the JVM if an underflow occurs in Java and it is the responsibility of a programmer to handle the underflow conditions.Examplepublic class UnderlowTest { public static void main(String[] args) { int num1 = -2147483648; int num2 = -1; System.out.println("Number 1: " + num1); System.out.println("Number 2: " + num2); long sum = (long)num1 + (long)num2; ... Read More
TreeSet provides an implementation of the Set interface that uses a tree for storage. Objects are stored in a sorted and ascending order.Access and retrieval times are quite fast, which makes TreeSet an excellent choice when storing large amounts of sorted information that must be found quickly.The reason is, if you look at the internal implementation of the TreeSet, it uses natural ordering, that means TreeSet uses Comparable interface by default to sort its value by comparing other value.Examplepublic class TreeSetDemo { public static void main(String args[]) { TreeSet treeSet = new TreeSet(); ... Read More
Array is a container which can hold a fix number of entities, which are of the same type. Each entity of an array is known as element and, the position of each element is indicated by an integer (starting from 0) value known as index.Exampleimport java.util.Arrays; public class ArrayExample { public static void main(String args[]) { Number integerArray[] = new Integer[3]; integerArray[0] = 25; integerArray[1] = 32; integerArray[2] = 56; System.out.println(Arrays.toString(integerArray)); } }Output[25, 32, 56]Whereas a Set object is a collection (object) stores ... Read More
If you compare the operator with NULL value then you will get NULL value always and no result.Let us see some examples for comparison −mysql> select 10 NULL; +------------+ | 10 NULL | +------------+ | NULL | +------------+ 1 row in set (0.00 sec) mysql> select NULL NULL; +--------------+ | NULL NULL | +--------------+ | NULL | +--------------+ 1 row in set (0.00 sec) mysql> select 'Chris' NULL; +-----------------+ | 'Chris' NULL | +-----------------+ | NULL | +-----------------+ 1 row in ... Read More
We can convert a hex string to byte array in Java by first converting the hexadecimal number to integer value using the parseInt() method of the Integer class in java. This will return an integer value which will be the decimal conversion of hexadecimal value. We will then use the toByteArray() method of BigInteger class that will return a byte array.Example Live Demoimport java.math.BigInteger; public class Demo { public static void main(String args[]) { String str = "1D08A"; int it = Integer.parseInt(str, 16); System.out.println("Hexadecimal String " + str); ... Read More
A Run time exception or an unchecked exception is the one which occurs at the time of execution. These include programming bugs, such as logic errors or improper use of an API. Runtime exceptions are ignored at the time of compilation.IndexOutOfBoundsException, ArithmeticException, ArrayStoreException and, ClassCastException are the examples of run time exceptions.ExampleIn following Java program, we have an array with size 5 and we are trying to access the 6th element, this generates ArrayIndexOutOfBoundsException.public class ExceptionExample { public static void main(String[] args) { //Creating an integer array with size 5 int inpuArray[] = ... Read More