The array is a container that can hold a fixed number of items and these items should be of the same type. Most of the data structures make use of arrays to implement their algorithms. The following are the important terms to understand the concept of Array.Element − Each item stored in an array is called an element.Index − Each location of an element in an array has a numerical index, which is used to identify the element.The size of the array will be determined at the time of creation.Example Live Demopublic class ArrayExample { public static void main(String args[]){ ... Read More
When superclass and the subclass contain the same instance methods including parameters, when called, the superclass method is overridden by the method of the subclass.Example Live Democlass Super{ public void sample(){ System.out.println("Method of the Super class"); } } public class MethodOverriding extends Super { public void sample(){ System.out.println("Method of the Sub class"); } public static void main(String args[]){ MethodOverriding obj = new MethodOverriding(); obj.sample(); } }OutputMethod of the Sub classMethod shadowingWhen superclass and subclass contain the same method including parameters and if they ... Read More
Checked exceptionsA checked exception is an exception that occurs at the compile time, these are also called as compile-time exceptions. These exceptions cannot simply be ignored at the time of compilation; the programmer should take care of (handle) these exceptions.When a checked/compile time exception occurs you can resume the program by handling it using try-catch blocks. Using these you can display your own message or display the exception message after the execution of the complete program.Example Live Demoimport java.io.File; import java.io.FileInputStream; public class Test { public static void main(String args[]){ System.out.println("Hello"); try{ ... Read More
Whenever you create an object in Java it is stored in the heap area of the JVM. If the JVM is not able to allocate memory for the newly created objects an exception named OutOfMemoryError is thrown.This usually occurs when we are not closing objects for long time or, trying to act huge amount of data at once.There are 3 types of errors in OutOfMemoryError −Java heap space.GC Overhead limit exceeded.Permgen space.Example 1 Live Demopublic class SpaceErrorExample { public static void main(String args[]) throws Exception { Float[] array = new Float[10000 * 100000]; } }OutputRuntime exceptionException ... Read More
Reference typesAs we know a class is a blue print in which we define the required behaviors and properties and, an interface is similar to class but it is a Specification (containing abstract methods).These are also considered as datatypes in Java, unlike other primitive datatypes a literal of these kind of types points/refers to the location of the object. They are also known as reference types.GenericsGenerics is a concept in Java where you can enable a class, interface and, method, accept all (reference) types as parameters. In other words it is the concept which enables the users to choose the ... Read More
In general, whenever you create a file you can restrict/permit certain users from reading/writing/executing a file.In Java files (their abstract paths) are represented by the File class of the java.io package. This class provides various methods to perform various operations on files such as read, write, delete, rename, etc.In addition, this class also provides the following methods −setExecutble() − This method issued to set the execute permissions to the file represented by the current (File) object.setWritable() − This method is used to set the write permissions to the file represented by the current (File) object.setReadable() − This method is used ... Read More
When an exception occurs in Java, the program terminates abnormally and the code past the line that caused the exception doesn’t get executed.To resolve this you need to either wrap the code that causes the exception within try catch ot, throw the exception using the throws clause. If you throw the exception using throws clause it will be p[postponed to the calling line i.e.Example Live Demoimport java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class ExceptionExample{ public static String readFile(String path)throws FileNotFoundException { String data = null; Scanner sc = new Scanner(new File("E://test//sample.txt")); ... Read More
JSX simply creates a React element using createElement method in the end.Example Submit Will be converted to −React.createElement( FormButton, {color: 'green', buttonSize: 10}, 'Submit’ )Self-closing tags are also possible to add.Capitalizing the custom React ElementThe custom react element must be named with first character in capital so that React will be able distinguish between the html element and the react element.As Jsx gets converted to React.createElement, the React library must be in scope. For that we have to import the React if jsx needs to use.Accessing the inner properties using dot operatorThe inner properties of an element ... Read More
Higher order component in short called as hoc. It’s a pattern which receives a component and returns a new component with add-on features to it.//hoc is the name of a custom JavaScript functionconst AddOnComponent= hoc(SimpleComponent);We use component with state and/or props to build an UI. Similar way a hoc builds a new component from the provided component.Use of hoc is making a cross cutting concerns in React. The components will take care of individual responsibility of single tasks while hoc functions will take care of cross cutting concerns.Connect function from redux is an example of hoc.A practical example of hocDisplay ... Read More
Most of the times we need to return multiple elements from a component. React Fragment helps in returning multiple elements. The other alternative is to use a html element like div to wrap them. But using extra html node can cause some semantic issues.Example of React.Fragmentrender() { return ( ); } The short syntax is : render() { return ( ... Read More