The elements of the ArrayList can be accessed one by one by using a for loop. A program that demonstrates this is given as followsExample Live Demoimport java.util.ArrayList; import java.util.List; public class Demo { public static void main(String[] args) { ArrayList aList = new ArrayList(); aList.add("Sun"); aList.add("Moon"); aList.add("Star"); aList.add("Planet"); aList.add("Comet"); System.out.println("The ArrayList elements are:"); for (String s : aList) { System.out.println(s); } } }OutputThe output of the above ... Read More
This example demonstrate about How to get local time and date in android using LocalDateTime API class.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. In the above code, we have taken textview to show time and date.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.TextView; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle ... Read More
This example demonstrate about How to get local date in android using local date API class.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. In the above code, we have taken textview to show date.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.icu.util.LocaleData; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; import java.awt.font.TextAttribute; import java.time.LocalDate; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) ... Read More
Now let us see a program of Intel 8085 Microprocessor. This program will convert binary or hexadecimal number to ASCII values.Problem StatementWrite 8085 Assembly language program to convert binary or Hexadecimal characters to ASCII values. DiscussionWe know that the ASCII of number 00H is 30H (48D), and ASCII of 09H is39H (57D). So all other numbers are in the range 30H to 39H. TheASCII value of 0AH is 41H (65D) and ASCII of 0FH is 46H (70D), so all other alphabets (B, C, D, E, F) are in the range 41H to 46H.Here we are providing hexadecimal digit at memory location ... Read More
The main purpose of constructors in Java is to initialize the instance variables of a class.But, if a class have Static variables you cannot initialize them using the constructors (you can assign values to static variables in constructors but in that scenario, we are just assigning values to static variables). because static variables are loaded into the memory before instantiation (i.e. before constructors are invoked)So, we should initialize static variables from static context. We cannot use static before constructors, Therefore, as an alternation to you can use static blocks to initialize static variables.Static blockA static block is a block of ... Read More
A code block/statement in Java to which the control never reaches and never gets executed during the lifetime of the program is known as unreachable block/statement.Generally, it happens whenever a piece of code hasA return statement before it.An infinite loop before it.Java does not support unreachable code. If you have any such statements, (which are unreachable) Java compiler raises a compile time error.Example1In the following Java program, the class UnreachableCodeExample has a method named greet which returns a String value. After the return statement it has a print statement. Live Demopublic class UnreachableCodeExample { public String greet() { ... Read More
A code block/statement in Java to which the control never reaches and never gets executed during the lifetime of the program is known as unreachable block/statement.public class UnreachableCodeExample { public String greet() { System.out.println("This is a greet method "); return "Hello"; System.out.println("This is an unreachable code "); } public static void main(String args[]) { new UnreachableCodeExample().greet(); } }Dead codeA dead code is an unreachable code, but it doesn’t generate compile time error. But if you execute it in eclipse it gives you a warning.ExampleIn ... Read More
An exception is an issue (run time error) occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed.Printing the Exception messageYou can print the exception message in Java using one of the following methods which are inherited from Throwable class.printStackTrace() − This method prints the backtrace to the standard error stream.getMessage() − This method returns the detail message string of the current throwable object.toString() − This message prints the short description of the current throwable object.Example Live Demoimport java.util.Scanner; public class ... Read More
Create TreeSet and add elements to itTreeSet tSet = new TreeSet(); tSet.add("P"); tSet.add("Q"); tSet.add("R"); tSet.add("S");Now, let us traverse elements in descending orderIterator j = tSet.descendingIterator(); while(j.hasNext()) { System.out.println(j.next()); }The following is an example to traverse TreeSet elements in descending orderExample Live Demoimport java.util.*; public class Demo { public static void main(String args[]){ TreeSet tSet = new TreeSet(); tSet.add("P"); tSet.add("Q"); tSet.add("R"); tSet.add("S"); System.out.println("TreeSet elements..."); Iterator i = tSet.iterator(); while(i.hasNext()){ System.out.println(i.next()); ... Read More
While inserting data into a table with auto-incremented column, just leave that particular column out and insert remaining values by specifying the remaining columns using the following syntax of the INSERT statement −INSERT into table_name (column_name1, column_name2....) values(value1, value2....)ExampleLet us create a table with name sales in MySQL database, with one of the columns as auto-incremented, using CREATE statement as shown below −CREATE TABLE Sales( ID INT PRIMARY KEY AUTO_INCREMENT, ProductName VARCHAR (20), CustomerName VARCHAR (20), DispatchDate date, DeliveryTime time, Price INT, Location VARCHAR(20) );Following JDBC program establishes a connection with the database ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP