Call Super in Constructor Without Extending Any Class in Java

Maruthi Krishna
Updated on 29-Jun-2020 12:41:12

3K+ Views

A super keyword is a reference of the superclass object in Java. Using this, you can invoke the instance methods constructors and, variables, of a superclass.Calling the constructor of a superclassYou can call the constructor of a superclass from the subclass’s constructor.ExampleConsider the following example, it has two classes SuperClass class and SubClass where the SubClass extends the SuperClass. The superclass has a parameterized constructor, we are invoking it from the subclass using the "super" keyword. Live Democlass SuperClass{    SuperClass(int data){       System.out.println("Superclass's constructor: "+data);    } } public class SubClass extends SuperClass{    SubClass(int data) {       ... Read More

Call Superclass Methods from a Static Method in Java

Maruthi Krishna
Updated on 29-Jun-2020 12:38:24

3K+ Views

Inheritance can be defined as the process where one (parent/super) class acquires the properties (methods and fields) of another (child/sub). With the use of inheritance, the information is made manageable in a hierarchical order. The class which inherits the properties is known as a subclass and the class whose properties are inherited is called superclass.  In short, in inheritance, you can access the members (variables and methods) of the superclass using the subclass object.Example Live Democlass SuperClass {    public void display(){       System.out.println("Hello this is the method of the superclass");    } } public class SubClass extends SuperClass ... Read More

Call Superclass's Static Method from Subclass in Java

Maruthi Krishna
Updated on 29-Jun-2020 12:37:42

3K+ Views

A static method is the one which you can call without instantiating the class. If you want to call a static method of the superclass, you can call it directly using the class name.Example Live Demopublic class Sample{    public static void display(){       System.out.println("This is the static method........");    }    public static void main(String args[]){       Sample.display();    } }OutputThis is the static method........It also works, if you call a static method using an instance. But, it is not recommended. Live Demopublic class Sample{    public static void display(){       System.out.println("This is the static ... Read More

Select SUM or 0 if No Records Exist in MySQL

Chandu yadav
Updated on 29-Jun-2020 12:27:22

2K+ Views

You can use aggregate function sum() inside COALESCE(). The below syntax returns the sum of all if the record exists otherwise 0 is returned. The syntax is as follows.select COALESCE(sum(yourColumnName2), 0) AS anyVariableName from yourTableName where yourColumnName1 like '%yourValue%';To understand the above syntax, let us create a table. The query to create a table is as follows.mysql> create table SumDemo -> ( -> Words varchar(100), -> Counter int -> ); Query OK, 0 rows affected (0.93 sec)Insert some records in the table using insert command. The query is as follows.mysql> insert into SumDemo values('Are You There', 10); Query OK, 1 ... Read More

Uses of super Keyword in Java

Maruthi Krishna
Updated on 29-Jun-2020 12:23:24

1K+ Views

The super keyword in Java is a reference to the object of the parent/superclass. Using it, you can refer/call a field, a method or, a constructor of the immediate superclass.Referring to a field using super keywordAs mentioned above, you can refer to an instance filed/variable of the immediate superclass from an instance method or, a constructor of a subclass, using the "super" keyword.If a class extends another class, a copy of members of the parent class will be created in the subclass i.e. Using the object of the subclass you can access the members of both subclass and the superclass.If ... Read More

Assign a Reference to 'this' in Java

Maruthi Krishna
Updated on 29-Jun-2020 12:21:45

1K+ Views

The "this" keyword in Java is used as a reference to the current object, within an instance method or a constructor. Using it, you can refer the members of a class such as constructors, variables, and methods.Assigning reference to "this"According to the definition "this" is a keyword which acts as a reference to the current object (the object from whose constructor/method you are using it), its value id is fixed. Therefore, you cannot assign a new reference value to it. Moreover, it is just a keyword, not a variable.Still, if you try to it assign a reference value to "this" it ... Read More

Return This Keyword from a Method in Java

Maruthi Krishna
Updated on 29-Jun-2020 12:20:49

6K+ Views

The "this" keyword in Java is used as a reference to the current object, within an instance method or a constructor. Using this you can refer the members of a class such as constructors, variables, and methods.Returning “this”Yes, you can return this in Java i.e. The following statement is valid.return this;When you return "this" from a method the current object will be returned.ExampleIn the following Java example, the class Student has two private variables name and age. From a method setValues() we are reading values from user and assigning them to these (instance) variables and returning the current object.public class Student ... Read More

MySQL User Creation Script

George John
Updated on 29-Jun-2020 12:19:59

1K+ Views

First, create a user and password using CREATE command. The syntax is as follows.CREATE USER 'yourUserName'@'localhost' IDENTIFIED BY 'yourPassword';The syntax to give all privileges of the specific database to the user is as follows.GRANT ALL PRIVILEGES ON yourDatabaseName . * TO 'yourUserName'@'localhost';Now you can implement the above syntaxes to create a user and grant all privileges.Step 1 − Create a userThe query is as follows.mysql> create user 'Adam Smith'@'localhost' IDENTIFIED BY 'Adam123456'; Query OK, 0 rows affected (0.29 sec)Step 2 − Grant all privileges to the user.The query is as follows.mysql> GRANT ALL PRIVILEGES ON test . * TO 'Adam ... Read More

List MySQL Tables and Sizes Ordered by Size

Ankith Reddy
Updated on 29-Jun-2020 12:17:27

2K+ Views

You can do this with the help of information_schema.tables. The syntax is as follows -SELECT TABLE_NAME, table_rows, data_length, index_length, round(((data_length + index_length) / 1024 / 1024), 2) "MB Size" FROM information_schema.TABLES WHERE table_schema = "yourDatabaseName" ORDER BY (data_length + index_length) ASC;To understand the above syntax, let us implement it for any database. Here, I am using database TEST. Let us see the query for our database TEST.mysql> SELECT TABLE_NAME, table_rows, data_length, index_length, -> round(((data_length + index_length) / 1024 / 1024), 2) "MB Size" -> FROM information_schema.TABLES WHERE table_schema = "test" -> ORDER BY (data_length + index_length) ASC;The following is the ... Read More

Get Volley ArrayList with Custom Object in Android

Chandu yadav
Updated on 29-Jun-2020 12:06:11

739 Views

This example demonstrate about How to get volley array list with custom object 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 text view to show custom array list object elements.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.widget.TextView; import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.StringRequest; import com.android.volley.toolbox.Volley; ... Read More

Advertisements