Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles on Trending Technologies
Technical articles with clear explanations and examples
Using underscore in Numeric Literals in Java
Followig is the code showing how to use underscore in numeric literals in Java −Example Live Demopublic class Demo{ public static void main (String[] args) throws java.lang.Exception{ int my_num_1 = 6_78_00_120; System.out.println("The number is : " + my_num_1); long my_num_2 = 2_00_11_001; System.out.println("The number is : " + my_num_2); float my_num_3 = 4.01_981F; System.out.println("The number is : " + my_num_3); double my_num_4 = 12.89_46_061; System.out.println("The number is : " + my_num_4); } }OutputThe number is ...
Read MoreUsing predefined class name as Class or Variable name in Java
Using a predefined class name as a class nameLet us see an example −Example Live Demopublic class Number{ public static void main (String[] args){ System.out.println("Pre-defined class name can be used as a class name"); } }OutputPre-defined class name can be used as a class nameThe class Number has a main function that displays a message when it is executed. The main function takes string values as arguments.Using a predefined class name as a variable nameLet us see an example −Example Live Demopublic class String{ public static void main (java.lang.String[] args){ System.out.println("Pre-defined class name ...
Read MoreUsing TreeMap to sort User-defined Objects in Java
To sort user-defined object in Java, the code is as follows −Example Live Demoimport java.io.*; import java.util.*; public class Demo{ static void sort_objects(String my_data){ String[] my_vals = my_data.split(" "); Map my_map = new TreeMap(); for (int i = 1; i < my_vals.length; i += 2){ int my_age = Integer.parseInt(my_vals[i]); String name = my_vals[i - 1]; if (my_map.containsKey(my_age)){ ArrayList my_list = my_map.get(my_age); my_list.add(name); ...
Read MoreHow to lay out Views in RelativeLayout programmatically in Android?
This example demonstrates how to lay out Views in RelativeLayout programmatically 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.javapackage com.app.sample; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.RelativeLayout; import android.widget.RelativeLayout.LayoutParams; import android.widget.Toast; public class MainActivity extends Activity { RelativeLayout relativelayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ...
Read MoreUnreachable Code Error in Java
Unreachable code error occurs when the code can’t be compiled due to a variety of reasons, some of which include: infinite loop, return statement before the unreachable line of code.Let us see an example −Example Live Demopublic class Demo{ public static void main(String args[]){ int val = 5; for (;;){ if (val == 5){ break; System.out.println("If the condition is not true, this line would be printed. "); } } } ...
Read MoreHow to implement custom deserializer using @JsonDeserialize annotation in Java?\\n
The @JsonDeserialize annotation is used to declare custom deserializer while deserializing JSON to Java object. We can implement a custom deserializer by extending the StdDeserializer class with a generic type Employee and need to override the deserialize() method of StdDeserializer class.Syntax@Target(value={ANNOTATION_TYPE, METHOD, FIELD, TYPE, PARAMETER}) @Retention(value=RUNTIME) public @interface JsonDeserializeIn the below program, we can implement a custom deserializer using @JsonDeserialize annotationExampleimport java.io.*; import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.*; import com.fasterxml.jackson.databind.deser.std.*; public class JsonDeSerializeAnnotationTest { public static void main (String[] args) throws JsonProcessingException, IOException { Employee emp = new Employee(115, "Adithya"); ObjectMapper mapper = new ObjectMapper(); ...
Read MoreHow to send a SMS using SMSmanager in Dual SIM mobile in Android?
This example demonstrates how do I send 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 androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; import android.Manifest; import android.content.pm.PackageManager; import android.os.Bundle; import android.telephony.SmsManager; import android.text.TextUtils; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends AppCompatActivity { Button btnSend; EditText editTextNum, editTextMsg; private static final ...
Read MoreHow to control serialization through @JSON annotation using flexjson in Java?\\n
The @JSON annotation is used by JSONSerializer class to exclude or include a field during the serialization process. We can use the serialize() method of JSONSerializer class to perform a shallow serialization of the target instance.Syntax@Retention(value=RUNTIME) @Target(value={FIELD, TYPE, METHOD}) public @interface JSONExampleimport flexjson.JSONSerializer; import flexjson.JSON; public class JSONAnnotationTest { public static void main(String[] args) { JSONSerializer serializer = new JSONSerializer().prettyPrint(true); Employee emp = new Employee("Raja", "Ramesh", 30, "Hyderabad"); String jsonStr = serializer.serialize(emp); System.out.println(jsonStr); } } // Employee class class Employee { private String firstName, lastName, address; private ...
Read MoreBakhshali Approximation for computing square roots in C program
Bakhshali approximation is a method of computing the square root of a number which is not a perfect square. Now, lets brush-related terms to easily understand the concept.Square root of a number x is a number that satisfies the following condition, y2 = x.Perfect Square is a number whose square roots are w. For example 16 is perfect square as its roots are 4 and 4.There are multiple methods defined mathematically to find the square root of a number. In this tutorial, we are going to learn about Bakhshali approximation to find the square root of a number.It is a ...
Read MoreBalance pans using given weights that are powers of a number in C++ program
STATEMENT − Balance pans using given weights that are powers of a number.DESCRIPTION − In this problem we are given a pan based weighing machine. we are given a weight T and some other weights whose values are powers of a number a. We need to balance the pans using the given weights.Now, based on this we have this equation, T + (some power of a) = (some other power of a)Now, we should remember that there is exactly one weight corresponding to a power value.Example, T = 12 : a = 4Using the below values, we can balance the ...
Read More