Overload Default Methods of an Interface in Java

Maruthi Krishna
Updated on 10-Sep-2019 10:59:13

2K+ Views

An interface in Java is similar to a class but, it contains only abstract methods and fields which are final and static.Since Java8 static methods and default methods are introduced in interfaces.Default methods − Unlike other abstract methods these are the methods that can have a default implementation. If you have a default method in an interface, it is not mandatory to override (provide body) it in the classes that are already implementing this interface.In short, you can access the default methods of an interface using the objects of the implementing classes.Example Live Demointerface MyInterface{    public static int num = ... Read More

Hide Unsupported Interface Methods from Class in Java

Maruthi Krishna
Updated on 10-Sep-2019 10:49:39

1K+ Views

Actually you can’t, once you implement an interface it is a must to provide implementation to all its methods or, make the class abstract. There is no way to skip methods of an interface without implementing (unless they are default methods). Still, if you try to skip implementing methods of an interface a compile-time error would be generated.Example Live Demointerface MyInterface{    public static int num = 100;    public void sample();    public void getDetails();    public void setNumber(int num);    public void setString(String data); } public class InterfaceExample implements MyInterface{    public static int num = 10000;    public ... Read More

Change Access Specifier from Public While Implementing Methods from Interface in Java

Maruthi Krishna
Updated on 10-Sep-2019 10:43:28

662 Views

An interface in Java is a specification of method prototypes. Whenever you need to guide the programmer or, make a contract specifying how the methods and fields of a type should be you can define an interface.To create an object of this type you need to implement this interface, provide a body for all the abstract methods of the interface and obtain the object of the implementing class.All the methods of the interface are public and abstract and, we will define an interface using the interface keyword as shown below −interface MyInterface{    public void display();    public void setName(String ... Read More

Synchronize Abstract Methods in Java

Maruthi Krishna
Updated on 10-Sep-2019 10:36:50

981 Views

An abstract method is the one that does not have a body. It contains only a method signature with a semi colon and, an abstract keyword before it.public abstract myMethod();To use an abstract method, you need to inherit it by extending its class and provide implementation (body) to it. If a class contains at least one abstract method, you must declare it abstract.Example Live Demoimport java.io.IOException; abstract class MyClass {    public abstract void display(); } public class AbstractClassExample extends MyClass{    public void display(){       System.out.println("subclass implementation of the display method");    }    public static void main(String ... Read More

Achieve Abstraction Using Interfaces in Java

Maruthi Krishna
Updated on 10-Sep-2019 10:28:50

9K+ Views

Abstraction is a process of hiding the implementation details from the user, only the functionality will be provided to the user. In other words, the user will have the information on what the object does instead of how it does it.Since all the methods of the interface are abstract and the user doesn’t know how a method is written except the method signature/prototype. Using interfaces, you can achieve (complete) abstraction.Abstraction in interfacesAn interface in Java is a specification of method prototypes. Whenever you need to guide the programmer or, make a contract specifying how the methods and fields of a ... Read More

CAN FALSE Match Some String in MySQL

AmitDiwan
Updated on 09-Sep-2019 09:11:53

85 Views

Yes, you can use false as 0 to match.Let us first create a table −mysql> create table DemoTable804 ( Id varchar(100) ); Query OK, 0 rows affected (0.66 sec)Insert some records in the table using insert command −mysql> insert into DemoTable804 values('101John'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable804 values('Carol1002'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable804 values('1000'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable804 values('1010Bob'); Query OK, 1 row affected (0.10 sec)Display all records from the table using select statement −mysql> select *from DemoTable804;This ... Read More

Set Default Values for Columns in MySQL Table

AmitDiwan
Updated on 09-Sep-2019 09:10:32

2K+ Views

To set default values for columns while creating a table, DEFAULT. Let us first see an example and create a table. As you can see below, while creating the table, we have set DEFAULT −mysql> create table DemoTable803 ( UserId int DEFAULT 101, UserName varchar(100) DEFAULT 'Chris' ); Query OK, 0 rows affected (1.18 sec)Insert some records in the table using insert command. For the values we are not inserting, the default values will get set automatically −mysql> insert into DemoTable803 values(102, 'Chris'); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable803(UserName) ... Read More

Display and Concatenate Records Ignoring Null Values in MySQL

AmitDiwan
Updated on 09-Sep-2019 09:08:45

799 Views

Use CONCAT() to concatenate records whereas IFNULL() to check for NULL values.Let us first create a table −mysql> create table DemoTable802 ( FirstName varchar(100), LastName varchar(100) ); Query OK, 0 rows affected (1.01 sec)Insert some records in the table using insert command −mysql> insert into DemoTable802 values('Adam', 'Smith'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable802 values('Carol', NULL); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable802 values(NULL, 'Taylor'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable802 values(NULL, NULL); Query OK, 1 row affected (0.21 sec)Display ... Read More

MySQL Query to Perform Sort Order on Same Field

AmitDiwan
Updated on 09-Sep-2019 09:06:18

168 Views

For this, use ORDER BY IF().Let us first create a table −mysql> create table DemoTable801 ( Score int ); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable801 values(30); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable801 values(99); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable801 values(45); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable801 values(55); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable801 values(99); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable801 values(69); ... Read More

Select Single Value from Similar Values in MySQL

AmitDiwan
Updated on 09-Sep-2019 09:04:29

206 Views

Let us first create a table −mysql> create table DemoTable800 ( Value int ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command. Here, we have inserted 5 similar values −mysql> insert into DemoTable800 values(10); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable800 values(10); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable800 values(10); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable800 values(10); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable800 values(10); Query OK, 1 row affected (0.10 sec)Display all ... Read More

Advertisements