Let us apply the following operations on BigDecimal using the in-built methods in Java −Addition: add() method Subtraction: subtract() method Multiplication: multiply() method Division: divide() methodLet us create three BigInteger objects −BigDecimal val1 = new BigDecimal("37578975587.876876989"); BigDecimal val2 = new BigDecimal("62567875598.976876569"); BigDecimal val3 = new BigDecimal("72567875598.376876569");Apply mathematical operations on them −val1 = val1.add(val2); System.out.println("Addition Operation = " + val1); val1 = val1.multiply(val2); System.out.println("Multiplication Operation = " + val1); val2 = val3.subtract(val2); System.out.println("Subtract Operation = " + val2);The following is an example −Example Live Demoimport java.math.BigDecimal; public class Demo { public static void main(String[] argv) throws Exception { ... Read More
Firstly, let us declare and initialize three long values −long val1 = 98799; long val2 = 98567; long val3 = 98768;Now, find the maximum of three long values using the following condition −// checking for maximum if (val2 > val1) { val1 = val2; } if (val3 > val1) { val1 = val3; }The following is the complete example to get the maximum value −Example Live Demopublic class Demo { public static void main(String[] args) { long val1 = 98799; ... Read More
This error occurs when you try to use a reserved word as a table or column name. It can occur due to −Case 1: Whenever you use reserved word as a table name −mysql> create table insert −> ( −> Id int −> );The error is as follows −ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'insert ( Id int )' at line 1The above error occurred because the word ‘insert’ is a keyword in MySQL.Case 2 − Whenever you ... Read More
You can use multiplication operator (*) between two cells. The syntax is as followsSELECT yourColumnName1, yourColumnName2, yourColumnName1*yourColumnName2 as ‘anyVariableName’ from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table MultiplicationDemo -> ( -> FirstPrice int, -> SecondPrice int -> ); Query OK, 0 rows affected (0.63 sec)Now you can display all records from the table using insert command. The query is as followsmysql> insert into MultiplicationDemo values(10, 2); Query OK, 1 row affected (0.17 sec) mysql> insert into MultiplicationDemo values(4, 2); Query OK, ... Read More
To add a live camera preview to our default UIView in swift we can either use AVFoundation framework of iOS SDK or native UIImagePickerController(). In this example we’ll be using ImagePicker as our aim is to present camera preview on the UIView and Imagepicker is suitable for that task. AVFoundation can be used when we need a lot of customization on our camera or different types of custom actions.To show a camera preview on the UIView we need to perform the following steps.Create a UIImagePickerController object.Conform our class to UIImagePickerControllerDelegate and UINavigationControllerDelegate.Assign delegates to the object we created in step ... Read More
When a garbage collector determines that no more references are made to a particular object, then the finalize() method is called by the garbage collector on that object. The finalize() method requires no parameters and does not return a value.A program that demonstrates the finalize() method in Java is given as follows:Example Live Demoimport java.util.*; public class Demo extends GregorianCalendar { public static void main(String[] args) { try { Demo obj = new Demo(); System.out.println("The current time is: " + obj.getTime()); obj.finalize(); ... Read More
To select MySQL rows where today’s date is between two date columns, you need to use AND operator. The syntax is as follows:SELECT *FROM yourTableName WHERE yourDateColumnName1 = ‘’yourDateValue’;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table selectDates -> ( -> Id int NOT NULL AUTO_INCREMENT, -> StartingDate date, -> EndingDate date, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.80 sec)Now you can insert some records in ... Read More
The java.math.BigDecimal class provides operations for arithmetic, scale manipulation, rounding, comparison, hashing, and format conversion.Two types of operations are provided for manipulating the scale of a BigDecimal −scaling/rounding operationsdecimal point motion operationsThe following are some of the constructors of the BigDecimal values −Sr.No.Constructor & Description1BigDecimal(BigInteger val)This constructor is used to translates a BigInteger into a BigDecimal.2BigDecimal(BigInteger unscaledVal, int scale)This constructor is used to translate a BigInteger unscaled value and an int scale into a BigDecimal.3BigDecimal(BigInteger unscaledVal, int scale, MathContext mc)This constructor is used to translate a BigInteger unscaled value and an int scale into a BigDecimal, with rounding according to ... Read More
Firstly, let us declare and initialize three long values.long val1 = 88799; long val2 = 98567; long val3 = 98768;Now, find the minimum of three long values using the following condition −// checking for maximum if (val2 < val1) { val1 = val2; } if (val3 < val1) { val1 = val3; }The following is the complete example to get the minimum value −Example Live Demopublic class Demo { public static void main(String[] args) { long val1 = 88799; long ... Read More
Increase the varchar size of an existing column in a database with the help of CHANGE command. The syntax is as follows −alter table yourTableName change yourColumnName yourColumnName dataType;Here, we are creating a table with a single column and varchar size 200 −mysql> create table IncreaseVarcharDemo −> ( −> StudentId varchar(200) −> ); Query OK, 0 rows affected (0.60 sec)Now insert record in the table. The query is as follows −mysql> insert into IncreaseVarcharDemo values('John123'); Query OK, 1 row affected (0.16 sec)Displaying all records from the table with the help of the following query −mysql> select *from ... Read More