Concrete Method in Java Interface

Maruthi Krishna
Updated on 29-Jun-2020 13:44:28

3K+ Views

Interface in Java is similar to class but, it contains only abstract methods and fields which are final and static.Since all the methods are abstract you cannot instantiate it. To use it, you need to implement this interface using a class and provide body to all the abstract methods int it.Concrete methods in an interfaceAll the methods in an interface must be abstract, you cannot have a concrete method (the one which has body) if you try to do so, it gives you a compile time error saying “interface abstract methods cannot have body”.ExampleIn the following Java program, we are ... Read More

Insert All Elements of Another Collection to a Specified Index of Java ArrayList

Ankith Reddy
Updated on 29-Jun-2020 13:43:20

349 Views

The elements of a Collection can be inserted at the specified index of the ArrayList using the method java.util.ArrayList.addAll(). This method has two parameters i.e. the specific index at which to start inserting the Collection elements in the ArrayList and the Collection itself.If there is an element already present at the index specified by ArrayList.addAll() then that element and all subsequent elements are shifted to the right to make the space for the Collection elements in the ArrayList.A program that demonstrates this is given as follow.Example Live  Demoimport java.util.ArrayList; import java.util.Vector; public class Demo {    public static void main(String[] args) ... Read More

Get Current Thread Name in Android

Anvi Jain
Updated on 29-Jun-2020 13:42:54

5K+ Views

Before getting into an example, we should know what thread is. A thread is a lightweight sub-process, it going to do background operations without interrupt to ui. This example demonstrate about How to get current thread name 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.     In the above code, we have taken textview. It contains information about current thread name.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; ... Read More

Get Unmodifiable View of Specified ArrayList in Java

Arjun Thakur
Updated on 29-Jun-2020 13:42:25

538 Views

The unmodifiable view of the specified ArrayList can be obtained by using the method java.util.Collections.unmodifiableList(). This method has a single parameter i.e. the ArrayList and it returns the unmodifiable view of that ArrayList.A program that demonstrates this is given as followsExample Live Demoimport java.util.ArrayList; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Demo {    public static void main(String args[]) throws Exception {       List aList = new ArrayList();       aList.add("Sally");       aList.add("George");       aList.add("John");       aList.add("Susan");       aList.add("Martha");       aList = Collections.unmodifiableList(aList);       System.out.println("The ... Read More

Get Current Thread Interruption Status in Android

Nishtha Thakur
Updated on 29-Jun-2020 13:41:24

280 Views

Before getting into an example, we should know what thread is. A thread is a lightweight sub-process, it going to do background operations without interrupt to ui. This example demonstrate How to get current thread is interrupted 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.     In the above code, we have taken textview. It contains information about the current thread is interrupted.package com.example.myapplication; import android.annotation.SuppressLint; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; ... Read More

Run SQL Script Using JDBC

Nishtha Thakur
Updated on 29-Jun-2020 13:41:00

17K+ Views

A database script file is a file that contains multiple SQL quries separated from each other. Usually, these files have the .sql extention.Running .sql script files in JavaYou can execute .sql script files in Java using the runScript() method of the ScriptRunner class of Apache iBatis. To this method you need to pass a connection object.Therefore to run a script file −Register the MySQL JDBC Driver using the registerDriver() method of the DriverManager class.Create a connection object to establish connection with the MySQL database using the getConnection() method.Initialize the ScriptRunner class of the package org.apache.ibatis.jdbc.Create a Reader object to read ... Read More

Get Last Index of Element in an ArrayList in Java

Ankith Reddy
Updated on 29-Jun-2020 13:40:46

828 Views

The last index of a particular element in an ArrayList can be obtained by using the method java.util.ArrayList.lastIndexOf(). This method returns the index of the last occurance of the element that is specified. If the element is not available in the ArrayList, then this method returns -1.A program that demonstrates this is given as follows.Example Live Demoimport java.util.ArrayList; import java.util.List; public class Demo {    public static void main(String[] args) {       List aList = new ArrayList();       aList.add("Orange");       aList.add("Apple");       aList.add("Peach");       aList.add("Orange");       aList.add("Mango");     ... Read More

Get Current Thread's Daemon Status in Android

Anvi Jain
Updated on 29-Jun-2020 13:40:37

211 Views

Before getting into an example, we should know what thread is. A thread is a lightweight sub-process, it going to do back ground operations without interrupt to ui. This example demonstrate How to get current thread is daemon 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.     In the above code, we have taken textview. It contains information about the current thread is a daemon.Step 3 − Add the following code ... Read More

Check If Current Thread Is Alive in Android

Nishtha Thakur
Updated on 29-Jun-2020 13:40:04

215 Views

Before getting into an example, we should know what thread is. A thread is a lightweight sub-process, it going to do back ground operations without interrupt to ui. This example demonstrate about How to get current thread is alive or not 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.     In the above code, we have taken textview. It contains information about the current thread is alive or not.Step 3 − ... Read More

Get Current Thread ID in Android

Anvi Jain
Updated on 29-Jun-2020 13:39:32

1K+ Views

Before getting into example, we should know what thread is. A thread is a lightweight sub-process, it going to do back ground operations without interrupt to ui. This example demonstrate about How to get current thread id 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.     In the above code, we have taken textview. It contains information about current thread id.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; ... Read More

Advertisements