Out of Memory Exception in Java

Maruthi Krishna
Updated on 06-Sep-2019 11:31:01

1K+ Views

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

Why We Need Generics in Java

Maruthi Krishna
Updated on 06-Sep-2019 11:29:28

4K+ Views

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

Check File Readability, Writability, and Executability in Java

Maruthi Krishna
Updated on 06-Sep-2019 11:19:46

3K+ Views

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

Throw Exception Without Using Throws in Java

Maruthi Krishna
Updated on 06-Sep-2019 11:02:55

4K+ Views

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 In Depth in React JS

Shyam Hande
Updated on 05-Sep-2019 08:00:25

354 Views

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 Components in React JS

Shyam Hande
Updated on 05-Sep-2019 07:53:53

254 Views

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

Fragment in React JS

Shyam Hande
Updated on 05-Sep-2019 07:48:28

529 Views

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

Forwarding Ref in React JS

Shyam Hande
Updated on 05-Sep-2019 07:45:54

461 Views

Passing a ref to the child component is called as forwarding ref. React provides a createRef function to create a ref for element.forwardRef is a function to pass the ref to child component.Example// ExampleRef.js const ExampleTextInput = React.forwardRef((props, ref) => (     )); const exampleInputRef = React.createRef(); class NewTextInput extends React.Component {    handleFormSubmit = e => {       e.preventDefault();       console.log(“Entered value: ”+exampleInputRef.current.value);    };    render() {       return (                       this.handleFormSubmit(e)}>                 ... Read More

How JSON Wire Protocol Works

Adiya Dua
Updated on 04-Sep-2019 15:05:56

870 Views

A24 JSON Wire protocol is the protocol in which is used when the web driver communicates with the browser. The working of the JSON is as below −In a server-client architecture, it is necessary that the client and server should be in sync and are able to receive and send the request and response.As the name suggests JSON(JavaScript Object Notation) is used to represent objects with a complex data structures. JSON wire protocol acts as a mediator between client libraries and Web Drivers. It sends transfers data between the client and the server on the web.The server doesn’t understand the ... Read More

Making HTTP Request in React JS

Shyam Hande
Updated on 04-Sep-2019 15:01:10

3K+ Views

In a typical web application, client makes a http request through browser and server sends html page in the response with data.But in a single page application (SPA), we have only one page and whenever client makes http request to server it generally responses with a json/xml formatted data.For making http request we have some of the below options −XmlHttpRequestAxiosWindows fetchAxios is easy to work with react and handing requests.Lets install it firstnpm install –save axiosImport it in the jsx file before usingimport Axios from ‘axios’;From the component lifecycle post, we observed that componentDidMount is the best place to make ... Read More

Advertisements