Tuesday, March 29, 2022

How to count a number of words in given String in Java? [Solved]

Can you write a method in Java that accepts a String argument and returns a number of words in it? A word is a sequence of one or more non-space characters i.e. any character other than '' (empty String). This should be your method signature:

public int count(String word);

This method should return 1 if the input is "Java" and return 3 if the input is "Java, C++, Python". Similarly a call to wordCount("    ") should return 0. 

How to use String.matches() with Regular Expression in Java? Example Tutorial

String Matching Example in Java
The string matches method in Java can be used to test String against regular expressions in Java. The string matches() method is one of the most convenient ways of checking if a String matches a regular expression in Java or not. Quite often we need to write code that needs to check if String is numeric, Does String contains alphabets e.g. A to Z or a to Z, How to check if String contains a particular digit 6 times, etc. There are so many cases in Java programming where we need a regular expression. 

Monday, March 14, 2022

Understanding "Lifting State Up" in React - Example Tutorial


If you have ever worked with React, then you know the importance of state management. The state is managed within the component and decides the component’s behavior. But as the application grows, the state is required to be shared among the different components. For such global state sharing, third-party libraries such as Redux are used.

Apart from managing the state inside a component or using redux for the global state, there is one more way to work with the state. This is called “lifting state up”. In this article, we will discuss what is “lifting state up” in React with the help of an example. 

Sunday, March 6, 2022

How to use React forms in JSX? Example Tutorial


Forms are an essential part of web application development. You can find forms on almost every website you visit. Forms are important because they are used to handle input from the users. Websites will not function properly if there is no way for input handling. 

Input can be taken in various forms. The most common type of input is text input. Other forms of input are checkboxes, radio buttons, and ranges. 

In React, forms are created like they are created in HTML. The most important part of forms in React is handling them. In this article, we will discuss how to create forms in React and handle them.