Found 34490 Articles for Programming

Private and final methods in Java Programming

Vikyath Ram
Updated on 27-Jun-2020 08:12:16

7K+ Views

In Java private methods are the methods having private access modifier and are restricted to be access in the defining class only and are not visible in their child class due to which are not eligible for overridden. However, we can define a method with the same name in the child class and could access in parent class.Like private methods final methods in Java are the methods having final non-access modifier instead of private and are again restricted to be accessed in the defining class only and are not visible in their child class due to which are not eligible ... Read More

filter_has_var() function in PHP

Ankith Reddy
Updated on 27-Dec-2019 10:22:28

299 Views

The filter_has_var() function is used to check that variable of specified type exists or not.Syntaxfilter_has_var(type, var)Parameterstype − There are five types of inputs to check i.e. INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV.var − The name of variable.ReturnThe filter_has_var() function returns true on success and false on failure.ExampleThe following is an example that is a quick check for the input variable "email”. The value INPUT_GET is used for this. Live Demo

Private Constructors and Singleton Classes in Java Programming

Rishi Raj
Updated on 30-Jul-2019 22:30:23

1K+ Views

As we know the primary role of the constructor is to instantiate a class object now if we made the constructor as private then we restrict its calling to be only in defining a class and not in some other class. Now the singleton class in Java is defined as the class which restricts the instantiation of a class and ensure that only one instance of the class exists in the JVM. After first time if instantiate the singleton class the new variable also points to the first instance created. In order to create a singleton class we could use ... Read More

PriorityQueue Class in Java Programming

Rishi Raj
Updated on 30-Jul-2019 22:30:23

83 Views

The java.util.PriorityQueue class is an unbounded priority queue based on a priority heap.Following are the important points about PriorityQueue − The elements of the priority queue are ordered according to their natural ordering, or by a Comparator provided at queue construction time, depending on which constructor is used. A priority queue does not permit null elements. A priority queue relying on natural ordering also does not permit insertion of non-comparable objects. Class declaration Following is the declaration for java.util.PriorityQueue class − public class PriorityQueue extends AbstractQueue implements Serializable Parameters Following ... Read More

Print a 2 D Array or Matrix in Java Programming

Arushi
Updated on 30-Jul-2019 22:30:23

1K+ Views

In this post we will try to print an array or matrix of numbers at console in same manner as we generally write on paper. For this the logic is to access each element of array one by one and make them print separated by a space and when row get to emd in matrix then we will also change the row Example Live Demo public class Print2DArray { public static void main(String[] args) { final int[][] matrix = { ... Read More

Math class methods in Java Programming

Arushi
Updated on 30-Jul-2019 22:30:23

359 Views

The java.lang.Math class contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. Class Declaration Following is the declaration for java.lang.Math class − public final class Math extends Object Field Following are the fields for java.lang.Math class − static double E − This is the double value that is closer than any other to e, the base of the natural logarithms. static double PI − This is the double value that is closer than any other to pi, the ratio of the circumference of a circle ... Read More

How to prevent Cloning to break a Singleton Class Pattern in Java?

Rishi Raj
Updated on 30-Jul-2019 22:30:23

243 Views

A Singleton pattern states that a class can have a single instance and multiple instances are not permitted to be created. For this purpose, we make the constructor of the class a private and return a instance via a static method. But using cloning, we can still create multiple instance of a class. See the example below − Example - Breaking Singleton Live Demo public class Tester{ public static void main(String[] args) throws CloneNotSupportedException { A a = A.getInstance(); ... Read More

Functional Interfaces in Java Programming

Fendadis John
Updated on 30-Jul-2019 22:30:23

315 Views

Functional interfaces have a single functionality to exhibit. For example, a Comparable interface with a single method 'compareTo' is used for comparison purpose. Java 8 has defined a lot of functional interfaces to be used extensively in lambda expressions. Following is the list of functional interfaces defined in java.util.Function package. Given below is the list of interfaces in Java8. Sr.No. Interface & Description 1 BiConsumer Represents an operation that accepts two input arguments, and returns no result. 2 BiFunction Represents a function that accepts two arguments and produces a result. ... Read More

How to create CircularImageView in android?

George John
Updated on 30-Jul-2019 22:30:23

879 Views

This example demonstrate about how to Create CircularImageView 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 −To make circler view, we should add CircularImageView library in gradle file as shown below.apply plugin: 'com.android.application' android {    compileSdkVersion 28    defaultConfig {       applicationId "com.example.andy.myapplication"       minSdkVersion 15       targetSdkVersion 28       versionCode 1       versionName "1.0"       testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"    }    buildTypes {       release ... Read More

How to check internet connection in android?

Chandu yadav
Updated on 30-Jul-2019 22:30:23

3K+ Views

This example demonstrate about how to check the state of internet connection through broadcast Receiver.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 − To find the internet status we have to add network state permission to AndroidManifest.xml file as shown below.                                                                     Step ... Read More

Advertisements