Generated by All in One SEO Pro v4.9.1, this is an llms.txt file, used by LLMs to index the site. # BeginnersBook ## Sitemaps - [XML Sitemap](https://beginnersbook.com/sitemap.xml): Contains all public & indexable URLs for this website. ## Posts - [How to restrict inheritance in java using Final Classes and Methods](https://beginnersbook.com/2024/12/how-to-restrict-inheritance-in-java-using-final-classes-and-methods/) - In Java, final classes and methods are used to restrict inheritance and prevent modifications in subclasses. This is useful when you want to ensure that class or its behaviour does not change. Prerequisite: Inheritance in java Common errors in Inheritance 1. Final Classes A class declared as final cannot be extended (cannot inherit it). As - [Common Errors in Inheritance in Java: Examples and solutions](https://beginnersbook.com/2024/12/common-errors-in-inheritance-in-java-examples-and-solutions/) - In previous tutorials, we discussed inheritance in java and types of inheritance in Java. In this guide, we will discuss some of the common errors in inheritance in java along with examples and solutions. 1. Using private Members in Subclasses Error: A subclass cannot access private members of its parent class directly. In the following - [How To Rotate A List In Java - Two Ways](https://beginnersbook.com/2024/06/rotate-a-list-in-java/) - In this guide, you will learn how to rotate a list in Java. Rotation means shifting of elements, for example rotating a list to right by 2 position means 1st element becomes 3rd element, 2nd element becomes 4th element and so on. We will see two examples to rotate a list: 1. Using Collections.rotate() You - [Ultimate Collection of C Programs: Source Code with Outputs](https://beginnersbook.com/2015/02/simple-c-programs/) - Explore a curated collection of C programming examples covering various topics, complete with source code and output. Perfect for beginners & advanced learners. - [Java Hexadecimal to Decimal Conversion with examples](https://beginnersbook.com/2019/04/java-hexadecimal-to-decimal-conversion/) - In this guide, we will learn how to convert a hexadecimal to a decimal number with the help of examples. Java Hexadecimal to Decimal Conversion example We can simply use Integer.parseInt() method and pass the base as 16 to convert the given hexadecimal number to equivalent decimal number. Here we have given a hexadecimal number - [First Perl Program](https://beginnersbook.com/2017/02/first-perl-program/) - In this tutorial, we will learn how to write first perl program and run it on various Operating Systems. First Perl Program: Hello World This is a simple perl program that prints Hello World!! on the screen. #!/usr/bin/perl #this is a comment print "Hello World!!"; Here first instruction #!/usr/bin/perl tells Operating systems to run this - [Java String trim() and hashCode() Methods with examples](https://beginnersbook.com/2013/12/java-string-trim-and-hashcode-methods/) - In this tutorial we will discuss Java String trim() and hashCode() methods with the help of examples. Java String trim() method signature It returns a String after removing leading and trailing white spaces from the input String. For e.g. " Hello".trim() would return the String "Hello". public String trim() Java String trim() method - [C++ Program to Find largest element in an array](https://beginnersbook.com/2017/09/cpp-program-to-find-largest-element-in-an-array/) - This program finds the largest element in an array. User is asked to enter the value of n(number of elements in array) then program asks the user to enter the elements of array. The program then finds the largest element and displays it. To understand this program you should have the basic knowledge of loops, - [Insertion Sort Program in C](https://beginnersbook.com/2015/02/insertion-sort-program-in-c/) - Insertion sort algorithm picks elements one by one and places it to the right position where it belongs in the sorted list of elements. In the following C program we have implemented the same logic. Before going through the program, lets see the steps of insertion sort with the help of an example. Input elements: - [Strings in C++](https://beginnersbook.com/2017/08/strings-in-c/) - Strings are words that are made up of characters, hence they are known as sequence of characters. In C++ we have two ways to create and use strings: 1) By creating char arrays and treat them as string 2) By creating string object Lets discuss these two ways of creating string first and then we - [Day calculation from date](https://beginnersbook.com/2013/04/calculating-day-given-date/) - Note: This is not a java specific post. The below mentioned methods are not specific to any technology and can be implemented in any programming language. INTRODUCTION There are two formulas for calculating the day of the week for a given date. Zeller’s Rule Key-Value Method Note: Both the methods work only for the Gregorian - [Java Year class explained with examples](https://beginnersbook.com/2022/06/java-year-class-explained-with-examples/) - An instance of Year class represents the year ISO-8601 calendar system, such as 2022. Any field that can be derived from a year, can be obtained using this class. This class doesn't store day, month, time or timezone information, for example value "2022" can be stored in Year, however the value "2nd October 2022" cannot - [Java LocalDate](https://beginnersbook.com/2022/06/java-localdate-2/) - It represents the date in year-month-day format such as 2022-12-05. This class represents the date without a timezone. java.time.LocalDate class: public final class LocalDate extends Object implements Temporal, TemporalAdjuster, ChronoLocalDate, Serializable Java LocalDate class - Method Summary Java LocalDate Examples Example 1: Checking leap year using isLeapYear() method In the following example, we are using - [Java YearMonth class explained with examples](https://beginnersbook.com/2022/06/java-yearmonth-class-explained-with-examples/) - YearMonth class represents the date in combination of year and month such as 2022-06. This class does not store day, time or time-zone information. For example, the value "June 2022" can be stored in a YearMonth but the value "2nd June 2022" cannot be stored in a YearMonth. Java YearMonth class: public final class YearMonth - [OOPs in Java: Encapsulation, Inheritance, Polymorphism, Abstraction](https://beginnersbook.com/2013/03/oops-in-java-encapsulation-inheritance-polymorphism-abstraction/) - In the last article we discussed OOPs Concepts. If you have not yet checked it out, I would highly recommend you to read it so that you have a basic overview of all the Object Oriented Programming Concepts. In this guide, we will discuss four important features of OOPs with the help of real life - [How to loop ArrayList in Java](https://beginnersbook.com/2013/12/how-to-loop-arraylist-in-java/) - In this guide, you will learn how you can loop through an ArrayList in Java. In the ArrayList tutorial, we learned that it belongs to java.util package and unlike arrays, it can grow in size dynamically. There are several different approaches to iterate an ArrayList, lets discuss them with examples: 1. Using a for Loop One of the - [Final method parameters in java](https://beginnersbook.com/2014/07/final-method-parameters-in-java/) - In the last tutorial we discussed about final keyword. In this post we are gonna discuss about final method parameters. You must have seen the use of final keyword in method arguments. Lets take an example to understand it: class FinalDemo { public void myMethod(int num, final String str){ // This is allowed as num - [Java 9 - Try With Resources Enhancements](https://beginnersbook.com/2018/05/java-9-try-with-resources-enhancements/) - Try with resource statement was first introduced in Java 7. This statement has received a major enhancement in Java 9. In this guide, we will discuss the improvements of try-with-resource statement in Java 9. What is Try-With-Resources? This statement was first introduced in Java 7 to avoid the redundant code that we had to write - [Java Variables: Declaration, Scope, and Naming Conventions](https://beginnersbook.com/2017/08/variables-in-java/) - This article covers the basics of Java variables, including variable declaration, scope, naming conventions and types of variable. It explains the types of variable in Java with the help of examples. What is a variable? In Java, a variable is a name of the memory location that holds a value of a particular data type. - [Java Program to Check two Strings are anagram or not](https://beginnersbook.com/2022/07/java-program-to-check-two-strings-are-anagram-or-not/) - Anagram of a string is another string with the same characters but order of the characters can be different. For example, Two strings "Listen" and "Silent" are anagram strings as both contain same characters, just the order of the characters is different. Similarly Strings "Race" and "Care" are also anagrams. In this article, you will - [Java 8 - Arrays Parallel Sort with example](https://beginnersbook.com/2017/10/java-8-arrays-parallel-sort-with-example/) - Java 8 introduced a new method parallelSort() in the Arrays class of java.util package. This method is introduced to support the parallel sorting of array elements. Algorithm of parallel sorting: 1. The given array is divided into the sub arrays and the sub arrays are further divided into the their sub arrays, this happens until - [Java String split() Method with examples](https://beginnersbook.com/2013/12/java-string-split-method-example/) - Java String split method is used for splitting a String into substrings based on the given delimiter or regular expression. For example: Input String: chaitanya@singh Regular Expression: @ Output Substrings: {"chaitanya", "singh"} Java String Split Method We have two variants of split() method in String class. 1. String[] split(String regex): It returns an array of - [Java String to long Conversion](https://beginnersbook.com/2013/12/how-to-convert-string-to-long-in-java/) - In this tutorial, you will learn how to convert String to long in Java. We can use Long wrapper class for this purpose, this class contains couple of methods that we can use for this conversion. There are following three ways to convert a String to a long value. Long.parseLong() Method Long.valueOf() Method Long(String s) - [C Program to print number of days in a month](https://beginnersbook.com/2024/05/c-program-to-print-number-of-days-in-a-month/) - In this C Programs series, We will write a C program to print number of days in a month. If the entered month is 2 then it also checks whether the year is leap year or not. C Program to print number of days in a given month The explanation of the program and output - [Why String Immutable or Final in Java](https://beginnersbook.com/2024/06/why-string-immutable-or-final-in-java/) - The immutable and final nature of String class is intentional. This is by design to offer several features and advantages. In this guide, we will discuss these advantages with examples. Reasons for String Immutability Security: Sensitive Data: Immutability feature of String offers security as data cannot be changed, this is exactly what we want for - [Add Multiple Items to an ArrayList in Java](https://beginnersbook.com/2022/08/add-multiple-items-to-an-arraylist-in-java/) - In this tutorial, you will learn how to add multiple items to an ArrayList in Java. 1. Add multiple items using adAll() method The addAll() can be used to add multiple items to an ArrayList. This method takes another list as an argument and add the elements of the passed list to the ArrayList. Here, - [Add Multiple Items to an ArrayList in Java](https://beginnersbook.com/2022/08/add-multiple-items-to-an-arraylist-in-java/) - In this tutorial, you will learn how to add multiple items to an ArrayList in Java. 1. Add multiple items using adAll() method The addAll() can be used to add multiple items to an ArrayList. This method takes another list as an argument and add the elements of the passed list to the ArrayList. Here, - [StringJoiner add() Method in Java](https://beginnersbook.com/2024/06/stringjoiner-add-method-in-java/) - StringJoiner class is introduced in Java 8. It is a part of the java.util package. The main purpose of a StringJoiner is to create a sequence of characters separated by a specified delimiter. You can optionally specify prefix and suffix as well. In this tutorial, we will discuss the add() method of StringJoiner class. Example 1: - [Java StringBuilder Class With Examples](https://beginnersbook.com/2022/10/java-stringbuilder-class/) - StringBuilder in Java is used to create mutable strings. A mutable string is the one which can be modified instead of creating new string instance. StringBuilder is an alternative to Java String class. In this guide, we will discuss StringBuilder class in detail. We will also cover important methods of Java StringBuilder class with examples. - [Java StringBuilder Class With Examples](https://beginnersbook.com/2022/10/java-stringbuilder-class/) - StringBuilder in Java is used to create mutable strings. A mutable string is the one which can be modified instead of creating new string instance. StringBuilder is an alternative to Java String class. In this guide, we will discuss StringBuilder class in detail. We will also cover important methods of Java StringBuilder class with examples. - [JSON Tutorial: Learn JSON in 10 Minutes](https://beginnersbook.com/2015/04/json-tutorial/) - JSON stands for JavaScript Object Notation. JSON objects are used for transferring data between server and client, XML serves the same purpose. However JSON objects have several advantages over XML and we are going to discuss them in this tutorial along with JSON concepts and its usages. JSON Syntax Rules JSON syntax follows these rules: - [Java – Convert LocalDate to LocalDateTime](https://beginnersbook.com/2017/10/java-convert-localdate-to-localdatetime/) - The LocalDate represents only the date without time and zone id, while the LocalDateTime represents date with time, so in order to convert LocalDate to LocalDateTime we must append the time with the LocalDate. LocalDate to LocalDateTime conversion There are two methods that we can use to convert LocalDate to LocalDateTime. Method atStartOfDay(): This method - [Java ZonedDateTime](https://beginnersbook.com/2017/11/java-zoneddatetime/) - The ZonedDateTime class represents the date with time and timezone information such as 2021-10-23T11:35:45+01:00 Europe/Paris. In the last post, we discussed LocalDateTime class, which represents the date with time but without timezone information so you can assume that a ZonedDateTime = LocalDateTime + Time Zone information. This is an immutable class. In this guide, we - [Multithreading in java with examples](https://beginnersbook.com/2013/03/multithreading-in-java/) - Multithreading is one of the most popular feature of Java programming language as it allows the concurrent execution of two or more parts of a program. Concurrent execution means two or more parts of the program are executing at the same time, this maximizes the CPU utilization and gives you better performance. These parts of - [Inheritance in Java With Examples](https://beginnersbook.com/2013/03/inheritance-in-java/) - Inheritance is one of the useful feature of OOPs. It allows a class to inherit the properties and methods of another class. A class inheriting properties and methods of another class can use those without declaring them. The main purpose of inheritance in java is to provide the reusability of code so that a class - [Static and dynamic binding in java](https://beginnersbook.com/2013/04/java-static-dynamic-binding/) - Static and dynamic binding are basic OOPs concepts. These concepts are associated with the polymorphism. When a method is called in a java program, its body is invoked. This association of method call to the method body is known as binding. For example: This statement System.out.println("Hello"); is calling the method println(). The body of the - [LinkedList in Java with Example](https://beginnersbook.com/2013/12/linkedlist-in-java-with-example/) - Similar to arrays in Java, LinkedList is a linear data structure. However LinkedList elements are not stored in contiguous locations like arrays, they are linked with each other using pointers. Each element of the LinkedList has the reference(address/pointer) to the next element of the LinkedList. LinkedList representation Each element in the LinkedList is called the - [Java String indexOf() Method](https://beginnersbook.com/2013/12/java-string-indexof-method-example/) - Java String indexOf() method is used to find the index of a specified character or a substring in a given String. Here are the different variations of this method in String class: Finding the index of a character: int indexOf(int ch) It returns the index of first occurrence of character ch in the given string. - [Vector in Java](https://beginnersbook.com/2013/12/vector-in-java/) - Vector implements List Interface. Like ArrayList it also maintains insertion order but it is rarely used in non-thread environment as it is synchronized and due to which it gives poor performance in searching, adding, delete and update of its elements. Importing the Vector Class import java.util.Vector; Creating a Vector Method 1: Vector vector = new Vector(); It - [Difference between ArrayList and LinkedList in Java](https://beginnersbook.com/2013/12/difference-between-arraylist-and-linkedlist-in-java/) - In this guide, you will learn difference between ArrayList and LinkedList in Java. ArrayList and LinkedList both implements List interface and their methods and results are almost identical. However there are few differences between them which make one better over another on case to case basis. ArrayList Vs LinkedList Performance difference between ArrayList and LinkedList - [JSP include action Tag](https://beginnersbook.com/2013/11/jsp-include-action-tag/) - Include action tag is used for including another resource to the current JSP page. The included resource can be a static page in HTML, JSP page or Servlet. We can also pass parameters and their values to the resource which we are including. Below I have shared two examples of , one which includes a - [JSP forward action tag](https://beginnersbook.com/2013/11/jsp-forward-action-tag/) - JSP forward action tag is used for forwarding a request to the another resource (It can be a JSP, static page such as html or Servlet). Request can be forwarded with or without parameter. In this tutorial we will see examples of action tag. Syntax: 1) Forwarding along with parameters. - [SQL CREATE DATABASE Statement](https://beginnersbook.com/2014/05/sql-create-database-statement/) - SQL create database statement is used to create a database with the specified name. Before you create tables and insert data into the tables, you need to create a database. SQL Create Database Statement Syntax and Example: CREATE DATABASE databaseName; Here CREATE DATABASE is a keyword which needs to be written as it is, the - [StringJoiner toString() Method in Java](https://beginnersbook.com/2024/06/stringjoiner-tostring-method-in-java/) - In this tutorial, we will discuss toString() method of StringJoiner class. This method is used to get the string representation of StringJoiner object, this includes the delimiter, prefix and suffix. Example 1: Converting StringJoiner to String In this example: We have created a StringJoiner objected joiner with a comma (, ) as the delimiter, a left - [Java int to double Conversion](https://beginnersbook.com/2018/09/java-convert-int-to-double/) - In this tutorial, you will learn how to convert int to double in Java. Since double has longer range than int data type, java automatically converts int value to double when the int value is assigned to double. In this guide, we will discuss three ways to do this conversion. Implicit Casting: As discussed, Java - [Calculate Average of List in Java](https://beginnersbook.com/2024/06/calculate-average-of-list-in-java/) - In this tutorial, you will learn how to calculate average of a List in Java. This can be done on ArrayList of numbers such as list of Integer, Double, Float, Long type etc. There are several ways to do this, in this guide, we will see following two approaches: Using For loop Using Java Streams - [Convert JSON Array to ArrayList in Java](https://beginnersbook.com/2024/06/convert-json-array-to-arraylist-in-java/) - In this guide, you will learn how to convert JSON array to ArrayList in Java. To parse the given JSON data, you can use org.json package of Java. Let's start step by step guide: 1. Add the JSON Library: In order to parse the JSON data, make sure that you have org.json library in your project. In - [Java ArrayList isEmpty() Method example](https://beginnersbook.com/2013/12/java-arraylist-isempty-method-example/) - The isEmpty() method of java.util.ArrayList class is used to check whether the list is empty or not. This method returns a boolean value. It returns true if the list is empty, and false if the list contains any elements. Syntax public boolean isEmpty() Example import java.util.ArrayList; public class ArrayListExample { public static void main(String[] args) { // Create an - [Java ArrayList trimToSize() Method](https://beginnersbook.com/2013/12/java-arraylist-trimtosize-method-example/) - The trimToSize() method of ArrayList class is used for memory optimization. It trims the capacity of ArrayList to the current list size. This method is useful when you want to free the unused storage space after you are done adding elements to an ArrayList, especially if you have allocated a large capacity initially but are - [Java ArrayList set() Method](https://beginnersbook.com/2013/12/java-arraylist-set-method-example/) - Java ArrayList set() method is used to replace an existing element present in the ArrayList at the specified position with the new given element. The syntax of the set() method is: public E set(int index, E element) In this syntax: index: This specifies the position of the element which needs to be replaced. element: The new element - [How to Initialize an ArrayList in Java](https://beginnersbook.com/2013/12/how-to-initialize-an-arraylist/) - In this tutorial, you will learn how to initialize an ArrayList in Java. There are several different ways to do this. Let's discuss them with examples. 1. Basic (Normal) Initialization One of the ways to initialize an ArrayList is to create it first and then add elements later using add() method. import java.util.ArrayList;public class ArrayListExample - [Java Array explained with examples](https://beginnersbook.com/2013/05/java-arrays/) - Array is a collection of elements of same type. For example an int array contains integer elements and a String array contains String elements. The elements of Array are stored in contiguous locations in the memory. Arrays in Java are based on zero-based index system, which means the first element is at index 0. This - [Java double to int Conversion](https://beginnersbook.com/2018/09/java-convert-double-to-int/) - In this tutorial, you will learn how to convert double to int in Java. A double number contains decimal digits so when we convert it into an int, the decimal digits are truncated. We can however use certain approaches where we can convert it into a nearest int rather than truncating decimal digits. Let's see - [Java Timestamp to Date Conversion](https://beginnersbook.com/2022/11/java-timestamp-to-date-conversion/) - In this guide, you will learn how to convert Timestamp to Date. Timestamp has higher precision than date and is used when we want to include the fractions seconds in Date & Time. There are two ways you can do this: Using java.util.Date Using java.time Timestamp to Date Conversion in Java 1. Using java.util.Date In - [How to Find length of an Integer in Java](https://beginnersbook.com/2024/06/how-to-find-length-of-an-integer-in-java/) - In this tutorial, you will learn how to find length of an Integer in Java. There are several ways you can achieve this. One of the easiest way you can do this is by converting the Integer to a string and then get the length of that string. This approach handles both positive and negative numbers correctly. - [How to Find Size of an int in Java](https://beginnersbook.com/2024/06/how-to-find-size-of-an-int-in-java/) - The int data type is a primitive data type in Java. The size of int is fixed as defined by Java language specification. The size of an int is 32 bits and it is consistent across all platforms that support Java language. Determining the Size of an int We can confirm the size of an int - [Java int vs Integer](https://beginnersbook.com/2024/06/java-int-vs-integer/) - In this guide, you will learn the differences between int and Integer. Both of these are the data types that represents integer values. However they serve different purposes and usages. int Primitive Data Type: int is a primitive data type in Java. Memory Efficiency: It takes less space in memory compared to Integer so it is more - [Java String to int Conversion](https://beginnersbook.com/2013/12/how-to-convert-string-to-int-in-java/) - In this tutorial, you will learn how to convert a String to int in Java. If a String is made up of digits like 1,2,3 etc, any arithmetic operation cannot be performed on it until it gets converted into an integer value. In this tutorial we will see the following two ways to convert String - [Java String contains() method](https://beginnersbook.com/2017/10/java-string-contains-method/) - Java String contains() method checks whether a particular sequence of characters is part of a given string or not. This method returns true if a specified sequence of characters is present in a given string, otherwise it returns false. For example: String str = "Game of Thrones"; //This will print "true" because "Game" is present - [Immutable String in Java](https://beginnersbook.com/2024/06/immutable-string-in-java/) - A String in Java is immutable, which means once you create a String object, its value cannot be changed. Any changes (such as concatenation) made to the string will create a new String object. This immutable nature of String in Java provides several advantages such as security, thread safety, and performance. Features of Immutable Strings - [Immutable String in Java](https://beginnersbook.com/2024/06/immutable-string-in-java/) - A String in Java is immutable, which means once you create a String object, its value cannot be changed. Any changes (such as concatenation) made to the string will create a new String object. This immutable nature of String in Java provides several advantages such as security, thread safety, and performance. Features of Immutable Strings - [Toggle String in Java](https://beginnersbook.com/2024/06/toggle-string-in-java/) - In this guide, we will learn how to toggle string in Java. Toggle means reversing the case of each character of String (i.e., converting uppercase letters to lowercase and vice versa). Java Program to Toggle a String To toggle a given String, you can iterate through each character of String and change its case using - [Toggle String in Java](https://beginnersbook.com/2024/06/toggle-string-in-java/) - In this guide, we will learn how to toggle string in Java. Toggle means reversing the case of each character of String (i.e., converting uppercase letters to lowercase and vice versa). Java Program to Toggle a String To toggle a given String, you can iterate through each character of String and change its case using - [Difference between String and StringBuffer](https://beginnersbook.com/2014/08/string-vs-stringbuffer/) - In this article, we will discuss the difference between String and StringBuffer. Both of these classes used to handle sequence of characters. However they are different in certain areas such as mutability, performance, and thread-safety. Let's discuss these differences with examples. String Immutability: String objects are immutable. This means that once a String object is created, its value cannot - [How to take String Input in Java](https://beginnersbook.com/2024/06/how-to-take-string-input-in-java/) - In this tutorial, we will learn how to take String input in Java. There are two ways you can take string as an input from user, using Scanner class and using BufferedReader. However most common way is using Scanner class. Let's see programs of each of these approaches: 1. String Input using Scanner Class In - [How to take String Input in Java](https://beginnersbook.com/2024/06/how-to-take-string-input-in-java/) - In this tutorial, we will learn how to take String input in Java. There are two ways you can take string as an input from user, using Scanner class and using BufferedReader. However most common way is using Scanner class. Let's see programs of each of these approaches: 1. String Input using Scanner Class In - [Java Switch with Strings](https://beginnersbook.com/2024/06/java-switch-with-strings/) - Introduced in Java 7, you can use switch statement with Strings. This makes code more readable as sometimes the string value of switch case variable makes more sense. Let's see how can we achieve this: Java Switch with Strings Examples Example 1: Checking day of the week using switch case public class SwitchStringExample { public - [Java Switch with Strings](https://beginnersbook.com/2024/06/java-switch-with-strings/) - Introduced in Java 7, you can use switch statement with Strings. This makes code more readable as sometimes the string value of switch case variable makes more sense. Let's see how can we achieve this: Java Switch with Strings Examples Example 1: Checking day of the week using switch case public class SwitchStringExample { public - [Java String intern() method](https://beginnersbook.com/2017/10/java-string-intern-method/) - Java String intern() method is used to manage memory by reducing the number of String objects created. It ensures that all same strings share the same memory. For example, creating a string "hello" 10 times using intern() method would ensure that there will be only one instance of "Hello" in the memory and all the 10 references - [Java String isEmpty() method](https://beginnersbook.com/2017/10/java-string-isempty-method-with-example/) - Java String isEmpty() method checks whether a String is empty or not. This method returns true if the given string is empty, else it returns false. In other words you can say that this method returns true if the length of the string is 0. Basic Syntax boolean isEmpty = str.isEmpty(); Java String isEmpty() method - [Java String format() method](https://beginnersbook.com/2017/10/java-string-format-method/) - Java String format() method is used for formatting the String. It works similar to printf function of C, you can format strings using format specifiers. There are so many things you can do with this method, for example you can concatenate the strings using this method and, at the same time you can format the output - [String Concatenation in Java](https://beginnersbook.com/2024/06/string-concatenation-in-java/) - String concatenation is process of combining multiple strings. In Java, there are multiple ways to do this. In this tutorial, we will see several different approaches to do String concatenation in Java. 1. Using the + Operator One of the easiest and simplest way to concatenate strings in Java is using the + operator. public class StringConcatenationPlusOperator { public - [String Concatenation in Java](https://beginnersbook.com/2024/06/string-concatenation-in-java/) - String concatenation is process of combining multiple strings. In Java, there are multiple ways to do this. In this tutorial, we will see several different approaches to do String concatenation in Java. 1. Using the + Operator One of the easiest and simplest way to concatenate strings in Java is using the + operator. public class StringConcatenationPlusOperator { public - [Java String join() method](https://beginnersbook.com/2017/10/java-string-join-method/) - The join() method of String class is introduced in Java 8. This method is used to concatenate strings with specified delimiter. It is also used to combine multiple elements of a collection with the specified separator. In this guide, we will see several programs to discuss Java String join() method. Note: Java 8 also introduced - [Java String valueOf() method](https://beginnersbook.com/2017/10/java-string-valueof-method/) - Java String valueOf() method is used to convert different types of values to an equivalent String representation. This method is a static method and there are overloaded versions of this method available to handle char, char[], int, long, float, double, boolean, Object, and so on. Different variants of java string valueOf() method 1. String.valueOf(boolean b) It takes boolean value as an argument and - [Java String Compare](https://beginnersbook.com/2022/06/java-program-to-compare-two-strings/) - In Java, you can compare strings using several different approaches. In this tutorial, we will write various Java programs to compare Strings in java. Using equal to operator (==) Using equals() method of String class compareTo() method of String class Using compareToIgnoreCase() method Using contentEquals() method 1. Comparing two strings by using == operator In - [Java Array Declaration and Initialization](https://beginnersbook.com/2024/06/java-array-declaration-and-initialization/) - In Java, an array is used to hold fixed number of similar type elements. The length of an array is fixed, which cannot be changed after it is created (to have variable length refer ArrayList). In this guide, we will see various examples of Array declaration and initialization in Java. Declaring an Array You can - [Java Array Declaration and Initialization](https://beginnersbook.com/2024/06/java-array-declaration-and-initialization/) - In Java, an array is used to hold fixed number of similar type elements. The length of an array is fixed, which cannot be changed after it is created (to have variable length refer ArrayList). In this guide, we will see various examples of Array declaration and initialization in Java. Declaring an Array You can - [How to print 2D Array in Java](https://beginnersbook.com/2024/06/how-to-print-2d-array-in-java/) - In Java, there are several ways to print a 2D array. In this guide, we will see various programs to print 2D array using different approaches: Note: In the previous tutorial, I have covered how to print an array(1D array). Printing 2D Arrays 1. Using Arrays.deepToString() You can use Arrays.deepToString() method to print a 2D array. You can simply - [How to print 2D Array in Java](https://beginnersbook.com/2024/06/how-to-print-2d-array-in-java/) - In Java, there are several ways to print a 2D array. In this guide, we will see various programs to print 2D array using different approaches: Note: In the previous tutorial, I have covered how to print an array(1D array). Printing 2D Arrays 1. Using Arrays.deepToString() You can use Arrays.deepToString() method to print a 2D array. You can simply - [How to print Array in Java](https://beginnersbook.com/2024/06/how-to-print-array-in-java/) - In Java, there are several ways to print an array. In this guide, we will see various programs to print array using different approaches: Printing 1D Arrays 1. Using Arrays.toString() You can use Arrays.toString() method to print an array. You can simply pass the array reference as an argument to this method to display all the - [How to print Array in Java](https://beginnersbook.com/2024/06/how-to-print-array-in-java/) - In Java, there are several ways to print an array. In this guide, we will see various programs to print array using different approaches: Printing 1D Arrays 1. Using Arrays.toString() You can use Arrays.toString() method to print an array. You can simply pass the array reference as an argument to this method to display all the - [Sorting 2D Array in Java](https://beginnersbook.com/2024/06/sorting-2d-array-in-java/) - In this tutorial, we will learn how to sort a 2D array in Java. As we know, a 2D array consists of rows and columns, thus we can sort the 2D array column-wise or row-wise, we will see both the programs. 1. Sorting 2D Array Column-wise In the following program, we are sorting the given - [Sorting 2D Array in Java](https://beginnersbook.com/2024/06/sorting-2d-array-in-java/) - In this tutorial, we will learn how to sort a 2D array in Java. As we know, a 2D array consists of rows and columns, thus we can sort the 2D array column-wise or row-wise, we will see both the programs. 1. Sorting 2D Array Column-wise In the following program, we are sorting the given - [Java Arrays Methods](https://beginnersbook.com/2024/06/java-arrays-methods/) - In Java, the Arrays class belong to java.util.Arrays. This class provides several useful methods that we can use to work with arrays more efficiently. In this guide, we will discuss some of the commonly used methods of Java Arrays class with examples. Commonly Used Methods in java.util.Arrays 1. Sorting Arrays Arrays.sort(): This methods sorts the given array - [Java Arrays Methods](https://beginnersbook.com/2024/06/java-arrays-methods/) - In Java, the Arrays class belong to java.util.Arrays. This class provides several useful methods that we can use to work with arrays more efficiently. In this guide, we will discuss some of the commonly used methods of Java Arrays class with examples. Commonly Used Methods in java.util.Arrays 1. Sorting Arrays Arrays.sort(): This methods sorts the given array - [Difference between local, instance and static variables in Java](https://beginnersbook.com/2024/06/difference-between-local-instance-and-static-variables-in-java/) - In Java, we have three types of variables: local, instance and static. We have briefly covered them in Java Variables Tutorial. In this guide, we will discuss the difference between local, instance and static variables in Java with examples. Local Variables Declaration: Local variables are declared inside a method, constructor, or block. Scope: Their scope - [Difference between local, instance and static variables in Java](https://beginnersbook.com/2024/06/difference-between-local-instance-and-static-variables-in-java/) - In Java, we have three types of variables: local, instance and static. We have briefly covered them in Java Variables Tutorial. In this guide, we will discuss the difference between local, instance and static variables in Java with examples. Local Variables Declaration: Local variables are declared inside a method, constructor, or block. Scope: Their scope - [Difference between for loop and for-each loop in Java](https://beginnersbook.com/2024/06/difference-between-for-loop-and-for-each-loop-in-java/) - In Java, both for loop and for-each loop are used for iterating over arrays or collections, however they have different syntax and their usage is also different. In this guide, we will discuss the difference between for loop and for-each loop with the help of examples. I have covered these loops separately here: for loop - [Difference between for loop and for-each loop in Java](https://beginnersbook.com/2024/06/difference-between-for-loop-and-for-each-loop-in-java/) - In Java, both for loop and for-each loop are used for iterating over arrays or collections, however they have different syntax and their usage is also different. In this guide, we will discuss the difference between for loop and for-each loop with the help of examples. I have covered these loops separately here: for loop - [Java For-each Loop (Enhanced for loop)](https://beginnersbook.com/2024/06/java-for-each-loop-enhanced-for-loop/) - In this guide, we will discuss for-each loop in detail with the help of examples. In Java, the for-each loop is used to iterate arrays or collections. It is easier to use than traditional for loop, this is why it is also known as enhanced for loop. Syntax Syntax of for-each loop: for (Type element - [Java For-each Loop (Enhanced for loop)](https://beginnersbook.com/2024/06/java-for-each-loop-enhanced-for-loop/) - In this guide, we will discuss for-each loop in detail with the help of examples. In Java, the for-each loop is used to iterate arrays or collections. It is easier to use than traditional for loop, this is why it is also known as enhanced for loop. Syntax Syntax of for-each loop: for (Type element - [ValueOf() Method in Java](https://beginnersbook.com/2024/06/valueof-method-in-java/) - In this guide, we will discuss one of the most commonly used method in Java. The valueOf() method is available in several wrapper classes and other classes such as String class. This method is mostly used in the conversion of types, for example, converting int to Integer, double to Double etc. ValueOf() method usage In Wrapper - [ValueOf() Method in Java](https://beginnersbook.com/2024/06/valueof-method-in-java/) - In this guide, we will discuss one of the most commonly used method in Java. The valueOf() method is available in several wrapper classes and other classes such as String class. This method is mostly used in the conversion of types, for example, converting int to Integer, double to Double etc. ValueOf() method usage In Wrapper - [Difference between static and non-static members in Java](https://beginnersbook.com/2013/05/static-vs-non-static-methods/) - Java is a Object Oriented Programming(OOP) language, which is often interpreted that we need objects to access methods and variables of a class, however this is not always true. While discussing static keyword in java, we learned that static members are class level and can be accessed directly without creating any instance. In this article - [Difference between Static and Dynamic Dispatch in Java](https://beginnersbook.com/2024/06/difference-between-static-and-dynamic-dispatch-in-java/) - In Java, when we call a method inside a program, the method call is resolved either at the compile time or during runtime, which is known as static and dynamic dispatch respectively. Static Dispatch (Compile-Time Polymorphism) When a method call is resolved at compile time, it is known as static dispatch. It is also referred - [Difference between Static and Dynamic Dispatch in Java](https://beginnersbook.com/2024/06/difference-between-static-and-dynamic-dispatch-in-java/) - In Java, when we call a method inside a program, the method call is resolved either at the compile time or during runtime, which is known as static and dynamic dispatch respectively. Static Dispatch (Compile-Time Polymorphism) When a method call is resolved at compile time, it is known as static dispatch. It is also referred - [Java ArrayList remove(Object obj) Method example](https://beginnersbook.com/2013/12/java-arraylist-removeobject-method-example/) - In this guide, you will learn how to remove a specified element from an ArrayList using remove() method. The method remove(Object obj) removes the first occurrence of the specified object(element) from the list. It belongs to the java.util.ArrayList class. public boolean remove(Object obj) Note: It returns false if the specified element doesn't exist in the - [How to sort ArrayList in Java](https://beginnersbook.com/2013/12/how-to-sort-arraylist-in-java/) - In this tutorial, you will learn how to sort ArrayList in Java. We will write several java programs to accomplish this. We can use Collections.sort() method to sort an ArrayList in ascending and descending order. //Sorting in Ascending orderArrayList numbers = new ArrayList(List.of(4, 1, 3, 2));Collections.sort(numbers); // Sort the ArrayList in ascending orderSystem.out.println(numbers); // Output: [1, - [Java Program to check leap year using ternary operator](https://beginnersbook.com/2024/06/java-program-to-check-leap-year-using-ternary-operator/) - In this tutorial, we will write a java program to check leap year using ternary operator. This program prompts user to enter a year. It then checks if it's a leap year or not using the ternary operator. Let's break down the condition used in the following program: Entered year is divisible by 4 Not - [Java Program to check leap year using ternary operator](https://beginnersbook.com/2024/06/java-program-to-check-leap-year-using-ternary-operator/) - In this tutorial, we will write a java program to check leap year using ternary operator. This program prompts user to enter a year. It then checks if it's a leap year or not using the ternary operator. Let's break down the condition used in the following program: Entered year is divisible by 4 Not - [Java String Max Size](https://beginnersbook.com/2024/06/java-string-max-size/) - In Java, a string is internally stored as an array of characters. This means the max size of a string is equal to the max size of an array, which is Integer.MAX_VALUE (or 2^31 - 1) = 2147483647. However, in practice, the actual maximum size of a String is limited by the available memory on the - [Java String Max Size](https://beginnersbook.com/2024/06/java-string-max-size/) - In Java, a string is internally stored as an array of characters. This means the max size of a string is equal to the max size of an array, which is Integer.MAX_VALUE (or 2^31 - 1) = 2147483647. However, in practice, the actual maximum size of a String is limited by the available memory on the - [How to take array input in Java](https://beginnersbook.com/2024/06/how-to-take-array-input-in-java/) - In this guide, you will learn how to take 1D array and 2D array input in Java. We will be using for loop and Scanner class to accomplish this. Java Program to take 1D array Input import java.util.Scanner;public class ArrayInputExample { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Prompt user - [How to take array input in Java](https://beginnersbook.com/2024/06/how-to-take-array-input-in-java/) - In this guide, you will learn how to take 1D array and 2D array input in Java. We will be using for loop and Scanner class to accomplish this. Java Program to take 1D array Input import java.util.Scanner;public class ArrayInputExample { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Prompt user - [Remove special characters from a String in Java](https://beginnersbook.com/2024/06/remove-special-characters-from-a-string-in-java/) - In this tutorial, we will learn how to remove special characters from a string in java. For example, if the given string is "Hello @ World" then the output will be "Hello World". In order to remove special characters, we can use regex along with the replaceAll() method. Java Program to remove special characters from a - [Remove special characters from a String in Java](https://beginnersbook.com/2024/06/remove-special-characters-from-a-string-in-java/) - In this tutorial, we will learn how to remove special characters from a string in java. For example, if the given string is "Hello @ World" then the output will be "Hello World". In order to remove special characters, we can use regex along with the replaceAll() method. Java Program to remove special characters from a - [How to reverse a String in Java Word by Word](https://beginnersbook.com/2024/06/how-to-reverse-a-string-in-java-word-by-word/) - In this guide, we will learn how to reverse a String in java word by word. For example: If user enters a string "hello world" then the program should output "world hello". This can be done by splitting the string into words, reversing the order of words and then joining them back together. Program to - [How to reverse a String in Java Word by Word](https://beginnersbook.com/2024/06/how-to-reverse-a-string-in-java-word-by-word/) - In this guide, we will learn how to reverse a String in java word by word. For example: If user enters a string "hello world" then the program should output "world hello". This can be done by splitting the string into words, reversing the order of words and then joining them back together. Program to - [System.getProperty() in java](https://beginnersbook.com/2024/06/system-getproperty-in-java/) - In this guide, we will discuss System.getProperty() method in Java. The getProperty() method of System class is frequently used to retrieve various system properties such as java version, os version, java home directory details etc. Program to get system properties using System.getProperty() Let's write a java program to get system properties using System.getProperty() method and - [System.getProperty() in java](https://beginnersbook.com/2024/06/system-getproperty-in-java/) - In this guide, we will discuss System.getProperty() method in Java. The getProperty() method of System class is frequently used to retrieve various system properties such as java version, os version, java home directory details etc. Program to get system properties using System.getProperty() Let's write a java program to get system properties using System.getProperty() method and - [How to check Java Version using Java Program](https://beginnersbook.com/2024/06/how-to-check-java-version-using-java-program/) - In the previous guide, we learned how to check java version using command line. In this guide, we will write a Java program to check the java version. To do this, we can use the System class, which gives access to the system properties. Program to check Java version public class JavaVersionCheck { public static - [How to check Java Version using Java Program](https://beginnersbook.com/2024/06/how-to-check-java-version-using-java-program/) - In the previous guide, we learned how to check java version using command line. In this guide, we will write a Java program to check the java version. To do this, we can use the System class, which gives access to the system properties. Program to check Java version public class JavaVersionCheck { public static - [How to verify Java Version](https://beginnersbook.com/2024/06/how-to-verify-java-version/) - You can use command line or terminal to verify the java version installed on your system. In this guide, we will see the steps to check java version in Windows, MacOS and Linux operating systems. Verify Java Version in Windows Step 1: Open Command Prompt: to do so just press Win + R, type cmd, - [How to verify Java Version](https://beginnersbook.com/2024/06/how-to-verify-java-version/) - You can use command line or terminal to verify the java version installed on your system. In this guide, we will see the steps to check java version in Windows, MacOS and Linux operating systems. Verify Java Version in Windows Step 1: Open Command Prompt: to do so just press Win + R, type cmd, - [How to round a number to two decimal places in Java](https://beginnersbook.com/2024/05/how-to-round-a-number-to-two-decimal-places-in-java/) - In Java, you can round double and float numbers to two decimal places using several different approaches. Let's see some java programs to see how can we achieve this. 1. Using Math.round We already covered this method in detail at: Java Math.round() method. Since, we are dealing with two decimal places, you can simply multiply - [How to round a number to two decimal places in Java](https://beginnersbook.com/2024/05/how-to-round-a-number-to-two-decimal-places-in-java/) - In Java, you can round double and float numbers to two decimal places using several different approaches. Let's see some java programs to see how can we achieve this. 1. Using Math.round We already covered this method in detail at: Java Math.round() method. Since, we are dealing with two decimal places, you can simply multiply - [Checkpoint in DBMS](https://beginnersbook.com/2022/07/checkpoint-in-dbms/) - In the previous chapter, you learned how to recover a transaction using log based recovery method in DBMS. In this guide, you will learn how to use checkpoint in database and how to recover a failed transaction using checkpoint. What is a checkpoint? Checkpoint is like a bookmark in the transaction that helps us rollback - [Try Catch in Java - Exception handling](https://beginnersbook.com/2013/04/try-catch-in-java/) - Try catch block is used for exception handling in Java. The code (or set of statements) that can throw an exception is placed inside try block and if the exception is raised, it is handled by the corresponding catch block. In this guide, we will see various examples to understand how to use try-catch for - [Packages in Java explained with Examples](https://beginnersbook.com/2013/03/packages-in-java/) - A package as the name suggests is a pack(group) of classes, interfaces and other packages. In java we use packages to organize our classes and interfaces. We have two types of packages in Java: built-in packages and the packages we can create (also known as user defined package). In this guide we will learn what - [Constructors in Java - A Complete Guide](https://beginnersbook.com/2013/03/constructors-in-java/) - Constructor is a block of code that initializes the newly created object. A constructor resembles an instance method in java but it's not a method as it doesn't have a return type. In short constructor and method are different(More on this at the end of this guide). People often refer constructor as special type of - [Garbage Collection in Java](https://beginnersbook.com/2013/04/java-garbage-collection/) - When JVM starts up, it creates a heap area which is known as runtime data area. This is where all the objects (instances of class) are stored. Since this area is limited, it is required to manage this area efficiently by removing the objects that are no longer in use. The process of removing unused - [OOPs concepts - What is Association in java?](https://beginnersbook.com/2013/05/association/) - Association is an important concept of object-oriented programming. In this article, we will discuss what is an Association in Java with the help of examples and programs. Association is a process of establishing relationship between two separate classes through their objects. The relationship can be one to one, One to many, many to one and many - [Encapsulation in Java with example](https://beginnersbook.com/2013/05/encapsulation-in-java/) - Encapsulation is one of the fundamental concept of object-oriented programming (OOP) It is widely used for data hiding, it binds the data (variables) and the methods (functions) in a single unit called class. In this guide, we will learn this concept with the help of examples and programs. Note: If you are looking for a - [Java Math.rint() Method](https://beginnersbook.com/2022/10/java-math-rint-method/) - In this article, we will discuss the rint() method of Math class Java. We will see several programs with explanation to understand this method . Math.rint(double x) method returns the double value that is nearest to the given argument x and equal to a mathematical integer number. This method rounds to the nearest integer, but - [Difference between rint() and round() method in Java](https://beginnersbook.com/2024/05/difference-between-rint-and-round-method-in-java/) - In this guide, we will discuss the difference between rint() and round() method in Java. Both of these methods belong to the Math class of Java. These methods are used for rounding numbers, however the rules they follow are bit different, especially when the number is exactly halfway between two integers. Example: For the number - [Difference between rint() and round() method in Java](https://beginnersbook.com/2024/05/difference-between-rint-and-round-method-in-java/) - In this guide, we will discuss the difference between rint() and round() method in Java. Both of these methods belong to the Math class of Java. These methods are used for rounding numbers, however the rules they follow are bit different, especially when the number is exactly halfway between two integers. Example: For the number - [How to Compile and Run your First Java Program](https://beginnersbook.com/2013/05/first-java-program/) - In this tutorial, you will find step by step guide to write, compile and run your first java program. We will also write a java program to print "Hello World" message on the screen. Let's start with a simple java program. Simple Java Program This is a very basic java program that prints a message - [How to set Path in Java](https://beginnersbook.com/2024/05/how-to-set-path-in-java/) - In this article, we will learn how to set path in java. Setting path in Windows allows you to run Java applications and compile Java code from the command line, without specifying the full path to the Java executable. Here's how you can do it: Step-by-Step Guide: Download and Install Java Development Kit (JDK): The - [How to set Path in Java](https://beginnersbook.com/2024/05/how-to-set-path-in-java/) - In this article, we will learn how to set path in java. Setting path in Windows allows you to run Java applications and compile Java code from the command line, without specifying the full path to the Java executable. Here's how you can do it: Step-by-Step Guide: Download and Install Java Development Kit (JDK): The - [C++ vs Java - Difference between C++ and Java](https://beginnersbook.com/2022/06/cpp-vs-java-difference-between-cpp-and-java/) - In this post, you will learn the difference between C++ and Java. There are many similarities and differences between these programming languages. Before we see the difference between them, lets look have a look the basic details about both of these programming languages. C++ language C++ is the first programming language that introduced the concept - [Comparable Interface in Java with example](https://beginnersbook.com/2017/08/comparable-interface-in-java-with-example/) - Comparable interface is mainly used to sort the arrays (or lists) of custom objects. Lists (and arrays) of objects that implement Comparable interface can be sorted automatically by Collections.sort (and Arrays.sort). Before we see how to sort an objects of custom objects, lets see how we can sort elements of arrays and Wrapper classes that - [Features of Java Programming Language](https://beginnersbook.com/2022/06/features-of-java-programming-language/) - Java is one of widely used and popular programming language. Java is packed with full of features, yet it still maintains the simplicity and flexibility that allows a developer to quickly learn and start working on java projects with ease. The flexibility of writing a java code on one machine and running it on several - [History of Java Programming Language](https://beginnersbook.com/2022/06/history-of-java-programming-language/) - Java is an object oriented programming language developed by Sun Microsystems in early 1990 by developers James Gosling, Mike Sheridan and Patrick Naughton. In 1991 James Gosling and his friends formed a team called Green Team to further work on this project. The original idea was to develop this programming language for digital devices such - [Introduction to Java programming](https://beginnersbook.com/2013/05/java-introduction/) - JAVA was developed by Sun Microsystems Inc in 1991, later acquired by Oracle Corporation. It was developed by James Gosling and Patrick Naughton. It is a simple programming language. Writing, compiling and debugging a program is easy in java. It helps to create modular programs and reusable code. Java terminology Before we start learning Java, lets - [How to convert Vector to array in java](https://beginnersbook.com/2014/07/how-to-convert-vector-to-string-array-in-java/) - In this article, we will learn how to convert a Vector to array in Java. Vector class uses dynamic arrays internally, however in certain cases, where we do not require further resizing, we may need to convert it into an Array for better performance. Java program to convert Vector to array In the following program, - [Java - Convert Vector to ArrayList example](https://beginnersbook.com/2014/07/java-convert-vector-to-arraylist-example/) - In this article, we will write a Java program to convert Vector to ArrayList. In Java, both Vector and ArrayList implement the List interface and use dynamic arrays internally to store elements. However their performance for various operations such as search, insert, delete etc. differ in performance in different scenarios. Note: You may also want - [Java – Convert Vector to List example](https://beginnersbook.com/2014/07/java-convert-vector-to-list-example/) - In this article, we will write a Java program to convert Vector to List, Vector and list both data structures used for storing elements, but their performance for various operations differ in different scenarios. More on this at Vector vs List. You may also want to checkout other conversion articles such as Vector to ArrayList - [How to Insert an item in Doubly LinkedList in Java](https://beginnersbook.com/2024/05/insert-an-item-in-doubly-linkedlist-in-java/) - In this tutorial, we will learn how to insert an item in Doubly LinkedList in java at various positions. We will write a Java Program to add an element at the end, beginning or at the specified position in Doubly Linked List. Java Program to add item at various positions in Doubly LinkedList The explanation - [Search Element in Doubly Linked List in Java](https://beginnersbook.com/2024/05/search-element-in-doubly-linked-list-in-java/) - In this tutorial, we will learn how to write a Java program to search an element in doubly linked list. Java Program to search an element in doubly linked list In this program, we have a doubly linked list that contains the string elements. We are searching a specified string value in the list. The - [Java - Search an element in LinkedList with example](https://beginnersbook.com/2014/07/java-search-elements-in-linkedlist-example/) - In this tutorial, we will learn how to search elements in LinkedList in Java. We will be writing a java program that searches a given linked list for a specified element and returns its index as output. Method of LinkedList class for searching element There are two methods in linked list class that searches an - [Java - Replace an element in a LinkedList with example](https://beginnersbook.com/2014/07/java-replace-element-in-a-linkedlist-example/) - In this article, we will learn how to replace an element in linked list using set() method. This method is especially useful when we need to replace element at specified index in linked list. The set() method: public E set(int index, E newElement): This method takes two arguments, index and newElement. It replaces the current - [C Program to check whether a given integer is positive or negative](https://beginnersbook.com/2015/02/c-program-to-check-whether-the-given-integer-is-positive-or-negative/) - In this article, we will write a C Program to check whether a given integer is positive or negative. For example, if user enters -5 then program should print that it's a negative number. C Program to check if an integer is positive or negative In the following program, we are using if-else statement. If - [C program to calculate and print the value of nPr](https://beginnersbook.com/2015/02/c-program-to-calculate-and-print-the-value-of-npr/) - In this article, we will write a C program to calculate and print the value of nPr. The formula is: nPr = n! / (n - r)!, here ! represents factorial. For example 6P2 = 6! / (6-2)! => 720 / 24 = 30. C Program to print the value of nPr based on user input In - [C program to calculate and print the value of nCr](https://beginnersbook.com/2015/02/c-program-to-calculate-and-print-the-value-of-ncr/) - In this article, we will write a C program to calculate and print the value of nCr. The formula of nCr is: nCr = n! / ( r!(n - r)! ). For 0 - [C Program to Add two distances using structure](https://beginnersbook.com/2024/05/c-program-to-add-two-distances-using-structure/) - In this program, we will learn how to write a C Program to add two distances using structure. C Program to add two user input distances using structure The explanation of the program is provided at the end of the following code. The brief description of important statements and function is provided in the program - [C Program to multiply two complex numbers using structure](https://beginnersbook.com/2024/05/c-program-to-multiply-two-complex-numbers-using-structure/) - In this tutorial, we will learn how to write a C program to multiply two complex numbers using structure. C Program to find the product of two complex numbers using structure In this program, user is asked to enter two complex numbers, the program then calculates the product of entered numbers. The explanation of the - [C Program to Convert time from 24 hour to 12 hour format](https://beginnersbook.com/2024/05/c-program-to-convert-time-from-24-hour-to-12-hour-format/) - In this tutorial, we will learn how to write a C program to convert 24 hour time format to 12 hour time format. For example: Input: 23 59Output: 11:59 PM C Program for 24 hour time to 12 hour time conversion Let's write a program for this conversion. The detailed explanation of the program is - [C Program to find largest element of an Array](https://beginnersbook.com/2015/02/c-program-to-find-largest-element-of-an-array/) - In this article, we will write a C program to find the largest element of an array. For example, if an array contains these elements [4, 6, 1, 12, 2] then program should print largest element 12 as output. C Program to print largest element of an array In this program, user is asked to - [C Program to display Fibonacci series](https://beginnersbook.com/2014/06/c-program-to-display-fibonacci-series/) - In this tutorial, we will learn how to write a C Program to display fibonacci series. The Fibonacci series is a sequence of numbers in which each number is the sum of the two previous numbers, usually starting with 0 and 1. We will see two different ways to accomplish this: Example 1: C Program - [C program to Reverse a String using recursion](https://beginnersbook.com/2014/06/c-program-to-reverse-a-string-using-recursion/) - In this article, we will write a C program to reverse a string using recursion. A function calling itself with smaller instances is called recursion. Recursion can be used for problems that can be broken down into smaller, similar problems. C Program to reverse an input string using recursion In this program, the recursive function, - [C Program to find prime numbers in a given range](https://beginnersbook.com/2014/06/c-program-to-find-prime-numbers-in-a-given-range/) - In this article, we will write a C Program to find prime numbers in a given range. For example, if user enters the range from 1 to 10, then program should print prime numbers between 1 to 10, which are 2, 3, 5 and 7. C Program to print prime numbers in a range In - [C Program to check Armstrong number](https://beginnersbook.com/2014/06/c-program-to-check-armstrong-number/) - In this example, we will write a C Program to check Armstrong number. An Armstrong number (also known as narcissistic number) is a number that is equal to the sum of its own digits each raised to the power of the number of digits. For example, 370 is an Armstrong number //We are adding cubes - [C Program to calculate area of rectangle](https://beginnersbook.com/2024/05/c-program-to-calculate-area-of-rectangle/) - In this example, we will write a C program to calculate area of rectangle based on user input. For example, if user enters width as 4 and height as 2 then program should print 8 as area of rectangle. Area of rectangle = width * height C Program to calculate area of rectangle based on - [C Program to calculate area of rectangle](https://beginnersbook.com/2024/05/c-program-to-calculate-area-of-rectangle/) - In this example, we will write a C program to calculate area of rectangle based on user input. For example, if user enters width as 4 and height as 2 then program should print 8 as area of rectangle. Area of rectangle = width * height C Program to calculate area of rectangle based on - [C program to Calculate area of triangle using Heron's formula](https://beginnersbook.com/2024/05/c-program-to-calculate-area-of-triangle-using-herons-formula/) - In this article, we will write a C Program to calculate area of triangle using Heron's formula. According to Heron's formula, the area of the triangle is = sqrt(s * (s - a) * (s - b) * (s - c)). Here s is the semi-perimeter of the triangle, whose value can be calculated using - [C program to Calculate area of triangle using Heron's formula](https://beginnersbook.com/2024/05/c-program-to-calculate-area-of-triangle-using-herons-formula/) - In this article, we will write a C Program to calculate area of triangle using Heron's formula. According to Heron's formula, the area of the triangle is = sqrt(s * (s - a) * (s - b) * (s - c)). Here s is the semi-perimeter of the triangle, whose value can be calculated using - [C Program to find factorial of a number using Recursion](https://beginnersbook.com/2014/06/c-program-to-find-factorial-of-number-using-recursion/) - In this guide, we will write a C Program to find factorial of a number using recursion. Recursion is a process in which a function calls itself in order to solve smaller instances of the same problem. This process continues until the smaller instance reaches a base case, at this post the recursion process stops - [C Program to reverse a given number](https://beginnersbook.com/2014/06/c-program-to-reverse-a-given-number-using-recursive-function/) - In this article, we will learn how to write a C program to reverse a number. For example, if the given number is 1234 then program should return number 4321 as output. We will see two different ways to accomplish this. Example 1: C Program to reverse a given number using Recursion In this program, - [C Program to find sum of array elements](https://beginnersbook.com/2014/06/c-program-to-find-sum-of-array-elements-using-pointers-recursion-functions/) - In this article, we will learn how to write a C program to find sum of array elements. For example, if the array is [1, 2, 3, 4, 5] then the program should print 1+2+3+4+5 = 15 as output. We will see various different ways to accomplish this. Example 1: Program to find sum of - [C Program to find greatest of three numbers](https://beginnersbook.com/2014/06/c-program-to-find-greatest-of-three-numbers/) - In this tutorial, you will learn how to write a C program to find greatest of three numbers. We will see three programs: In the first program, we will use if statement, second program if..else statement and in third program we will use nested if..else statement to find the greatest number. Example 1: Program to - [C Program to calculate Area of an Equilateral triangle](https://beginnersbook.com/2014/06/c-program-to-calculate-area-of-equilatral-triangle/) - In this tutorial, you will learn how to write a C program to calculate area of an equilateral triangle. A triangle is called equilateral triangle if all three of its sides are equal. Formula to calculate area of an equilateral triangle: Area = (sqrt(3)/4 )* (side * side) C Program to calculate Area of an - [C Program to calculate Area and Circumference of Circle](https://beginnersbook.com/2014/06/c-program-to-calculate-area-and-circumference-of-circle/) - In this tutorial, you will learn how to write a C program to calculate area and circumference of a circle. This program is pretty simple as both the circle area and circle circumference need radius value. Formula to calculate are and circumference of circle Here 3.14159 is the value of Pi, represented by symbol π. - [C Program to print cube of a number upto an integer](https://beginnersbook.com/2024/05/c-program-to-print-cube-of-a-number-upto-an-integer/) - In this article, we will write a C Program to print cube of a number upto an integer. For example, if the user enters a number 2 then program should print the cube of each number from 1 till the entered number. The output should look like this: Enter an integer: 2Cube of 1 is - [C Program to print cube of a number upto an integer](https://beginnersbook.com/2024/05/c-program-to-print-cube-of-a-number-upto-an-integer/) - In this article, we will write a C Program to print cube of a number upto an integer. For example, if the user enters a number 2 then program should print the cube of each number from 1 till the entered number. The output should look like this: Enter an integer: 2Cube of 1 is - [C Program to convert a time from 12 hour to 24 hour format](https://beginnersbook.com/2024/05/c-program-to-convert-a-time-from-12-hour-to-24-hour-format/) - In this tutorial, we will write a C program to convert a time from 12 hour format to 24 hour format. For example: Input: 03:30 PMOutput: 15:30 C Program for 12 hour to 24 hour conversion Let's write the code for this conversion. The explanation of the code is provided in the code itself using - [C Program to print date of birth using structure](https://beginnersbook.com/2024/05/c-program-to-print-date-of-birth-using-structure/) - In this guide, we will learn how to write a C program to print date of birth using structure. This program will help you understand the usage of structure. C Program to print a person's date of birth using structure The explanation of this program is provided at the end of the code along with - [C Program to swap first occurrence of a character in a String](https://beginnersbook.com/2024/05/c-program-to-swap-first-occurrence-of-a-character-in-a-string/) - In this article, we will write a C program to swap first occurrence of a character in a String with the given character. C Program to swap first occurrence of character with another character A brief explanation of the statements is provided in the program itself using comments. You can find the detailed explanation at - [C Program to swap first occurrence of a character in a String](https://beginnersbook.com/2024/05/c-program-to-swap-first-occurrence-of-a-character-in-a-string/) - In this article, we will write a C program to swap first occurrence of a character in a String with the given character. C Program to swap first occurrence of character with another character A brief explanation of the statements is provided in the program itself using comments. You can find the detailed explanation at - [C Program to validate a given date](https://beginnersbook.com/2024/05/c-program-to-validate-a-given-date/) - In this tutorial, we will learn to write a C program to validate a given date. For example, if the user enters a date 31/02/2020 (where 02 is a month) then the program should be able to tell that its an invalid date. C Program to validate date Let's write the complete code for the - [C Program to check if a number is divisible by 3 and 5](https://beginnersbook.com/2024/05/c-program-to-check-if-a-number-is-divisible-by-3-and-5/) - In this article, we will write a very simple C program to check if a number is divisible by 3 and 5. C Program to check if a given number is divisible by 3 and 5 This program first takes an integer number as an input from the user. Then, it checks if the number - [C program to replace first occurrence of vowel with ‘-‘ in string](https://beginnersbook.com/2024/05/c-program-to-replace-first-occurrence-of-vowel-with-in-string/) - In this tutorial, we will learn how to write a C program to replace the first occurrence of vowel with '-'. C Program to replace first occurrence of vowel in a String with '-' Let's write the code. The detailed explanation of the program is provided at the end of the code. The brief explanation - [C program to replace first occurrence of vowel with ‘-‘ in string](https://beginnersbook.com/2024/05/c-program-to-replace-first-occurrence-of-vowel-with-in-string/) - In this tutorial, we will learn how to write a C program to replace the first occurrence of vowel with '-'. C Program to replace first occurrence of vowel in a String with '-' Let's write the code. The detailed explanation of the program is provided at the end of the code. The brief explanation - [C Program to swap first and last elements of an array](https://beginnersbook.com/2024/05/c-program-to-swap-first-and-last-elements-of-an-array/) - In this tutorial, we will write a C program to swap first and last element of an array. For example, if the given array is [1, 2, 3, 4] then the program should return an array [4, 2, 3, 1] with first and last element swapped. C Program to swap first and last elements of - [C Program to swap first and last elements of an array](https://beginnersbook.com/2024/05/c-program-to-swap-first-and-last-elements-of-an-array/) - In this tutorial, we will write a C program to swap first and last element of an array. For example, if the given array is [1, 2, 3, 4] then the program should return an array [4, 2, 3, 1] with first and last element swapped. C Program to swap first and last elements of - [C program to print numbers divisible by 3 and 5 from 1 to 100](https://beginnersbook.com/2024/05/c-program-to-print-numbers-divisible-by-3-and-5-from-1-to-100/) - In this article, we will see a simple C program to print all the numbers between 1 and 100 that are divisible by 3 and 5 both. C Program to print numbers that are divisible by 3 and 5 between 1 and 100 The program iterates through from numbers 1 to 100 using for loop. - [C Program to check abundant number](https://beginnersbook.com/2024/05/c-program-to-check-abundant-number/) - In this tutorial, we will write a C program to check if a number is abundant number or not. A number is called an abundant number if sum of its proper divisors (excluding itself) is greater than the number itself. Note: Proper divisors are numbers that divide the given number without leaving a remainder. For - [C Program to find sum of digits of a number](https://beginnersbook.com/2024/05/c-program-to-find-sum-of-digits-of-a-number/) - In this article, we will write a C program to find sum of digits of a given number. For example, if the input number is 345 then the output of the program should be 3+4+5 = 12. C Program to print sum of digits of a number Detailed explanation of the logic is provided at - [C Program to display factors of a number](https://beginnersbook.com/2024/05/c-program-to-display-factors-of-a-number/) - In this article, we will write a C program to display factors of a number. For example, if the input number is 12, then the program should print numbers 1, 2, 3, 4, 6, 12 as output. C program to print factors of a number Let's write the code that prompts user to enter a - [C Program to swap first and last digit of a number](https://beginnersbook.com/2024/05/c-program-to-swap-first-and-last-digit-of-a-number/) - In this article, we will write a simple C program to swap the first and last digit of a number. For example, if the input number is 3456, then the program should print 6453 (swapping first and last digit) as output. C Program to swap the first and last digit of a number In this - [C Program to swap first and last digit of a number](https://beginnersbook.com/2024/05/c-program-to-swap-first-and-last-digit-of-a-number/) - In this article, we will write a simple C program to swap the first and last digit of a number. For example, if the input number is 3456, then the program should print 6453 (swapping first and last digit) as output. C Program to swap the first and last digit of a number In this - [C Program to print the day for an input of date month and year](https://beginnersbook.com/2024/05/c-program-to-print-the-day-for-an-input-of-date-month-and-year/) - In this article, we will write a C program to print the day (for example Monday, Tuesday etc.) for an input of date, month and year. The explanation of the program is at the end of the code. #include #include // Function to calculate the day of the weekint calculateDayOfWeek(int day, int month, int year) - [C Program to print current date and time](https://beginnersbook.com/2024/05/c-program-to-print-current-date-and-time/) - In this tutorial, we will write a C program that prints the current date and time on console. First we are writing a basic program that fetches the local time from system and prints it on the screen. The explanation of this program is at the end of the code. Later in this article, we - [C Program for employee salary calculation using structure](https://beginnersbook.com/2024/05/c-program-for-employee-salary-calculation-using-structure/) - In this tutorial, we will write a C program to calculate the total salary of employees using structure. Program for salary calculation using structure The explanation of this is at the end of the program along with the sample output. #include // Define the structure for employee detailsstruct Employee { int id; // Employee ID - [C Program to read and print employee details using structure](https://beginnersbook.com/2024/05/c-program-to-read-and-print-employee-details-using-structure/) - In this tutorial, we will learn how to write a C program to read and print employee details using structures. C Program for employee details using structure #include // Define the structure for employee detailsstruct Employee { int id; // Employee ID char name[50]; // Employee Name float salary; // Employee Salary};int main() { // - [Gson Streaming APIs to read and write JSON With examples](https://beginnersbook.com/2024/05/gson-streaming-apis-to-read-and-write-json-with-examples/) - In this guide, we will learn how to use Gson streaming APIs to read and write JSON files. This is especially useful when we are working with large JSON files. In order to save memory consumption, we can use Gson APIs to read and write such files without loading complete JSON file into the memory. - [Gson Streaming APIs to read and write JSON With examples](https://beginnersbook.com/2024/05/gson-streaming-apis-to-read-and-write-json-with-examples/) - In this guide, we will learn how to use Gson streaming APIs to read and write JSON files. This is especially useful when we are working with large JSON files. In order to save memory consumption, we can use Gson APIs to read and write such files without loading complete JSON file into the memory. - [Check Buzz Number in Java and print all numbers in a range](https://beginnersbook.com/2022/11/buzz-number-in-java/) - A number which either ends with 7 or divisible by 7 is called Buzz number. For example, 35 is a Buzz number as it is divisible by 7, similarly 47 is also a Buzz number as it ends with 7. In this tutorial, we will write java programs to check Buzz number and print Buzz - [Instance Variables in Java - Definition and Usage](https://beginnersbook.com/2023/03/instance-variables-in-java-definition-and-usage/) - In Java, an instance variable is a variable that belongs to an instance of a class, rather than to the class itself. An instance variable is declared within a class, but outside of any method, and is defined for each object or instance of the class. This article provides an overview of instance variables in - [Instance Variables in Java - Definition and Usage](https://beginnersbook.com/2023/03/instance-variables-in-java-definition-and-usage/) - In Java, an instance variable is a variable that belongs to an instance of a class, rather than to the class itself. An instance variable is declared within a class, but outside of any method, and is defined for each object or instance of the class. This article provides an overview of instance variables in - [What is new Keyword in Java](https://beginnersbook.com/2022/10/what-is-new-keyword-in-java/) - The new keyword is used to create an object of a class. It allocates a memory to the object during runtime. It invokes the specified constructor of the class to create the object. It returns a reference to the allocated memory. How to use the new keyword? The following syntax is used to create an - [Java Program to Sort Strings in an Alphabetical Order](https://beginnersbook.com/2018/10/java-program-to-sort-strings-in-an-alphabetical-order/) - In this java tutorial, we will learn how to sort Strings in an Alphabetical Order. Java Example: Arranging Strings in an Alphabetical Order In this program, we are asking user to enter the count of strings that he would like to enter for sorting. Once the count is captured using Scanner class, we have initialized - [Check if String is Null, Empty or Blank in Java](https://beginnersbook.com/2022/10/check-if-string-is-null-empty-or-blank-in-java/) - In this guide, we will learn how to check if a string is null, empty or blank. First let's see what is the difference between null, empty or blank string in java. What is Null String? A string with no assigned value. For example: String str = null; The length of null string is zero - [What is int Keyword in Java](https://beginnersbook.com/2022/10/what-is-int-keyword-in-java/) - The int keyword is a primitive data type in Java. An int data type can hold values ranging from -231(-2147483648) to 231-1 (2147483647). public class JavaExample { public static void main(String[] args) { int num = 123456; System.out.println(num); } } Output: 123456 Note: Size of the integer is 32 bit (4 bytes). The default value - [C Program to Display Armstrong Number Between Two Intervals](https://beginnersbook.com/2022/12/c-program-to-display-armstrong-number-between-two-intervals/) - In this guide, we will write a C program to print all Armstrong numbers between the given ranges. A number is called Armstrong number, if it satisfies the following condition: abc...n = an + bn+ cn+... Here, n is the number of digits in the number For example:2 is an Armstrong number because 2 = - [Java Programs - Java Programming Examples with Output](https://beginnersbook.com/2017/09/java-examples/) - To understand a programming language you must practice the programs, this way you can learn any programming language faster. This page includes java programs on various java topics such as control statements, loops, classes & objects, functions, arrays etc. All the programs are tested and provided with the output. If you new to java and - [Java long to String Conversion](https://beginnersbook.com/2015/05/java-long-to-string/) - In this guide, we will discuss the following ways to convert a long value to a String: String.valueOf(long l) Method Long.toString(long l) Method String.format() Method Using DecimalFormat Using StringBuilder and StringBuffer Note: Out of all these ways, the String.valueOf() is the preferred method for conversion as it is null safe. If the long value is - [Java int to String Conversion With Examples](https://beginnersbook.com/2015/05/java-int-to-string/) - In this guide, you will learn how to convert an int to string in Java. We can convert int to String using String.valueOf() or Integer.toString() method. We can also use String.format() method for the conversion. 1. Convert int to String using String.valueOf() String.valueOf(int i) method takes integer value as an argument and returns a string - [Check Duck Number in Java and Print these numbers in a range](https://beginnersbook.com/2022/11/duck-number-in-java/) - A positive number that contains a zero digit is called Duck Number. The important point to note is that numbers with only leading zeroes are not Duck numbers. For example, 3056, 10045, 7770 are Duck Numbers while the numbers such as 012, 0045, 01444 are not Duck numbers. Note: 04505 is also a Duck number - [Emirp Number in Java with example](https://beginnersbook.com/2022/06/emirp-number-in-java-with-example/) - In this tutorial, you will learn how to write a java program to check if a number is Emirp number. What is an Emirp Number? A prime number is called Emirp number if we get a different prime number when its digits are reversed. For example, 13 is an Emirp number because: 13 is a - [Sphenic Number in Java - Check and Print all numbers in a range](https://beginnersbook.com/2022/11/sphenic-number-in-java-check-and-print-all-numbers-in-a-range/) - A Sphenic number is a product of three distinct prime numbers. For example, 66 is a sphenic number as it is a product of 2, 3, 11 and all these numbers are prime. Numbers such as 30, 42, 66, 70, 78 etc are all Sphenic Numbers. Java Program to Check Sphenic Number import java.util.*; public - [Java Date to Timestamp Conversion](https://beginnersbook.com/2022/11/java-date-to-timestamp-conversion/) - Timestamp has higher precision as it includes fraction seconds, while a Date is accurate upto seconds as it doesn't include fraction of seconds. In this guide, we will see java programs to convert a given Date to Timestamp. Program to Convert Date to Timestamp Timestamp constructor expects a long argument, it constructs a Timestamp object - [Java Object to String Conversion](https://beginnersbook.com/2022/11/java-object-to-string-conversion/) - In this guide, we will learn how to convert Object to String in Java. We will also see program for StringBuffer and StringBuilder object to String conversion. Java Program to convert an object of a class to String Here, we are using toString() and valueOf() methods to convert the object of Student class to a - [Java String to Object Conversion](https://beginnersbook.com/2022/11/java-string-to-object-conversion/) - In this guide, we will learn how to convert String to Object in Java. Object is a parent class of all the classes in Java so you can simply assign a string to an object to convert it. Program to Convert String to Object using simple assignment You can use the assignment operator (=) to - [Java String to float Conversion](https://beginnersbook.com/2022/11/java-string-to-float-conversion/) - In this guide, we will see how to convert String to float in Java. We will use the parseFloat() method of Float class for this conversion. public static float parseFloat(String str) This method takes string argument and returns a float number represented by the argument str. Program to Convert String to float public class JavaExample{ - [Queue Interface in Java Collections](https://beginnersbook.com/2017/08/queue-interface-in-java-collections/) - A Queue is designed in such a way so that the elements added to it are placed at the end of Queue and removed from the beginning of Queue. The concept here is similar to the queue we see in our daily life, for example, when a new iPhone launches we stand in a queue - [Wrapper class in Java](https://beginnersbook.com/2017/09/wrapper-class-in-java/) - In the OOPs concepts guide, we learned that object oriented programming is all about objects. The eight primitive data types byte, short, int, long, float, double, char and boolean are not objects, Wrapper classes are used for converting primitive data types into objects, like int to Integer, double to Double, float to Float and so - [Java Iterator with examples](https://beginnersbook.com/2014/06/java-iterator-with-examples/) - Iterator is used for iterating (looping) various collection classes such as HashMap, ArrayList, LinkedList etc. In this tutorial, we will learn what is iterator, how to use it and what are the issues that can come up while using it. Iterator took place of Enumeration, which was used to iterate legacy classes such as Vector. - [Generics in Java With Examples](https://beginnersbook.com/2022/11/generics-in-java-with-examples/) - Generics was introduced in 2004 in Java programming language. Before the introduction of generics, type safety was not available, which caused program to throw errors during runtime. In this tutorial, we will learn why generics are introduced and how to use them in Java. We will also cover wildcard generics with examples. Why to use - [Final Keyword In Java - Final variable, Method and Class](https://beginnersbook.com/2014/07/final-keyword-java-final-variable-method-class/) - In this tutorial we will learn the usage of final keyword. The final keyword can be used for variables, methods and classes. We will cover following topics in detail. 1) final variable2) final method3) final class 1) final variable final variables are nothing but constants. We cannot change the value of a final variable once - [Java ArrayList addAll(int index, Collection c) Method example](https://beginnersbook.com/2013/12/java-arraylist-addall-int-index-collection-c-method-example/) - In the last tutorial we have shared the example of addAll(Collection c) method which is used for adding all the elements of Collection c at the end of list. Here we will see another variant add(int index, Collection c) which adds all the elements of c at the specified index of a list. public boolean addAll(int - [Java - String regionMatches() Method example](https://beginnersbook.com/2013/12/java-string-regionmatches-method-example/) - The method regionMatches() tests if the two Strings are equal. Using this method we can compare the substring of input String with the substring of specified String. Two variants:public boolean regionMatches(int toffset, String other, int ooffset, int len): Case sensitive test.public boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len): It has option - [Java Program for Decimal to Octal Conversion](https://beginnersbook.com/2014/07/java-program-for-decimal-to-octal-conversion/) - In this guide, we will discuss the following two ways to convert decimal to octal in Java. Using predefined method toOctalString(int num) of Integer classWriting a custom logic for decimal to octal conversion Example 1: Decimal to Octal using toOctalString() method The Integer.toOctalString(int i) method accepts integer number as argument and returns the equivalent octal - [Java Program for Decimal to Hexadecimal Conversion](https://beginnersbook.com/2014/07/java-program-to-convert-decimal-to-hexadecimal/) - There are two following ways to convert a decimal number to hexadecimal number: 1) Using toHexString() method of Integer class.2) Do conversion by writing your own logic without using any predefined methods. Program 1: Decimal to hexadecimal Using toHexString() method The toHexString() method accepts integer number as argument and returns equivalent hexadecimal number as a - [Java program for binary to decimal conversion](https://beginnersbook.com/2014/07/java-program-for-binary-to-decimal-conversion/) - There are two following ways to convert binary number to decimal number: 1) Using Integer.parseInt() method of Integer class.2) Do conversion by writing your own logic without using any predefined methods. Method 1: Binary to Decimal conversion using Integer.parseInt() method The Integer.parseInt() method accepts two arguments, first argument is the string which you want to - [How to change Permalink Structure in WordPress](https://beginnersbook.com/2013/09/change-permalink-structure-wordpress/) - Changing permalink structure is an easy task but doing it properly without losing traffic & SEO is important thing. In this post we are gonna see what are the ways to change permalink structure in WordPress without any issues (Redirection, 404 errors). Last Post: Best Permalink Structure for WordPress SEO For first time change: If - [The Best Permalink Structure for WordPress SEO](https://beginnersbook.com/2013/09/permalink-structure-seo-wordpress/) - What is a permalink?It’s a permanent link to the page/post.In WordPress, by default it is setup as: https://beginnersbook.com/?p=111 Why it’s importance?SEO benefits - The target keyword should be present in permalink. Other advantage is that, it makes the users navigation easy if configured properly, which is also a plus point in terms of SEO. In - [How to find LSI keywords](https://beginnersbook.com/2013/01/how-to-find-lsi-keywords/) - Before you start reading below methods to learn how to find LSI keywords, I would highly recommend you to read my previous post about What are LSI keywords. In the previous post I discussed importance of LSI words over high keyword density. I also shared how such keywords can help to improve on page and - [LSI Keywords Simple Yet Very Powerful](https://beginnersbook.com/2012/11/lsi-keywords-for-better-ranking/) - Latent semantic indexing keywords (or LSI keywords) are nothing but SEO terms for related keywords or synonyms. In this Article I will cover basic aspects of Why we should use LSI keywords in an article and How to use them. Quick Links: What are LSI keywords?LSI and SEOResearch: How to find LSI keywords?Where to use - [Who Invented School?](https://beginnersbook.com/2022/09/who-invented-school/) - Horace Mann, born in Franklin, Massachusetts in 1796, is the man who is widely considered to be the inventor of the school system. He is also known as the Father of modern education. An American educator, abolitionist, and a reformer in the field of education, he was well-known for his efforts in promoting a strong - [Who Invented Homework?](https://beginnersbook.com/2022/10/who-invented-homework/) - Homework or assignment is a set of tasks teachers give to their students. These tasks are supposed to be completed by student at home before coming to the school the next day. The question that who invented the school homework is popular among students. The answer to this questions is: Horace Mann is the inventor - [Who invented Computer?](https://beginnersbook.com/2022/10/who-invented-computer/) - Charles Babbage, born in London, England in December 26, 1791, is the man who is widely considered to be the inventor of the digital computer. He is also known as the Father of computer. Why was Computer invented? Charles Babbage started working on computer in 1812, however the term computer was not used at that - [What is protected Keyword in Java](https://beginnersbook.com/2022/10/what-is-protected-keyword-in-java/) - The protected keyword is an access modifier in java. It is used for variables, methods and constructors. The fields marked with protected keyword are only accessible inside same package or through inheritance. Usage of protected Keyword A protected variable or method can only be accessed inside the same package. However they can also be accessed - [What is private Keyword in Java](https://beginnersbook.com/2022/10/what-is-private-keyword-in-java/) - The private keyword is an access modifier in java. It can be used for variables, methods, constructors and inner classes. Note: The private is the most restrictive modifier compared to other modifiers such as public, default and protected.It cannot be applied to a class (except inner class) or an interface.The private variables and methods can - [What is long Keyword in Java](https://beginnersbook.com/2022/10/what-is-long-keyword-in-java/) - The long keyword is a primitive data type in Java. Similar to int data type, it is used to store whole numbers. The range of long data type is much wider than int. A long data type has a range of -263(-9223372036854775808) to 263-1(9223372036854775807). public class JavaExample { public static void main(String[] args) { long - [Java instanceof With Examples](https://beginnersbook.com/2022/10/java-instanceof-with-examples/) - The instanceof keyword is an operator in java. It checks if the given object is an instance of a specified class or interface. It returns true or false. Let's take a simple example first, to see how instanceof works: public class JavaExample { public static void main(String[] args) { //the obj is an object of - [What is do Keyword in Java](https://beginnersbook.com/2022/10/what-is-do-keyword-in-java/) - The do keyword is used along with while keyword to form a do-while loop. do{ //body of do-while }while(condition); Example of do keyword public class JavaExample { public static void main(String[] args) { int i = 0; do { System.out.println(i); i++; }while (i < 6); } } Output: Why we need do while when we - [What is double Keyword in Java](https://beginnersbook.com/2022/10/what-is-double-keyword-in-java/) - The double keyword is a data type which is used to store decimal point values ranging from 1.7e-308 to 1.7e+308. This range is represented in "scientific notation", in normal form you can consider 1.7e+308 equivalent to 17 followed by 307 zeroes. public class JavaExample { public static void main(String[] args) { double num = 2005.455d; - [What is float Keyword in Java](https://beginnersbook.com/2022/10/what-is-float-keyword-in-java/) - The float keyword is a data type in Java, which is used for floating point values. The range for float data type is 3.4e-038 to 3.4e+038. This range is in scientific notation, the notation value 3.4e+038 is equivalent to 34 followed by 37 zeroes (see the example at the end of this post to learn - [What is default Keyword in Java](https://beginnersbook.com/2022/10/what-is-default-keyword-in-java/) - The default keyword is used inside switch block to mark a default case. Example of default keyword in switch block Used to specify a default case, this runs when no matching case is being found.It is placed in the end of the switch block and it doesn't require break statement.If there is matching case found - [What is a class Keyword in Java](https://beginnersbook.com/2022/10/what-is-a-class-keyword-in-java/) - The class keyword is used to create a class in Java. A class contains variables, methods, etc. A java code cannot execute without a class. Notes: The file in which java code is stored must match with the class name that contains main method.Class name is unique and cannot be duplicated inside same package.A java - [What is char Keyword in Java](https://beginnersbook.com/2022/10/what-is-char-keyword-in-java/) - The char keyword is a data type. You can store a character such as 'A', 'a' etc to the char variable. Important Points: The value assigned to a char data type is provided in single quotes such 'Q', 'h' etc.You can also pass integer numbers ranging from 0 to 65,535 to a char variable, these - [What is catch Keyword in Java](https://beginnersbook.com/2022/10/what-is-catch-keyword-in-java/) - The catch keyword is used in a try-catch block. A catch block is always comes after a try block, if any exception occurs inside try block, then it is handled by the corresponding catch block. The purpose of catch block is to provide a meaningful error message. try{ //statements }catch(Exception e){ //exception handling statements } - [What is case Keyword in Java](https://beginnersbook.com/2022/10/what-is-case-keyword-in-java/) - The case keyword is used inside switch block. Together they form a switch-case block which is used to evaluate condition and execute a corresponding case block based on the outcome of condition. Example of case keyword There are multiple cases inside a switch block. Based on the outcome of the condition specified in parentheses, a - [What is byte Keyword in Java](https://beginnersbook.com/2022/10/what-is-byte-keyword-in-java/) - The byte keyword has following two usages in Java: byte data typebyte return type of a method The byte keyword is used to define a primitive data type. A byte data type variable can hold values ranging from -128 to 127. The size of byte data type is 8 bit. It can also be used - [What is break Keyword in Java](https://beginnersbook.com/2022/10/what-is-break-keyword-in-java/) - The break keyword is used inside loops (for, while or do-while) or switch-case block. When used in loops: It ends the loop as soon as it is encountered, thus it is always accompanied by a condition. When used in switch block: It prevents execution of the next case statement after the execution of previous case - [What is a boolean Keyword in Java](https://beginnersbook.com/2022/10/what-is-a-boolean-keyword-in-java/) - The boolean keyword has following two usages in Java: boolean data typeboolean return type of a method The boolean keyword is a data type that is used when declaring a variable. The possible values of a boolean variable are true or false. boolean b1 = true; boolean b2 = false; It is also used as - [What is abstract Keyword in Java](https://beginnersbook.com/2022/10/what-is-abstract-keyword-in-java/) - The abstract keyword is used for classes and methods in Java. It is not an access modifier, but it is used to achieve abstraction in Java. abstract class: An abstract class does not allow you to create an object of it. To access the methods and variables of this class, you must inherit this class. - [Java Keywords With Examples](https://beginnersbook.com/2022/10/java-keywords-with-examples/) - List of keywords and their usages in Java Programming language. To learn more about a specific keyword, just click on the keyword and it will take you to a separate keyword tutorial where you can find examples and more details about that particular keyword. - [Java Integer parseInt()Method](https://beginnersbook.com/2022/10/java-integer-parseintmethod/) - Java Integer parseInt() method returns int value after parsing the given string using the specified radix. If radix is not provided, then it uses 10 as radix. Syntax of parseInt() method public static int parseInt(String s) throws NumberFormatException public static int parseInt(String s, int radix) throws NumberFormatException //this overloaded version is introduced in java 1.9 - [Java Integer numberOfTrailingZeros() Method](https://beginnersbook.com/2022/10/java-integer-numberoftrailingzeros-method/) - The numberOfTrailingZeros() method of Integer class, returns number of zero-bits after the last one-bit in the binary representation of the given int number. Returns 32 if there are no one-bit in the binary representation of the given int number (which means number is zero). Syntax of numberOfTrailingZeros() method public static int numberOfTrailingZeros(int i) numberOfTrailingZeros() Parameters - [Java Integer numberOfLeadingZeros() Method](https://beginnersbook.com/2022/10/java-integer-numberofleadingzeros-method/) - The numberOfLeadingZeros() method of Integer class, returns number of 0’s bits before the first one-bit in the binary representation of the given int number. If number is zero (there are no one-bit), then it returns 32. Syntax of numberOfLeadingZeros() method public static int numberOfLeadingZeros(int i) numberOfLeadingZeros() Parameters i – An int value whose number of - [Java Integer longValue() Method](https://beginnersbook.com/2022/10/java-integer-longvalue-method/) - The longValue() method of Integer class, returns the value represented by this Integer object as long. Since the size of long is greater than the size of int data type, It is also called widening primitive conversion. Syntax of longValue() method public long longValue() longValue() Parameters It does not have any parameter. longValue() ReturnValue Returns - [Java Integer intValue() Method](https://beginnersbook.com/2022/10/java-integer-intvalue-method/) - The intValue() method of Integer class returns the value of this Integer object as int. You can use this method for Integer to int conversion. Syntax of intValue() method public int intValue() intValue() Parameters NA intValue() Return Value Returns the value represented by Integer object as int primitive data type. Example 1 A value contained - [Operators in Java With Examples](https://beginnersbook.com/2017/08/operators-in-java/) - Operator is a symbol that instructs the compiler to perform a specific action. For example, a “+” operator instructs the compiler to perform addition, a “>” operator instructs the compiler to perform comparison, “=” for assignment and so on. In this guide, we will discuss operations in java with the help of examples. Operator and - [Data Types in Java](https://beginnersbook.com/2017/08/data-types-in-java/) - Data type defines the values that a variable can take, for example if a variable has int data type, it can only take integer values. In java we have two categories of data type: 1) Primitive data types 2) Non-primitive data types - Arrays and Strings are non-primitive data types, we will discuss them later - [Type Casting in Java](https://beginnersbook.com/2022/10/type-casting-in-java/) - Assigning a value of one primitive data type to another primitive data type is known as casting. There are two types of type casting in java as shown in the following diagram. Narrowing(explicit) type castingWidening(implicit) type casting Narrowing Type Casting It is also known as explicit type casting. It is done when assigning a larger - [DBMS 5NF](https://beginnersbook.com/2022/10/dbms-5nf/) - A relation is said to be in 5NF, if it satisfies the following conditions: It is in 4NF.It cannot be further broken down to smaller tables.The decomposed tables join operation must be lossless, which means the decomposed tables joined using natural join should produce original relation without loosing any information. 5NF Example Consider this table, - [DBMS 4NF](https://beginnersbook.com/2022/10/dbms-4nf/) - A relation is in 4NF if it satisfies the following conditions: It is in BCNF (Boyce Codd Normal Form).It does not have any multi-valued dependency. What is multi-valued dependency? Before we learn how to decompose a relation into 4NF, let's learn what is a multi-valued dependency. A relation is said to be in multi-valued dependency, - [Java Integer min() Method](https://beginnersbook.com/2022/10/java-integer-min-method/) - The min() method of Integer class, returns smaller of two int numbers passed as arguments to this method. It works similar to Math.min() method. Hierarchy: java.lang Package -> Integer Class -> min() Method Syntax of min() method public static int min(int a, int b) min() Parameters a - First operand.b - Second operand. min() Return - [Java Integer max() Method](https://beginnersbook.com/2022/10/java-integer-max-method/) - The max() method returns greater of two int numbers passed as arguments to this method. It works similar to Math.max() method. Hierarchy: java.lang Package -> Integer Class -> max() Method Syntax of max() method public static int max(int a, int b) max() Parameters a – An int number passed as first argument to max method.b - [Java Integer Class and Methods](https://beginnersbook.com/2022/10/java-integer-class-and-methods/) - Integer is a wrapper class for primitive int data type. This class provides several useful methods, which can be used to perform various operations on integers. In this guide, we will discuss all the methods of Java Integer class with examples. Constructors of Integer class in Java Java Integer class Methods 1. bitCount() The bitCount() - [Java Integer lowestOneBit() Method](https://beginnersbook.com/2022/10/java-integer-lowestonebit-method/) - The lowestOneBit() method of Integer class, returns an int value with a single one bit in the position of the lowest order. This is determined by placing one-bit at the lowest order (right most) in the binary representation of a given int number. For example: If the binary representation of a given number is 0000 - [Java Integer highestOneBit() Method](https://beginnersbook.com/2022/10/java-integer-highestonebit-method/) - The highestOneBit() method of Integer class, returns an int value with a single one bit in the position of the highest order. This is determined by placing one-bit at the highest position (left most) in the binary representation of a given int number. For example: If the binary representation of a given number is 0000 - [Java Integer hashCode() Method](https://beginnersbook.com/2022/10/java-integer-hashcode-method/) - The hashCode() method returns a hash code for the given integer value. Syntax of hashCode() method The following variation of hashCode() method does not accept any argument. It returns the hash code for the int value represented by this Integer object. Supported versions: Java 1.2 and onwards. public int hashCode() An overloaded version of hashCode() - [Java Program to read integer value from the Standard Input](https://beginnersbook.com/2017/09/java-program-to-read-integer-value-from-the-standard-input/) - In this program we will see how to read an integer number entered by user. Scanner class is in java.util package. It is used for capturing the input of the primitive types like int, double etc. and strings. Example: Program to read the number entered by user We have imported the package java.util.Scanner to use - [Java - Static Class, Block, Methods and Variables](https://beginnersbook.com/2013/04/java-static-class-block-methods-variables/) - Static keyword can be used with class, variable, method and block. Static members belong to the class instead of a specific instance, this means if you make a member static, you can access it without object. Let's take an example to understand this: Here we have a static method myMethod(), we can call this method - [Java StringBuffer class With Examples](https://beginnersbook.com/2022/10/java-stringbuffer-class/) - Java StringBuffer class is used to create mutable strings. A mutable string is the one which can be modified. StringBuffer is an alternative to Java String class. In this guide, we will discuss StringBuffer class in detail. We will also cover important methods of Java StringBuffer class with examples. Constructors of StringBuffer class Example of - [Java - String Class and Methods with examples](https://beginnersbook.com/2013/12/java-strings/) - String is a sequence of characters, for e.g. "Hello" is a string of 5 characters. In java, string is an immutable object which means it is constant and can cannot be changed once it is created. In this tutorial we will learn about String class and String methods with examples. Creating a String There are - [Exception Propagation in Java with examples](https://beginnersbook.com/2022/09/exception-propagation-in-java-with-examples/) - Exception propagation is a process by which compiler ensures that the exception is handled somewhere, if it is not handled where the exception occurs. For example, if main() method calls a method and that method (method1) is calling another method (method2). If the exception occurs in method2 and is not handled there then the exception - [Checked and unchecked exceptions in java with examples](https://beginnersbook.com/2013/04/java-checked-unchecked-exceptions-with-examples/) - There are two types of exceptions: checked exception and unchecked exception. In this guide, we will discuss them. The main difference between checked and unchecked exception is that the checked exceptions are checked at compile-time while unchecked exceptions are checked at runtime. What are checked exceptions? Checked exceptions are checked at compile-time. It means if - [Java Exception Handling Examples](https://beginnersbook.com/2013/04/exception-handling-examples/) - In this tutorial, we will see examples of some of the popular exceptions and how to handle them properly using try-catch block. We will see exception handling of ArithmeticException, ArrayIndexOutOfBoundsException, NumberFormatException, StringIndexOutOfBoundsException and NullPointerException. If you are new to the concept of exception handling, I highly recommend you to refer this starter guide: Exception handling - [Exception handling in Java with examples](https://beginnersbook.com/2013/04/java-exception-handling/) - Exception handling is one of the most important feature of java programming that allows us to handle the runtime errors caused by exceptions. In this guide, you will learn what is an exception, types of it, exception classes and how to handle exceptions in java with examples. What is an exception? An Exception is an - [Inner classes in java: Anonymous inner and static nested class](https://beginnersbook.com/2013/05/inner-class/) - What is an inner class? Inner class are defined inside the body of another class (known as outer class). These classes can have access modifier or even can be marked as abstract and final. Inner classes have special relationship with outer class instances. This relationship allows them to have access to outer class members including private members too. Inner - [OOPs Concepts in Java With Examples](https://beginnersbook.com/2013/04/oops-concepts/) - In this guide, you will learn the OOPs Concepts in Java. Object-oriented programming System(OOPs) is a programming concept that is based on "objects". The primary purpose of object-oriented programming is to increase the readability, flexibility and maintainability of programs. Object oriented programming brings data and its behaviour together in a single entity called objects. It - [String Array in Java](https://beginnersbook.com/2022/08/string-array-in-java/) - In this guide, you will learn about string array in java, how to use them and various operations that you can perform on string array in java. String array is a collection of strings, stored in contiguous memory locations. For example: The following string array contains four elements. These elements are stored in contiguous memory - [Break statement in Java with example](https://beginnersbook.com/2017/08/java-break-statement/) - The break statement is usually used in following two scenarios: a) Use break statement to come out of the loop instantly. Whenever a break statement is encountered inside a loop, the control directly comes out of loop and the loop gets terminated for rest of the iterations. It is used along with if statement, whenever - [Java Integer getInteger() Method](https://beginnersbook.com/2022/10/java-integer-getinteger-method/) - The getInteger() method of Integer class, returns the integer value of the system property with the specified property name. Hierarchy: java.lang Package -> Integer Class -> getInteger() Method Syntax of getInteger() method There are three variations of getInteger() method. Let's discuss them one by one. This first variation accept a single String name nm, which - [Java Integer floatValue() Method](https://beginnersbook.com/2022/10/java-integer-floatvalue-method/) - Java Integer floatValue() method returns the value of this Integer object as float after performing widening primitive conversion (Integer -> float). Hierarchy: java.lang Package -> Integer Class -> floatValue() Method Syntax of floatValue() method public float floatValue() floatValue() Parameters NA floatValue() Return Value It returns a float value equivalent to the value represented by this - [Java Integer equals() Method](https://beginnersbook.com/2022/10/java-integer-equals-method/) - Java Integer equals(Object obj) method compares this Integer object to the given object obj. It returns true if both the objects contain same int value else it returns false. Hierarchy: java.lang Package -> Integer Class -> equals() Method Syntax of equals() method public boolean equals(Object obj) equals() Parameters obj – The given object to compare - [Java Integer doubleValue() Method](https://beginnersbook.com/2022/10/java-integer-doublevalue-method/) - The doubleValue() method returns the value of this Integer as double after performing widening primitive conversion. Hierarchy: java.lang Package -> Integer Class -> doubleValue() Method Syntax of doubleValue() method public double doubleValue() doubleValue() Parameters NA doubleValue() Return Value A double data type value equivalent to the value of this Integer object numerically. Supported java versions: - [Java Integer divideUnsigned() Method](https://beginnersbook.com/2022/10/java-integer-divideunsigned-method/) - The divideUnsigned() method returns the unsigned quotient after dividing first argument by second argument. Syntax of divideUnsigned() method public static int divideUnsigned(int dividend, int divisor) divideUnsigned() Parameters dividend – The first int argument. The value to be divided.divisor – The second int argument. The value that is dividing. divideUnsigned() Return Value Returns unsigned quotient obtained - [Java Integer decode() Method](https://beginnersbook.com/2022/10/java-integer-decode-method/) - The decode() method decodes a given string into an Integer object. It can accept decimal, hexadecimal and octal strings as argument. Decimal strings: No prefix such as "102", "501" etc.Hexadecimal strings: 0x or 0X prefix such as "0x12E", "0XEF" etc.Octal strings: 0 prefix such as 0456, 0357 etc. Syntax of decode() method public static Integer - [Java Integer compareUnsigned() Method](https://beginnersbook.com/2022/10/java-integer-compareunsigned-method/) - The compareUnsigned() method compares two primitive int values without considering their sign. It is same as compare() method except that it doesn’t take sign into consideration while comparison. Syntax of compareUnsigned() method public static int compareUnsigned(int x, int y) compareUnsigned() Parameters x – First int number to comparey – Second int number to compare compareUnsigned() - [Java Integer compareTo() Method](https://beginnersbook.com/2022/10/java-integer-compareto-method/) - The compareTo() method compares this Integer with the Integer argument. It returns, 0 if this Integer is equal to given Integer, a value less than 0 if this Integer is less than Integer argument, a value greater than zero if this Integer is greater than Integer argument. This is a signed comparison. Hierarchy: java.lang Package - [Java Integer compare() Method](https://beginnersbook.com/2022/10/java-integer-compare-method/) - The compare() method compares two primitive int values passed as arguments to this method. It compares both the int values numerically. Syntax of compare() method public static int compare(int x, int y) compare() Parameters x – First int number to compare.y – Second int number to compare. compare() Return Value It returns the value 0 - [Java Integer byteValue() Method](https://beginnersbook.com/2022/10/java-integer-bytevalue-method/) - The byteValue() method of Integer class returns the given integer value in bytes after narrowing primitive conversion (Integer -> byte) . This method is used when you want to convert the Integer to bytes. Note: byte range is -128 to 127 and Integer range is -2,147,483,648 to 2,147,483,647 so it is clear that an Integer - [Java Integer bitCount() Method](https://beginnersbook.com/2022/10/java-integer-bitcount-method/) - The bitCount() method of Java Integer class returns the number of 1's bits in the two's complement representation of the given integer value. public class JavaExample { public static void main(String args[]) { int i = 24; // binary equivalent of 24 is: 11000 System.out.println(Integer.toBinaryString(i)); System.out.println(Integer.bitCount(i)); } } Output: 11000 2 Syntax of bitCount() method - [Java Math Class](https://beginnersbook.com/2022/10/java-math-class/) - Java Math class provides several useful methods that can be useful for performing various mathematical calculations in Java. It includes basic arithmetic, logarithmic and trigonometric methods. In this guide, we will discuss all the methods of Math class with examples. Note: All the methods of java math class are provided in the list at the - [Java Math.ulp() Method](https://beginnersbook.com/2022/10/java-math-ulp-method/) - Java Math.ulp() method returns distance between the number passed as argument and the next floating point number. An ulp (unit in the last place or unit of least precision) is the distance between two consecutive floating point numbers. public class JavaExample { public static void main(String[] args) { double d = 0.99; System.out.println(Math.ulp(d)); } } - [Java Math.IEEEremainder() Method](https://beginnersbook.com/2022/10/java-math-ieeeremainder-method/) - Java Math.IEEEremainder(double f1, double f2) method returns the remainder of f1/f2 based on the IEEE 754 standard. The remainder is equal to the f1 - f2 * n, where f1 and f2 are the arguments and n is an integer closest to the quotient of f1/f2. If two integers are equally close to the quotient - [Java Math.getExponent() Method](https://beginnersbook.com/2022/10/java-math-getexponent-method/) - Java Math.getExponent() method returns unbiased exponent used in the representation of the argument. This method can accept double and float arguments. public class JavaExample { public static void main(String[] args) { double x = Double.POSITIVE_INFINITY; // Returns Double.MAX_EXPONENT+1 System.out.println(Math.getExponent(x)); } } Output: 1024 Syntax of Math.getExponent() method public static int getExponent(double d) public static int - [Java Math.hypot() Method](https://beginnersbook.com/2022/10/java-math-hypot-method/) - Java Math.hypot(double x, double y) method returns the sqrt(x2 + y2), where x is the first argument and y is the second argument. This method doesn't throw any exception, if there is an overflow or underflow. This means, if the result of this method is less than Double.MIN_VALUE or greater than Double.MAX_VALUE then it doesn't - [Java Math.random() Method](https://beginnersbook.com/2022/10/java-math-random-method/) - Java Math.random() method returns a random double number between 0.0 and 1.0, where 0.0 is inclusive and 1.0 is exclusive. Number is chosen from this range randomly and each number has equal probability. public class JavaExample { public static void main(String[] args) { System.out.println(Math.random()); } } Output: You will most likely get a different output - [Java Math.floorDiv() Method](https://beginnersbook.com/2022/10/java-math-floordiv-method/) - Java Math.floorDiv(int x, int y) method returns the integer quotient value after dividing argument x by argument y. This method divides the argument x by y and then applies the floor() method on the result to get the integer that is less than or equal to the original quotient value. public class JavaExample { public - [Java Math.floor() Method](https://beginnersbook.com/2022/10/java-math-floor-method/) - Java Math.floor(double x) method returns the largest integer that is less than or equal to the given argument x. public class JavaExample { public static void main(String[] args) { double x = 100.99; //returns a double value equal to an integer //which is less than or equal to x System.out.println(Math.floor(x)); } } Output: 100.0 Syntax - [Java Math.expm1() Method](https://beginnersbook.com/2022/10/java-math-expm1-method/) - Java Math.expm1(double x) method returns ex - 1. Here, e is a Euler’s number, whose approximate value is 2.718281828459045. public class JavaExample { public static void main(String[] args) { double x = 1; // returns e (2.718281828459045) to power of 1 minus 1 System.out.println(Math.expm1(x)); } } Output: 1.718281828459045 Note: An interesting point to note is that for - [Java Math.toRadians() Method](https://beginnersbook.com/2022/10/java-math-toradians-method/) - Java Math.toRadians() method converts the given angle in degrees to radians. This the approximate conversion and in most of the cases, it is inexact. public class JavaExample { public static void main(String[] args) { double degrees = 45; // degrees to radians conversion double radians = Math.toRadians(degrees); System.out.println(radians); } } Output: 0.7853981633974483 Syntax of Math.toRadians() - [Java Math.toDegrees() Method](https://beginnersbook.com/2022/10/java-math-todegrees-method/) - Java Math.toDegrees() method converts the angle given in radians to degrees. This is the approximate conversion and result are not exactly what you would expect. public class JavaExample { public static void main(String[] args) { double radians = Math.PI; // radians to degrees conversion double degrees = Math.toDegrees(radians); System.out.println(degrees); } } Output: 180.0 Syntax of - [Java Math.tanh() Method](https://beginnersbook.com/2022/10/java-math-tanh-method/) - Java Math.tanh() method returns hyperbolic tangent of the given value. This method accepts double type value as an argument and returns the hyperbolic tangent of this value as a result. Hyperbolic tangent of a value x is defined as (ex - e-x)/(ex + e-x), where e is the Euler’s number whose value is 2.718281828459045. public - [Java Math.cosh() Method](https://beginnersbook.com/2022/10/java-math-cosh-method/) - Java Math.cosh() method returns hyperbolic cosine of the given value. This method accepts double type value as an argument and returns the hyperbolic cosine of this value as a result. Hyperbolic cosine of a value x is defined as (ex + e-x)/2, where e is the Euler’s number whose value is 2.718281828459045. public class JavaExample - [Java Math.sinh() Method](https://beginnersbook.com/2022/10/java-math-sinh-method/) - Java Math.sinh() method returns hyperbolic sine of the given value. This method accepts double type value as an argument and returns the hyperbolic sine of this value as a result. Hyperbolic sine of a value x is defined as (ex - e-x)/2, where e is the Euler's number whose value is 2.718281828459045. public class JavaExample - [Java Math.atan() Method](https://beginnersbook.com/2022/10/java-math-atan-method/) - Java Math.atan() method returns arc tangent of the given value. Arc tangent is the inverse of tangent function. The value returned by this method ranges between -pi/2 and pi/2. public class JavaExample { public static void main(String[] args) { double a = 0.0; System.out.println(Math.atan(a)); } } Output: 0.0 Syntax of Math.atan() method Math.atan(1); //returns 0.7853981633974483 - [Java Math.acos() Method](https://beginnersbook.com/2022/10/java-math-acos-method/) - Java Math.acos() method returns arc cosine of the given value. Arc cosine is the inverse of cosine function. The value returned by this method ranges between 0.0 and pi. public class JavaExample { public static void main(String[] args) { double a = 1.0; System.out.println(Math.acos(a)); } } Output: 0.0 Syntax of Math.acos() method Math.acos(-1); //returns 3.141592653589793 - [Java Math.asin() Method](https://beginnersbook.com/2022/10/java-math-asin-method/) - Java Math.asin() method returns arc sine of the given value. Arc sine is the inverse of the sine function. The value returned by this method ranges between -pi/2 and pi/2. public class JavaExample { public static void main(String[] args) { double a = 1.0; System.out.println(Math.asin(a)); } } Output: 1.5707963267948966 Syntax of Math.asin() method Math.asin(0); //returns - [Java Math.tan() Method](https://beginnersbook.com/2022/10/java-math-tan-method/) - Java Math.tan() method returns the trigonometric tangent of the given angle. This angle value (in radians) is passed as an argument to this method. For example, Math.tan(Math.toRadians(0)) returns 0.0. public class JavaExample { public static void main(String[] args) { double degrees = 0; //conversion degree to radians double radians = Math.toRadians(degrees); System.out.println(Math.tan(radians)); } } Output: - [Java Math.cos() Method](https://beginnersbook.com/2022/10/java-math-cos-method/) - Java Math.cos() method returns the trigonometric cosine of the given angle in radians. This angle value is passed as an argument to this method and it returns the cosine value ranging from -1 to 1. For example, Math.cos(Math.toRadians(0)) returns 1.0. public class JavaExample { public static void main(String[] args) { double degrees = 0; //conversion - [Java Math.sin() Method](https://beginnersbook.com/2022/10/java-math-sin-method/) - Java Math.sin() method returns the trigonometric sine of the given angle in radians. This angle value is passed as an argument to this method and it returns the sine value ranging from -1 to 1. For example, Math.sin(Math.toRadians(90)) returns 1.0. public class JavaExample { public static void main(String[] args) { double degrees = 90; //conversion - [Java Math.exp() Method](https://beginnersbook.com/2022/10/java-math-exp-method/) - Java Math.exp() method returns e raised to the power of given argument. Here e is a Euler's number, whose approximate value is 2.718281828459045. public class JavaExample { public static void main(String[] args) { double num = 1; // returns e (approx. 2.718281828459045) to power of 1 System.out.println(Math.exp(num)); } } Output: 2.718281828459045 Syntax of Math.exp() method - [Java null literal](https://beginnersbook.com/2022/10/java-null-literal/) - The null keyword in java is a literal. It is neither a data type nor an object. The null (all letters in small case) is a literal that represents the absence of a value. For example, if you assign a null to an object of string class, it does not refer to any value in - [Python Programming Examples With Output](https://beginnersbook.com/2018/02/python-programs/) - Here we are sharing Python programs on various topics of Python Programming such as array, strings, series, numbers, mathematical calculation, sorting & searching algorithms and many more. Our aim is to provide you the perfect solution to all the Python programming questions that you may face during interviews or in class assignments. Python Basic Programs - [RDBMS Concepts](https://beginnersbook.com/2015/04/rdbms-concepts/) - RDBMS stands for relational database management system. A relational model can be represented as a table of rows and columns. A relational database has following major components:1. Table2. Record or Tuple3. Field or Column name or Attribute4. Domain5. Instance6. Schema7. Keys 1. Table A table is a collection of data represented in rows and columns. - [Java Math.log1p() Method](https://beginnersbook.com/2022/10/java-math-log1p-method/) - Java Math.log1p() method returns natural logarithm (base e) of the sum of argument and 1. In simple words log1p(num) returns log(num+1). public class JavaExample { public static void main(String[] args) { double num = 25; //equivalent to log (25+1) i.e log(26) System.out.println(Math.log1p(num)); System.out.println(Math.log(num+1)); } } Output: 3.258096538021482 3.258096538021482 Syntax of Math.log1p() method Math.log1p(100); //returns 4.61512051684126 - [Java Math.log10() Method](https://beginnersbook.com/2022/10/java-math-log10-method/) - Java Math.log10() method returns base 10 logarithm of the double argument. In this tutorial, we will discuss log10() method with examples. Syntax of Math.log10() method Math.log10(10); //returns 1.0 log10() Description public static double log10(double num): Returns the base 10 logarithm of double argument num. The returns type of log10() method is double. log10() Parameters num: The double value - [Java Math.log() Method](https://beginnersbook.com/2022/10/java-math-log-method/) - Java Math.log(double num) method returns natural logarithm of the double value num. The natural logarithm is also known as base e logarithm. The e is a constant, whose approximate value is 2.71828. When base and the value both are equal then log returns 1. Here, we are trying to find out the base e log - [Java Math.toIntExact() Method](https://beginnersbook.com/2022/10/java-math-tointexact-method/) - Java Math.toIntExact() method returns the long argument as an int. This method accepts long data type value as an argument and returns the equivalent integer value. public class JavaExample { public static void main(String[] args) { long num = -1600568L; //converts long to int int i = Math.toIntExact(num); System.out.println(i); } } Output: -1600568 Syntax of - [Java Math.negateExact() Method](https://beginnersbook.com/2022/10/java-math-negateexact-method/) - Java Math.negateExact() method returns negation of the argument. If the given argument is positive, it returns the same argument with negative sign and vice versa. public class JavaExample { public static void main(String[] args) { int i = 151; //integer long l = -140056L; //long System.out.println(Math.negateExact(i)); System.out.println(Math.negateExact(l)); } } Output: -151 140056 Syntax of negateExact() - [Java Math.decrementExact() Method](https://beginnersbook.com/2022/10/java-math-decrementexact-method/) - Java Math.decrementExact() method returns the argument after decreasing it by one. In this tutorial, we will discuss decrementExact() method with examples. public class JavaExample { public static void main(String[] args) { int i = 50; //int long l = 16004L; //long System.out.println(Math.decrementExact(i)); System.out.println(Math.decrementExact(l)); } } Output: 49 16003 Syntax of decrementExact() method Math.decrementExact(50); //returns 49 - [Java Math.incrementExact() Method](https://beginnersbook.com/2022/10/java-math-incrementexact-method/) - Java Math.incrementExact() method returns the argument after increasing it by one. In this tutorial, we will discuss incrementExact() method with examples. public class JavaExample { public static void main(String[] args) { int i = 151; //int long l = 8004; //long System.out.println(Math.incrementExact(i)); System.out.println(Math.incrementExact(l)); } } Output: 152 8005 Syntax of incrementExact() method Math.incrementExact(1005); //returns 1006 - [Ternary Operator in Java with Examples](https://beginnersbook.com/2022/09/ternary-operator-in-java-with-examples/) - Ternary operator is the only operator in java that takes three operands. A ternary operator starts with a condition followed by a question mark (?), then an expression to execute if the condition is 'true; followed by a colon (:), and finally the expression to execute if the condition is 'false'. This operator is frequently - [Shift Operators in Java with Examples](https://beginnersbook.com/2022/09/shift-operators-in-java-with-examples/) - Shift operators are used to perform bit manipulation. In this guide, we will discuss various shift operators in java with the help of examples. Java supports following shift operators: 1. Signed Left Shift Operator ( - [Bitwise Operators in Java with Examples](https://beginnersbook.com/2022/09/bitwise-operators-in-java-with-examples/) - Bitwise operators are used to perform bit-level operations. Let's say you are performing an AND operation on two numbers (a & b), then these numbers are converted into binary numbers and then the AND operation is performed. Finally, the compiler returns decimal equivalent of the output binary number. Bitwise Operators in Java 1. Bitwise AND - [Relational Operators in Java with Examples](https://beginnersbook.com/2022/09/relational-operators-in-java-with-examples/) - Relational operators are used to compare two operands. In this guide, we will discuss various relational operators in java with the help of examples. Java programming language supports following relational operators. In any operation, there is an operator and operands. For example: In a+b, the "+" symbol is the operator and a & b are - [Unary Operators in Java with Examples](https://beginnersbook.com/2022/09/unary-operators-in-java-with-examples/) - The word Unary means an operation that involves a single element. As the name suggests, The Unary operators in Java involve single operand. Java supports following unary operators: Unary minus(-)Increment(++)Decrement(- -)NOT(!)Bitwise Complement(~) 1. Unary minus(-) Operator Example The unary minus operator changes the sign of the operand. This operator is used on numbers, it changes - [Logical Operators in Java with Examples](https://beginnersbook.com/2022/09/logical-operators-in-java-with-examples/) - Logical Operators are used to evaluate the outcome of conditions. There are three logical operators in java: AND (&&), OR (||) and NOT (!). The AND and OR operators are used when multiple conditions are combined and we need to evaluate the outcome as a whole. AND Operator: It returns true if all the conditions - [Arithmetic Operators in Java with Examples](https://beginnersbook.com/2022/09/arithmetic-operators-in-java-with-examples/) - Operator is a symbol that instructs the compiler to perform a specific action. For example, a “+” operator instructs the compiler to perform addition, a “>” operator instructs the compiler to perform comparison, “=” for assignment and so on. The operators in java are classified in eight different categories. In this guide, we will mainly - [Assignment Operators in Java with Examples](https://beginnersbook.com/2022/09/assignment-operators-in-java-with-examples/) - Operator is a symbol that instructs the compiler to perform a specific action. For example, a "+" operator instructs the compiler to perform addition, a ">" operator instructs the compiler to perform comparison, "=" for assignment and so on. The operators in java are classified in eight different categories. In this guide, we will mainly - [Java Math.multiplyExact() Method](https://beginnersbook.com/2022/10/java-math-multiplyexact-method/) - Java Math multiplyExact() method returns the product of its arguments. In this tutorial, we will discuss multiplyExact() method with examples. public class JavaExample { public static void main(String[] args) { int i = 20, i2 = 10; long l = 10000L, l2 = 15000L; System.out.println(Math.multiplyExact(i, i2)); System.out.println(Math.multiplyExact(l, l2)); } } Output: 200 150000000 Syntax of - [Java Math.addExact() Method](https://beginnersbook.com/2022/10/java-math-addexact-method/) - Java Math.addExact() method returns sum of its arguments. public class JavaExample { public static void main(String[] args) { int i = 10, i2 = 20; long l = 10000L, l2 = 15000L; System.out.println(Math.addExact(i, i2)); System.out.println(Math.addExact(l, l2)); } } Output: 30 25000 Syntax of Math.addExact() method Math.addExact(5, 7); //returns 12 addExact() Description public static int addExact(int - [Java Math.subtractExact() Method](https://beginnersbook.com/2022/10/java-math-subtractexact-method/) - Java Math.subtractExact() method returns the difference of its arguments. It subtracts the value of second argument from the first argument and returns the result. public class JavaExample { public static void main(String[] args) { int i = 20, i2 = 10; long l = 10000L, l2 = 15000L; System.out.println(Math.subtractExact(i, i2)); System.out.println(Math.subtractExact(l, l2)); } } Output: - [Java Math.nextDown() Method](https://beginnersbook.com/2022/10/java-math-nextdown-method/) - Java Math.nextDown() method returns floating point number adjacent to the passed argument, in the direction of negative infinity. public class JavaExample { public static void main(String[] args) { double d = 12345; float f = 8.88f; System.out.println(Math.nextDown(d)); System.out.println(Math.nextDown(f)); } } Output: 12344.999999999998 8.879999 Syntax of Math.nextDown() method Math.nextDown(12.25f); //returns 12.249999 nextDown() Description public static double - [Java Math.nextUp() Method](https://beginnersbook.com/2022/10/java-math-nextup-method/) - Java Math.nextUp() method returns floating point number adjacent to the passed argument, in the direction of positive infinity. public class JavaExample { public static void main(String[] args) { double d = 12345; float f = 8.88f; System.out.println(Math.nextUp(d)); System.out.println(Math.nextUp(f)); } } Output: 12345.000000000002 8.880001 Syntax of Math.nextUp() method Math.nextUp(12.25f); //returns 12.250001 nextUp() Description public static double - [Java Math.nextAfter() Method](https://beginnersbook.com/2022/10/java-math-nextafter-method/) - Java Math.nextAfter() method returns the floating point number adjacent to the first argument, in the direction of second argument. public class JavaExample { public static void main(String[] args) { double d1 = 12.8; //used for magnitude double d2 = 15; //used for direction double d3 = 10; //another direction System.out.println(Math.nextAfter(d1, d2)); System.out.println(Math.nextAfter(d1, d3)); } } - [Java StringBuffer codePointBefore()](https://beginnersbook.com/2022/10/java-stringbuffer-codepointbefore/) - Java StringBuffer codePointBefore(int index) method returns the unicode code point value for the character before the specified index. For example, sb.codePointBefore(5) would return the code point for character present at the index 4 in the given sequence sb. Here, sb is an object of StringBuffer class. Syntax of codePointBefore() method int codePoint = sb.codePointBefore(1); This statement will return - [Java StringBuffer codePointCount()](https://beginnersbook.com/2022/10/java-stringbuffer-codepointcount/) - Java StringBuffer codePointCount(int beginIndex, int endIndex) returns the code points count between the given indexes. In this tutorial, we will discuss codePointCount() method with examples. Syntax of codePointCount() method int cpCount = sb.codePointCount(3, 6); This statement will return the code points count for the characters between index 3 and index 6 in this sequence. Here, - [Java StringBuffer subSequence()](https://beginnersbook.com/2022/10/java-stringbuffer-subsequence/) - Java StringBuffer subSequence() method returns a sub sequence based on the start and end indexes. As we know, StringBuffer is a char sequence, the subSequence() method returns a subset of this sequence. Syntax of subSequence() method //returns the char sequence from index 3 to 6 //3 is inclusive and 6 is exclusive CharSequence cs = - [Java StringBuffer setCharAt()](https://beginnersbook.com/2022/10/java-stringbuffer-setcharat/) - Java StringBuffer setCharAt() method sets a specified character at the given index. This method changes the character sequence represented by StringBuffer object, as it replaces the existing char with new char. In this tutorial, we will discuss setCharAt() method with examples. Syntax of setCharAt() method sb.setCharAt(2, 'A'); //changes the char at index 2 with char - [Java StringBuffer codePointAt()](https://beginnersbook.com/2022/10/java-stringbuffer-codepointat/) - Java StringBuffer codePointAt(int index) method returns a code point value of the character present at the specified index. A code point is a numeric value that represents a char, letter, punctuation, space etc. In this guide, we will discuss codePointAt() method with examples. Syntax of codePointAt() method //returns code point of first char in the sequence - [Java StringBuffer offsetByCodePoints()](https://beginnersbook.com/2022/10/java-stringbuffer-offsetbycodepoints/) - Java StringBuffer offsetByCodePoints(int index, int codePointOffset) method returns the index of a character that is offset from the given index by the specified code points. Syntax of offsetByCodePoints() method int index = sb.offsetByCodePoints(3, 4); The above statement will return the index of a character that is 4 code points away from the character present at - [Java StringBuffer charAt()](https://beginnersbook.com/2022/10/java-stringbuffer-charat/) - Java StringBuffer charAt() method returns the character present at the given index. In this tutorial, we will discuss the charAt() method with examples. Syntax of charAt() method sb.charAt(0); //returns the first char sb.charAt(sb.length()-1); //returns the last char Here, sb is an object of StringBuffer class. charAt() Description public char charAt(int index): This method returns the character present at the specified - [Java StringBuffer ensureCapacity()](https://beginnersbook.com/2022/10/java-stringbuffer-ensurecapacity/) - Java StringBuffer ensureCapacity() method ensures that specified minimum capacity is maintained. If the current capacity is less than the specified minimum capacity then the capacity is increased. Syntax of ensureCapacity() method sb.ensureCapacity(25) //if current capacity < 25 then increase capacity Here, sb is an object of StringBuffer class. ensureCapacity() Description public void ensureCapacity(int min): If - [Java StringBuffer capacity()](https://beginnersbook.com/2022/10/java-stringbuffer-capacity/) - Java StringBuffer capacity() method returns the current capacity of StringBuffer object. In this tutorial, we will discuss the capacity() method in detail with the help of examples. StringBuffer sb = new StringBuffer(); //default capacity 16 StringBuffer sb = new StringBuffer(34); //capacity 34 Syntax of capacity() method int cp = sb.capacity() //returns the capacity of sb Here, - [Java StringBuffer toString()](https://beginnersbook.com/2022/10/java-stringbuffer-tostring/) - Java StringBuffer toString() method returns the string representation of this character sequence. An object of StringBuffer class represents a character sequence. The toString() method converts this sequence into a String. Syntax of toString() method String str = sb.toString(); //converts sb to a String str Here, sb is an object of StringBuffer class toString() Description public - [Java StringBuffer getChars()](https://beginnersbook.com/2022/10/java-stringbuffer-getchars/) - In this guide, we will discuss Java StringBuffer getChars() method with examples. Syntax of getChars() method //it will copy the chars from index 1 to 8 //and place it at 3rd index in chArray sb.getChars(1, 8, chArray, 3) Here, sb is an object of StringBuffer class. getChars() Description public void getChars(int srcBegin, int srcEnd, char[] - [Java StringBuffer indexOf()](https://beginnersbook.com/2022/10/java-stringbuffer-indexof/) - Java StringBuffer indexOf() method returns the first occurrence of the given string in this sequence. In this guide, we will discuss indexOf() method with examples. Syntax of indexOf() method sb.indexOf("hello"); //searches string "hello" in the sb sb.indexOf("hello", 4) //starts searching string "hello" from index 4 Here, sb is an object of StringBuffer class. indexOf() Description There are two variations - [Java StringBuffer lastIndexOf()](https://beginnersbook.com/2022/10/java-stringbuffer-lastindexof/) - Java StringBuffer lastIndexOf() method returns the index of last occurrence of the given string in this sequence. In this tutorial, we will discuss the lastIndexOf() method with examples. Syntax of lastIndexOf() method //Returns the index of last occurrence of string "welcome" sb.lastIndexOf("welcome"); //Returns index of last occurrence of "welcome" before index 5 sb.lastIndexOf("welcome", 5); Here, sb is - [Java StringBuffer length()](https://beginnersbook.com/2022/10/java-stringbuffer-length/) - Java StringBuffer length() method returns the length of the given sequence. The StringBuffer instance represents a character sequence, the length() method returns the total number of characters present in this sequence. Syntax of length() method //returns the length of the character sequence //represented by StringBuffer instance sb sb.length() length() Description public int length(): Returns the total - [Java StringBuffer trimToSize()](https://beginnersbook.com/2022/10/java-stringbuffer-trimtosize/) - Java StringBuffer trimToSize() method is used to reduce the capacity of StringBuffer instance, if possible. This method checks for non-utilized allocated space, it frees up the storage to optimize the buffer size. Syntax of trimToSize() method sb.trimToSize() //free up non-utilized buffer Here, sb is an object of StringBuffer class. trimToSize() Description public void trimToSize(): It optimizes the - [Java StringBuffer delete()](https://beginnersbook.com/2022/10/java-stringbuffer-delete/) - Java StringBuffer delete() method is used to delete a part of the string. A StringBuffer instance represents a character sequence. We can delete a portion of this char sequence, by specifying start and end index in delete() method. Syntax of delete() method //deletes a substring from first char till 5th char sb.delete(0, 5); //end index - [Java StringBuffer insert()](https://beginnersbook.com/2022/10/java-stringbuffer-insert/) - Java StringBuffer insert() method is used to insert the given element at the specified position in this character sequence. Syntax of insert() method //insert string "hello" at the position (index) 1 sb.insert(1, "hello"); //insert integer 100 at the index 2 sb.insert(2, 100); //insert boolean 'true' at the end of StringBuffer instance sb.insert(sb.length(), true); Here, sb is an object - [Java StringBuffer replace()](https://beginnersbook.com/2014/08/stringbuffer-replace-method-example/) - In this tutorial, we will discuss Java StringBuffer replace() method with the help of examples. Syntax of replace() method: //replace substring from index 4 to 9 by given string "hello" //4 is inclusive and 9 is exclusive sb.replace(4, 9, "hello"); replace() Description public StringBuffer replace(int start, int end, String str): Replace the substring starting from start index till end index with the - [Java StringBuffer substring()](https://beginnersbook.com/2014/08/stringbuffer-substring-method-example/) - In this tutorial, we will discuss the Java StringBuffer substring() method with the help of examples. The syntax of substring() method is: sb.substring(4) //substring starting from index 4 till end sb.substring(2, 5) //substring from index 2 till index 5 Here, sb is an object of StringBuffer class. substring() Description There are two variations of substring() method in Java StringBuffer class. public - [Java StringBuffer setLength() Method](https://beginnersbook.com/2022/10/java-stringbuffer-setlength-method/) - Java StringBuffer setLength() method is used to set a new length to the existing StringBuffer sequence. If the new length is greater than the current length then null characters are appended at the end of the sequence. Syntax of setLength() Method: sb.setLength(4); //set the length of sb to 4 Here, sb represents the object of Java - [Java StringBuffer deleteCharAt() Method](https://beginnersbook.com/2022/10/java-stringbuffer-deletecharat-method/) - In this guide, we will discuss the Java StringBuffer deleteCharAt() method with examples. Syntax of deleteCharAt() Method: sb.deleteCharAt(4); //deletes char present at index 4 Here sb is an instance of StringBuffer class. deleteCharAt() Description public StringBuffer deleteCharAt(int index): This method deletes the character present at the specified index. The StringBuffer instance returned by this method is one - [Java StringBuffer appendCodePoint() Method](https://beginnersbook.com/2022/10/java-stringbuffer-appendcodepoint-method/) - Java StringBuffer appendCodePoint(int codePoint) Method appends string representation of the specified code point to this sequence. In this guide, we will discuss appendCodePoint() method with examples. Syntax of appendCodePoint(): sb.appendCodePoint(90); The above statement would append character ‘Z’ (Unicode code point 90) at the end of the sequence represented by the object of StringBuffer class. appendCodePoint() - [Java StringBuffer append() Method](https://beginnersbook.com/2022/10/java-stringbuffer-append-method/) - The append() method of Java StringBuffer class is used to append a specified value at the end of this character sequence. Syntax of append() Method: //append string "welcome" at the end of sb sb.append("welcome"); //append the string "abc" at the end of sb char[] chArray = {'a', 'b', 'c'} sb.append(chArray); Here, sb is an object of StringBuffer - [Java - How to append a newline to StringBuffer](https://beginnersbook.com/2015/04/append-a-newline-to-stringbuffer/) - When we append the content to a StringBuffer object, the content gets appended to the end of sequence without any spaces and line breaks. For example: StringBuffer sb= new StringBuffer("Hello,"); sb.append("How"); sb.append("are"); sb.append("you??"); System.out.println(sb); This would produce this output: Hello,Howareyou?? So what if I would like to append space or new line to the buffer? - [Java - How null works with StringBuffer](https://beginnersbook.com/2015/04/how-null-works-with-stringbuffer/) - You should be careful while appending nulls to StringBuffer as it may result in the unexpected output (if you are not aware how null works with StringBuffer). When you append null to StringBuffer, it actually appends four character string "null" to the buffer instead of an empty string. Let’s take an example to see this - [Java Math.copySign() Method](https://beginnersbook.com/2022/10/java-math-copysign-method/) - Java Math.copySign() method returns the first argument with the sign of second argument. In simple words, it copies the sign of second argument and replaces the sign of first argument with this copied sign. public class JavaExample { public static void main(String[] args) { double n1 = 150.55, n2 = -32.56; System.out.println(Math.copySign(n1, n2)); } } - [Java Math.ceil() Method](https://beginnersbook.com/2022/10/java-math-ceil-method/) - Java Math.ceil() method returns the closest integer value, which is greater than or equal to the given value. For example, Math.ceil(9.9) would return 10. In this guide, we will discuss the ceil() method with examples. public class JavaExample { public static void main(String[] args) { double n1 = 5.55, n2 = -5.55; System.out.println(Math.ceil(n1)); System.out.println(Math.ceil(n2)); } - [Java Math.signum() Method](https://beginnersbook.com/2022/10/java-math-signum-method/) - Java Math.signum() method returns the signum function of passed argument. If the argument is zero, it returns zero. If argument is negative, it returns -1.0. If argument is positive, it returns 1.0. In this tutorial, we will discuss signum() method with examples. Note: In Mathematics, a signum function extracts the sign of a real number. - [Java Math.pow() Method](https://beginnersbook.com/2022/10/java-math-pow-method/) - Java Math.pow() method returns, first argument raised to the power of second argument. For example, Math.pow(3, 2) returns 9. In this tutorial, we will discuss pow() method with examples. public class JavaExample { public static void main(String[] args) { double num = 3, num2 = 2; //3 raised to the power 2 == 3*3 == - [Java Math.cbrt() Method](https://beginnersbook.com/2022/10/java-math-cbrt-method/) - Java Math.cbrt() method returns cube root of a given double value. In this guide, we will discuss cbrt() method with examples. public class JavaExample { public static void main(String[] args) { double num = 27; System.out.println("Cube root: "+Math.cbrt(num)); } } Output: Cube root: 3.0 Syntax of Math.cbrt() Method Math.cbrt(64); //returns 4.0 cbrt() Description public static - [Java Math.sqrt() Method](https://beginnersbook.com/2022/10/java-math-sqrt-method/) - Java Math.sqrt() method returns the square root of a given number. In this guide, we will discuss sqrt() method in detail with examples. public class JavaExample { public static void main(String[] args) { double num = 9; System.out.println("Square root: "+Math.sqrt(num)); } } Output: Square root: 3.0 Syntax of Math.sqrt() method Math.sqrt(16); //returns 4.0 sqrt() Description - [Java Math.min() Method](https://beginnersbook.com/2022/10/java-math-min-method/) - Java Math.min() method returns the smaller number between two numbers passed as arguments. In this tutorial, we will discuss Math.min() method with examples. public class JavaExample { public static void main(String args[]) { float f1 = -2.225f; float f2 = -6.5f; //This will print the smaller float number System.out.println(Math.min(f1, f2)); double d1 = 40000; double - [Java Math.round() Method](https://beginnersbook.com/2022/10/java-math-round-method/) - Java Math.round() method returns closest number to the passed argument. For example, Math.round(15.75) would return 16. In this tutorial, we will discuss the round() method with examples. public class JavaExample { public static void main(String[] args) { double d = 15.75; float f = -7.6f; // closest long value when rounding off double System.out.println(Math.round(d)); //closest - [Java Math.max() Method](https://beginnersbook.com/2022/10/java-math-max-method/) - Java Math.max() returns the greater number between two passed numbers. In this tutorial, we will discuss this method in detail with the help of examples. public class JavaExample { public static void main(String args[]) { float num = -15.5f; float num2 = -5.55f; //This will print the greater float number System.out.println(Math.max(num, num2)); double d1 = - [Java Math.abs() Method](https://beginnersbook.com/2022/10/java-math-abs-method/) - Java Math.abs() method returns an absolute value of the given number. In this tutorial, we will discuss abs() method with examples. public class JavaExample { public static void main(String args[]) { int i = -10; float f = -5f; System.out.println(Math.abs(i)); System.out.println(Math.abs(f)); } } Output: 10 5.0 Syntax of abs() Method Math.abs(-15.5); //returns 15.5 abs() Description - [Java StringBuilder capacity() Method](https://beginnersbook.com/2014/08/java-stringbuilder-capacity-method/) - Java StringBuilder capacity() method returns the current capacity of StringBuilder object. In this tutorial, we will discuss the capacity() method in detail with the help of examples. StringBuilder sb = new StringBuilder(); //default capacity 16 StringBuilder sb = new StringBuilder(34); //capacity 34 Syntax of capacity() method: int cp = sb.capacity() //returns the capacity of sb - [Java StringBuilder append() Method](https://beginnersbook.com/2014/08/java-stringbuilder-append-char-c-method/) - The append() method of Java StringBuilder class is used to append a specified value at the end of this character sequence. Syntax of append() Method: //append string "hello" at the end of sb sb.append("hello"); //append the string "xyz" at the end of sb char[] chArray = {'x', 'y', 'z'} sb.append(chArray); Here, sb is an object - [StringBuilder append() null values as "null" String](https://beginnersbook.com/2014/08/stringbuilder-append-null-values-as-null-string/) - While working with StringBuilder you may have come across a strange behaviour of append() method for null values. If you append a null value to the StringBuilder object, it would be stored as a "null" (four character string) in the object instead of no value at all. Let's take an example to understand what I - [How to append a newline to StringBuilder](https://beginnersbook.com/2014/08/how-to-append-a-newline-to-stringbuilder/) - There are following two ways to append a new Line to a StringBuilder object:1) StringBuilder.append("\n");2) StringBuilder.append(System.getProperty("line.separator")); Example In this example we have a StringBuilder object sb and we have demonstrated both the methods of adding a new line. class AddNewLineDemo{ public static void main(String args[]){ // Create StringBuilder object StringBuilder sb = new StringBuilder("String1 - - [Java StringBuilder offsetByCodePoints()](https://beginnersbook.com/2022/10/java-stringbuilder-offsetbycodepoints/) - The offsetByCodePoints(int index, int codePointOffset) method returns the index of a character that is offset from the given index by the specified code points. Syntax of offsetByCodePoints() Method: int index = sb.offsetByCodePoints(3, 4); The above statement will return the index of a character that is 4 code points away from the character present at index - [Java StringBuilder codePointBefore()](https://beginnersbook.com/2022/10/java-stringbuilder-codepointbefore/) - Java StringBuilder codePointBefore(int index) method returns the unicode code point for the character before the specified index. For example, sb.codePointBefore(5) would return the code point for character present at the index 4 in the given sequence sb. Syntax of codePointBefore() Method: int codePoint = sb.codePointBefore(1); The above statement would return the code point for the - [Java StringBuilder codePointCount()](https://beginnersbook.com/2022/10/java-stringbuilder-codepointcount/) - Java StringBuilder codePointCount(int beginIndex, int endIndex) returns the code point count between the specified indexes. In this tutorial, we will discuss codePointCount() method with examples. Syntax of codePointCount() Method: int cpCount = sb.codePointCount(2, 5); The above statement would return the code point count for the characters between index 2 and index 5 in this sequence. - [Java StringBuilder appendCodePoint()](https://beginnersbook.com/2022/10/java-stringbuilder-appendcodepoint/) - Java StringBuilder appendCodePoint(int codePoint) Method appends string representation of the specified code point to this sequence. In this guide, we will discuss appendCodePoint() method with examples. Syntax of appendCodePoint(): sb.appendCodePoint(90); The above statement would append character 'Z' (Unicode code point 90) at the end of the sequence represented by the object of StringBuilder class. appendCodePoint() - [Java StringBuilder codePointAt()](https://beginnersbook.com/2022/10/java-stringbuilder-codepointat/) - Java StringBuilder codePointAt(int index) method returns a code point value of the character present at the specified index. A code point is a numeric value that represents a char, letter, punctuation, space etc. In this guide, we will discuss codePointAt() method with examples. Syntax of codePointAt() Method: //returns code point of first char in the - [Java StringBuilder subSequence()](https://beginnersbook.com/2022/10/java-stringbuilder-subsequence/) - Java StringBuilder subSequence() method returns a sub sequence based on the start and end indexes. As we know, StringBuilder is a char sequence, the subSequence() method returns a subset of this sequence. Syntax of subSequence() Method: //returns the char sequence from index 2 to 5 //2 is inclusive and 5 is exclusive CharSequence cs = - [Java StringBuilder setCharAt()](https://beginnersbook.com/2022/10/java-stringbuilder-setcharat/) - Java StringBuilder setCharAt() method sets a specified character at the given index. This method changes the character sequence represented by StringBuilder object as it replaces the existing char with new char. In this tutorial, we will discuss setCharAt() method with examples. Syntax of setCharAt() Method: sb.setCharAt(2, 'A'); //changes the char at index 2 with char - [Java StringBuilder deleteCharAt()](https://beginnersbook.com/2022/10/java-stringbuilder-deletecharat/) - In this guide, we will discuss the Java StringBuilder deleteCharAt() method with examples. Syntax of deleteCharAt() Method: sb.deleteCharAt(3); //deletes char present at index 3 Here sb is an instance of StringBuilder class. deleteCharAt() Description public StringBuilder deleteCharAt(int index): This method deletes the character present at the specified index. The StringBuilder instance returned by this method - [Java StringBuilder getChars()](https://beginnersbook.com/2022/10/java-stringbuilder-getchars/) - In this guide, we will discuss Java StringBuilder getChars() method with examples. Syntax of getChars() method: //it will copy the sb char sequence from 1 to 5 //and paste it at 3rd index in chArray sb.getChars(1, 5, chArray, 3) Here, sb is an object of StringBuilder class. Also read: StringBuilder in Java getChars() Description public - [Java StringBuilder setLength()](https://beginnersbook.com/2022/10/java-stringbuilder-setlength/) - Java StringBuilder setLength() method is used to set a new length to the existing StringBuilder sequence. If the new length is greater than the current length then null characters are appended at the end of the sequence. Syntax of setLength() Method: sb.setLength(5); //set the length of sb to 5 Here, sb represents the object of - [Java StringBuilder toString()](https://beginnersbook.com/2022/10/java-stringbuilder-tostring/) - Java StringBuilder toString() method returns the string representation of the character sequence. As we learned in previous tutorial StringBuilder in Java that a StringBuilder instance represents a character sequence. The toString() method converts this sequence into a String. Syntax of toString() method: String str = sb.toString(); //converts sb to a String str Here, sb is - [Java StringBuilder reverse()](https://beginnersbook.com/2022/10/java-stringbuilder-reverse/) - Java StringBuilder reverse() method is used to reverse a given character sequence. Syntax of reverse() method: sb.reverse(); //reverses the string represented by sb Here, sb is an object of Java StringBuilder class. reverse() Description public StringBuilder reverse(): A StringBuilder instance represents a character sequence (a string). This method replaces the existing character sequence by reverse - [Java StringBuilder replace()](https://beginnersbook.com/2022/10/java-stringbuilder-replace/) - In this tutorial, we will discuss Java StringBuilder replace() method with the help of examples. Syntax of replace() method: //replace substring from index 4 to 9 by given string "hello" //4 is inclusive and 9 is exclusive sb.replace(4, 9, "hello"); replace() Description public StringBuilder replace(int start, int end, String str): Replace the substring starting from - [Java StringBuilder length()](https://beginnersbook.com/2022/10/java-stringbuilder-length/) - Java StringBuilder length() method returns the length of the string. The StringBuilder instance represents a character sequence, the length() method returns the total number of characters present in this sequence. The syntax of length() method is: //returns the length of the character sequence //represented by StringBuilder instance sb sb.length() length() Description public int length(): Returns - [Java StringBuilder trimToSize()](https://beginnersbook.com/2022/10/java-stringbuilder-trimtosize/) - Java StringBuilder trimToSize() method is used to reduce the capacity of StringBuilder instance, if possible. This method checks for non-utilized allocated space, it frees up the storage to optimize the buffer size. This method belongs to the StringBuilder class in Java. The syntax of trimToSize() method is: sb.trimToSize() //free up non-utilized buffer Here, sb is - [Java StringBuilder lastIndexOf()](https://beginnersbook.com/2022/10/java-stringbuilder-lastindexof/) - In this tutorial, we will discuss the Java StringBuilder lastIndexOf() method with the help of example programs. The syntax of lastIndexOf() method is: //Returns the index of last occurrence of string "welcome" sb.lastIndexOf("welcome"); //Returns index of last occurrence of "welcome" before index 5 sb.lastIndexOf("welcome", 5); Here, sb is an object of StringBuilder class. lastIndexOf() Description - [Java StringBuilder indexOf()](https://beginnersbook.com/2022/10/java-stringbuilder-indexof/) - In this guide, we will discuss the Java StringBuilder indexOf() method with the help of examples. The syntax of indexOf() method is: sb.indexOf("hello"); //searches string "hello" in the sb sb.indexOf("hello", 4) //starts searching string "hello" from index 4 Here, sb is an object of StringBuilder class. indexOf() Description There are two variations of indexOf() method - [Java StringBuilder indexOf()](https://beginnersbook.com/2022/10/java-stringbuilder-indexof/) - In this guide, we will discuss the Java StringBuilder indexOf() method with the help of examples. The syntax of indexOf() method is: sb.indexOf("hello"); //searches string "hello" in the sb sb.indexOf("hello", 4) //starts searching string "hello" from index 4 Here, sb is an object of StringBuilder class. indexOf() Description There are two variations of indexOf() method - [Java StringBuilder ensureCapacity()](https://beginnersbook.com/2022/10/java-stringbuilder-ensurecapacity/) - In this tutorial, we will discuss the Java StringBuilder ensureCapacity() method with the help of examples. This method ensures that a minimum capacity is maintained. If the current capacity is less than the specified minimum capacity then the capacity is increased. The syntax of ensureCapacity() method is: sb.ensureCapacity(34) //if capacity is less than 34 then - [Java StringBuilder ensureCapacity()](https://beginnersbook.com/2022/10/java-stringbuilder-ensurecapacity/) - In this tutorial, we will discuss the Java StringBuilder ensureCapacity() method with the help of examples. This method ensures that a minimum capacity is maintained. If the current capacity is less than the specified minimum capacity then the capacity is increased. The syntax of ensureCapacity() method is: sb.ensureCapacity(34) //if capacity is less than 34 then - [Java StringBuilder insert()](https://beginnersbook.com/2022/10/java-stringbuilder-insert/) - The insert() method of Java StringBuilder class is used to insert the given element at the specified position in this character sequence. The Syntax of insert() method is: //insert string "hello" at the position (index) 1 sb.insert(1, "hello"); //insert integer 100 at the index 2 sb.insert(2, 100); //insert boolean 'true' at the end of StringBuilder - [Java StringBuilder substring()](https://beginnersbook.com/2022/10/java-stringbuilder-substring/) - In this tutorial, we will discuss the Java StringBuilder substring() method with the help of examples. The syntax of substring() method is: sb.substring(4) //substring starting from index 4 till end sb.substring(2, 5) //substring from index 2 till index 5 Here, sb is an object of StringBuilder class. substring() Description There are two variations of substring() - [Java StringBuilder substring()](https://beginnersbook.com/2022/10/java-stringbuilder-substring/) - In this tutorial, we will discuss the Java StringBuilder substring() method with the help of examples. The syntax of substring() method is: sb.substring(4) //substring starting from index 4 till end sb.substring(2, 5) //substring from index 2 till index 5 Here, sb is an object of StringBuilder class. substring() Description There are two variations of substring() - [Java StringBuilder delete()](https://beginnersbook.com/2022/10/java-stringbuilder-delete/) - Java StringBuilder delete() method is used to delete a portion of the string. A StringBuilder instance represents a character sequence. We can delete a portion of this char sequence, by specifying start and end index in delete() method. The syntax of delete() method is: //deletes a substring from first char till 5th char sb.delete(0, 5); - [Java StringBuilder charAt()](https://beginnersbook.com/2014/08/java-stringbuilder-charat-method/) - In this tutorial, we will discuss the Java StringBuilder charAt() method with the help of examples. The syntax of charAt() method is: sb.charAt() Here, sb is an object of StringBuilder class. charAt() Description public char charAt(int index): This method returns the character present at the specified index. The first char of StringBuilder is at index - [DBMS Tutorial - Database Management System notes](https://beginnersbook.com/2015/04/dbms-tutorial/) - DBMS stands for Database Management System. We can break it like this DBMS = Database + Management System. Database is a collection of data and Management System is a set of programs to store and retrieve those data. Based on this we can define DBMS like this: DBMS is a collection of inter-related data and - [Tic Tac Toe in C Programming using 2D Array](https://beginnersbook.com/2022/09/tic-tac-toe-in-c-programming-using-2d-array/) - In this guide, we will write a C program to implement Tic Tac Toe game using 2D array. C Program #include #include //2d array to represent tic tac toe matrix char matrix[3][3]; char checkBoard(void); void init_matrix(void); void playerTurn(void); void computerTurn(void); void displayBoard(void); int main(void) { char done; printf("Welcome to Tic Tac Toe Game.\n"); - [Tic Tac Toe in C Programming using 2D Array](https://beginnersbook.com/2022/09/tic-tac-toe-in-c-programming-using-2d-array/) - In this guide, we will write a C program to implement Tic Tac Toe game using 2D array. C Program #include #include //2d array to represent tic tac toe matrix char matrix[3][3]; char checkBoard(void); void init_matrix(void); void playerTurn(void); void computerTurn(void); void displayBoard(void); int main(void) { char done; printf("Welcome to Tic Tac Toe Game.\n"); - [Split String into array of Characters in Java](https://beginnersbook.com/2022/09/split-string-into-array-of-characters-in-java/) - In this guide, we will see how to split a string into array of characters in Java. This can be archived by using this regex (?!^) in the split method of Java string class. Java Program to Split String into Array of Characters Explanation of regex ( ? ! ^ ): The ?! part in - [Split String into array of Characters in Java](https://beginnersbook.com/2022/09/split-string-into-array-of-characters-in-java/) - In this guide, we will see how to split a string into array of characters in Java. This can be archived by using this regex (?!^) in the split method of Java string class. Java Program to Split String into Array of Characters Explanation of regex ( ? ! ^ ): The ?! part in - [Split String by Multiple Delimiters in Java](https://beginnersbook.com/2022/09/split-string-by-multiple-delimiters-in-java/) - We learned various ways to split string in Java. In this guide, we will see how to split string by multiple delimiters in Java. Program to Split String by Multiple Delimiters In this example, we have a string that contains multiple special characters, we want to split this string using these special characters as delimiters. - [Split String by Multiple Delimiters in Java](https://beginnersbook.com/2022/09/split-string-by-multiple-delimiters-in-java/) - We learned various ways to split string in Java. In this guide, we will see how to split string by multiple delimiters in Java. Program to Split String by Multiple Delimiters In this example, we have a string that contains multiple special characters, we want to split this string using these special characters as delimiters. - [Split String by Dot (.) in Java](https://beginnersbook.com/2022/09/split-string-by-dot-in-java/) - You can split a string by dot using the following regex inside the String.split() method. Here, we need to use double backslash before dot(.) to escape it else it would split the string using any character. str.split("\."); Program to split string by dot public class JavaExample{ public static void main(String args[]){ //String that contains dot - [Split String by space in Java](https://beginnersbook.com/2022/09/split-string-by-space-in-java/) - In this guide, we will write a program to split a string by space in Java. Java Program to split string by space You can use \s+ regex inside split string method to split the given string using whitespace. See the following example. \s - Matches any white-space character. The extra backslash is to escape the - [Split String by Pipe Character ( | ) in Java](https://beginnersbook.com/2022/09/split-string-by-pipe-character-in-java/) - In this example, we will see how to write a java program to split a string by pipe | symbol. Java Program to split string by Pipe Pipe represented by | symbol, is a meta character in regex. If you simply pass the | in split method like this: str.split("|") then it would return an unexpected - [Split String by Capital letters in Java](https://beginnersbook.com/2022/09/split-string-by-capital-letters-in-java/) - In this example, we will see how to write a program to split a string by capital letters in Java. Java Program to split string by Capital Letters To split a string by capital letters, we will use (?=\p{Lu}) regex. We will pass this regex in Java String split() method as shown in the following - [Computer Network Topology - Mesh, Star, Bus, Ring and Hybrid](https://beginnersbook.com/2019/03/computer-network-topology-mesh-star-bus-ring-and-hybrid/) - Geometric representation of how the computers are connected to each other is known as topology. There are eight types of topology - Mesh, Star, Bus, Ring, Hybrid, Tree, P2P and Daisy chain. Types of Topology There are mainly eight types of topology in computer networks: Mesh TopologyStar TopologyBus TopologyRing TopologyHybrid TopologyTree TopologyP2P TopologyDaisy Chain Topology - [Method Overloading in Java with examples](https://beginnersbook.com/2013/05/method-overloading/) - Method Overloading is a feature that allows a class to have multiple methods with the same name but with different number, sequence or type of parameters. In short multiple methods with same name but with different signatures. For example the signature of method add(int a, int b) having two int parameters is different from signature - [What is Hybrid Topology – Advantages and Disadvantages](https://beginnersbook.com/2022/09/what-is-hybrid-topology/) - Hybrid topology is a combination of two or more computer network topologies. For example a hybrid of star and bus topology is called tree topology. Tree topology is an example of hybrid topology. Use of Hybrid Topology Hybrid topology is used to get the benefits of more than one topology. For example a star topology - [What is Star Topology - Advantages and Disadvantages](https://beginnersbook.com/2022/09/what-is-star-topology/) - A Star Topology is a network topology in which, devices are connected to a central device known as hub. This forms a star pattern thus this topology is named Star topology, it is also referred as star network. In this guide, we will discuss Star topology, its applications, types and advantages & disadvantages. What is - [What is Mesh Topology – Advantages and Disadvantages](https://beginnersbook.com/2022/09/what-is-mesh-topology/) - In mesh topology, all the devices on the network are connected with each other. For example, if a mesh topology has four computers A, B, C and D on the network then computer A has direct one to one connection with B, C and D. Similarly device B has one to one connection with A, - [What is Ring Topology – Advantages and Disadvantages](https://beginnersbook.com/2022/09/what-is-ring-topology/) - A geometrical representation of devices that are connected in a circular manner is called Ring topology. Each device in the ring topology is connected to immediate neighbour devices on both sides. A network that follows the ring topology is often referred as ring network. In ring topology, data travels in a direction, passing from one - [What is Tree Topology – Advantages and Disadvantages](https://beginnersbook.com/2022/09/what-is-tree-topology/) - Tree topology is a geometrical representation of devices in a network, that are connected to each other in such a way that, it forms a tree like structure. Tree Topology is an example of hybrid topology. A hybrid topology is a combination of two or more computer network topologies. In this guide, we will discuss - [Program to Implement Merge Sort in Java](https://beginnersbook.com/2022/09/program-to-implement-merge-sort-in-java/) - In this guide, you will learn how to implement merge sort algorithm in Java. What is a Merge Sort in Java? Merge sort algorithm is used to sort a group of elements. It is a general purpose comparison based algorithm. Merge sort is based on the principe of divide-and-conquer approach that was invented by John - [Convert Integer List to int Array in Java](https://beginnersbook.com/2022/09/convert-integer-list-to-int-array-in-java/) - In this guide, we will see how to convert Integer List to int Array in Java. There are several ways, you can do this conversion, we have covered following methods: Using toArray() methodUsing simple for loopUsing Stream API 1. Using toArray() method This is one of the simplest way of doing the ArrayList to Array - [Convert a Set of String to a comma separated String in Java](https://beginnersbook.com/2022/09/convert-a-set-of-string-to-a-comma-separated-string-in-java/) - Problem description: We have given a Set that contains String elements. Our task is to convert this set of string to a comma separated string in Java. For example: Input: Set = ["Apple", "Orange", "Mango"] Output: "Apple, Orange, Mango" Input: Set = ["J", "a", "v", "a"] Output: "J, a, v, a" Example 1: Using String.join() - [How to Convert ArrayList to HashSet in Java](https://beginnersbook.com/2022/09/convert-arraylist-to-hashset-in-java/) - There are several ways to convert ArrayList to HashSet. In this guide, we will discuss the following ways with examples: Passing ArrayList to constructor of HashSet classIterating ArrayList and adding elements to HashSet using HashSet.add()Using HashSet.addAll() methodUsing java 8 stream 1. Passing ArrayList to constructor of HashSet class One of the constructor of HashSet accepts - [HashSet in Java With Examples](https://beginnersbook.com/2013/12/hashset-class-in-java-with-example/) - This class implements the Set interface, backed by a hash table (actually a HashMap instance). It does not guarantee the iteration order of the set. This means that the iteration order of Java HashSet elements doesn't remain constant. This class permits the null element. Points to Note about HashSet: HashSet internally uses Hashtable data structure.HashSet - [Python Programming Examples With Output](https://beginnersbook.com/2022/09/python-programming-examples/) - Here we are sharing Python programs on various topics of Python Programming such as array, strings, series, numbers, mathematical calculation, sorting & searching algorithms and many more. Our aim is to provide you the perfect solution to all the Python programming questions that you may face during interviews or in class assignments. Python Basic Programs Hello World - [C++ Example Programs With Output](https://beginnersbook.com/2022/09/cpp-example-programs-with-output/) - Here we are sharing C++ programs on various topics of C++ Programming such as array, strings, series, area & volume of geometrical figures, mathematical calculation, sorting & searching algorithms and many more. Our aim is to provide you the perfect solution of all the C++ programming questions that you may have either faced during interviews or in - [Convert Comma Separated String to HashSet in Java](https://beginnersbook.com/2022/09/convert-comma-separated-string-to-hashset-in-java/) - In this guide, we will discuss, how to convert a comma separated string to HashSet in Java. We will be using the String split() method to split the string into multiple substrings and then these substrings will be stored as HashSet elements. Input String: "text1,text2,text3" Output HashSet Elements: ["text1", "text2", "text3"] Input String: "Apple,Orange,Banana" Output - [Java Pattern split() Method With Examples](https://beginnersbook.com/2022/09/java-pattern-split-method/) - The split() method of Pattern class is used to split a string based on the specified pattern. Similar to java string split method, this method also accepts regular expression as delimiter. The Pattern class belongs to java.util.regex package, you need to import java.util.regex.Pattern package to use this class. There are two variants of the Java - [Java Code to Split String by Comma](https://beginnersbook.com/2022/09/java-code-to-split-string-by-comma/) - In this guide, we will discuss how to split a string by comma (,). You can use Java String split() method to split a given string. Example 1: Split String by Comma Here, we have a comma separated string. To split this string into substring using comma as delimiter, we are passing the , symbol - [Split String by Newline in Java](https://beginnersbook.com/2022/09/split-string-by-newline-in-java/) - In this guide, you will learn how to split string by newline in Java. The newline character is different for various operating systems, so I will try to cover the java code for most of the operating systems such as Mac OS, Windows, Unix and Linux. How to Split String by Newline in Java 1. - [How to Split a String in Java with Delimiter](https://beginnersbook.com/2022/09/how-to-split-a-string-in-java-with-delimiter/) - In this guide, you will learn how to split a string in java with delimiter. There are three ways you can split a string in java, first and preferred way of splitting a string is using the split() method of string class. The second way is to use the Scanner class. Other way is using - [StringTokenizer in Java with Examples](https://beginnersbook.com/2022/09/stringtokenizer-in-java-with-examples/) - In this guide, we will discuss StringTokenizer in Java. StringTokenizer The primary purpose of this class is provide methods to split string in java. The substrings generated after splitting are referred as tokens. A Simple Example of StringTokenizer Class Let's see a simple example, where we are using StringTokenizer class to split a given string - [Java - How to Convert a String to ArrayList](https://beginnersbook.com/2015/05/java-string-to-arraylist-conversion/) - In this java tutorial, you will learn how to convert a String to an ArrayList. Input: 22,33,44,55,66,77 Delimiter: , (comma) Output: ArrayList with 6 elements {22, 33, 44, 55, 66, 77} Input: Welcome to BeginnersBook Delimiter: " " (whitespace) Output: ArrayList with 3 elements {"Welcome", "to", "BeginnersBook"} The steps to convert string to ArrayList: 1) - [C Program to print Prime Numbers from 1 to 100 (or 1 to N)](https://beginnersbook.com/2022/09/c-program-to-print-prime-numbers-from-1-to-100-or-1-to-n/) - In this article, we will learn how to write a C program to print prime numbers from 1 to 100. We will also see a program to display prime numbers from 1 to n where value of n is entered by user. Program to print Prime Numbers from 1 to 100 In this program, we have - [StringTokenizer vs Split Method - Which is better?](https://beginnersbook.com/2022/09/stringtokenizer-vs-split-method-which-is-better/) - In this article, you will learn the difference between StringTokenizer and split() method in Java. Let's see how these two methods are used to split a given string then we will discuss the difference. StringTokenizer import java.util.*; class JavaExample { public static void main(String[] args) { String str = "20-09-2022"; StringTokenizer strToken = new StringTokenizer(str, - [HashMap in Java With Examples](https://beginnersbook.com/2013/12/hashmap-in-java-with-example/) - HashMap is a Map based collection class that is used for storing Key & value pairs, it is denoted as HashMap or HashMap. HashMap in java, is similar to the Hashtable class except that it is unsynchronized and permits nulls(null values and null key). It is not an ordered collection which means it - [ArrayList in Java With Examples](https://beginnersbook.com/2013/12/java-arraylist/) - Arraylist class implements List interface and it is based on an Array data structure. It is widely used because of the functionality and flexibility it offers. ArrayList in Java, is a resizable-array implementation of the List interface. It implements all optional list operations and permits all elements, including null. Most of the developers choose Arraylist over - [Primary key in DBMS](https://beginnersbook.com/2015/04/primary-key-in-dbms/) - In this guide, you will learn about primary key in DBMS with the help of examples. We will discuss, what is a primary key, how it is different from other keys in DBMS such as foreign key and unique key. What is a Primary Key A primary key is a minimal set of attributes (columns) - [Java String substring() Method with examples](https://beginnersbook.com/2013/12/java-string-substring-method-example/) - The substring() method is used to get a substring from a given string. This is a built-in method of string class, it returns the substring based on the index values passed to this method. For example: "Beginnersbook".substring(9) would return "book" as a substring. This method has two variants, one is where you just specify the - [Java ArrayList add Method with Examples](https://beginnersbook.com/2013/12/java-arraylist-add-method-example/) - The add() method of Java ArrayList class is used to add elements to an ArrayList. In this guide, we will see various examples of add method. Syntax 1. To add element at the end of the list: public boolean add (E element) 2. To add elements at a specific position: public void add(int index, Object - [Java String startsWith() Method with examples](https://beginnersbook.com/2013/12/java-string-startswith-method-example/) - The startsWith() method of String class is used for checking prefix of a String. It returns a boolean value true or false based on whether the given string starts with the specified letter or word. For example: String str = "Hello"; //This will return true because string str starts with "He" str.startsWith("He"); Java String startsWith() - [Java String replace(), replaceFirst() and replaceAll() methods](https://beginnersbook.com/2013/12/java-string-replace-replacefirst-replaceall-method-examples/) - In this tutorial, we will discuss replace(), replaceFirst()and replaceAll() methods. All of these Java String methods are mainly used for replacing a part of String with another String. Java String replace method signature String replace(char oldChar, char newChar): It replaces all the occurrences of a oldChar character with newChar character. For e.g. "pog pance".replace('p', 'd') - [Java String compareTo() Method with examples](https://beginnersbook.com/2013/12/java-string-compareto-method-example/) - The Java String compareTo() method is used for comparing two strings lexicographically. Each character of both the strings is converted into a Unicode value for comparison. If both the strings are equal then this method returns 0 else it returns positive or negative value. The result is positive if the first string is lexicographically greater - [Recursion in C with Examples](https://beginnersbook.com/2022/09/recursion-in-c-with-examples/) - In this guide, you will learn recursion in C programming with the help of examples. A function that calls itself is known as recursive function and this process of calling itself is called recursion. Recursion Example 1: Fibonacci sequence In this example, we are displaying Fibonacci sequence using recursion. The Fibonacci Sequence is the series - [Java Program to Calculate Area and Circumference of Circle](https://beginnersbook.com/2014/01/java-program-to-calculate-area-and-circumference-of-circle/) - In this tutorial, you will learn how to calculate area and circumference of circle in Java. We will see two programs, in the first program, the radius value is initialized in the program and in the second program, the radius value is entered by the user. Formula for area and circumference of circle Area of - [Java program to reverse a number using for, while and recursion](https://beginnersbook.com/2014/01/java-program-to-reverse-a-number/) - In this tutorial, you will learn how to reverse a number in Java. For example if a given input number is 19 then the output of the program should be 91. There are several ways to reverse a number in Java. We will mainly discuss following three techniques to reverse a number. Table of contents - [Examples of throws Keyword in Java](https://beginnersbook.com/2013/12/throws-keyword-example-in-java/) - In this guide, we will see few examples of throws keyword. I highly recommend you to read my detailed guide on throws keyword before going through these examples so that you have a better understand of the this concept. Read these guides to learn exception handling from scratch: Exception handling in Java - complete guide - [Java Throws Keyword in Exception handling](https://beginnersbook.com/2013/04/java-throws/) - The throws keyword is used to handle checked exceptions. As we learned in the previous article that exceptions are of two types: checked and unchecked. Checked exception (compile time) needs to be handled else the program won't compile. On the other hand unchecked exception (Runtime) doesn't get checked during compilation. Throws keyword is used for - [C Program to Search Substring in a given String](https://beginnersbook.com/2022/09/c-program-to-search-substring-in-a-given-string/) - In this article, you will learn how to write a C program to search a substring in a given string. Program to check if substring is present in the given string or not Here we have a string represented by string array str[] and a substring represented by substr[]. Both of these strings are entered - [Types of User-defined Functions in C with Examples](https://beginnersbook.com/2022/09/types-of-user-defined-functions-in-c/) - In this tutorial, you will learn various types of user defined functions. We will see examples of how to pass arguments and call different variations of these functions. I highly recommend you to also read these articles on functions: Functions in C Programming User defined functions in C Type 1: When function doesn't have parameters - [User-defined function in C with Examples](https://beginnersbook.com/2022/09/user-defined-function-in-c-with-examples/) - In this guide, you will learn how to create user-defined function in C. A function is a set of statements that together perform a specific task. If you are new to this topic, I highly recommend you to read my complete guide on functions: Functions in C Programming. An example of function: You are frequently - [Program to Convert Feet to Inches in Java, C, C++, Python & PHP](https://beginnersbook.com/2022/09/program-to-convert-feet-to-inches-in-java-c-c-python-php/) - In this guide, we will see programs to convert length given in feet to inches in various programming languages such as Java, C, C++, Python, PHP. Feet and inches both are the unit of lengths. Formula to Convert Feet to Inches inches = 12 * feet Multiply the length given in feet by 12 to - [Program to Convert Kilometres (km) to Centimetres (cm)](https://beginnersbook.com/2022/09/program-to-convert-kilometres-km-to-centimetres-cm/) - In this guide, we will see programs to convert Kilometres to Centimetres in various programming languages such as Java, C, C++, Python, PHP. The kilometres and centimetres both are the unit of lengths. Formula to convert Kilometres to Centimetres cm = km * 100000 Multiply the km by 100000 to get the length in cm. - [Program to Convert Kilometres (km) to Centimetres (cm)](https://beginnersbook.com/2022/09/program-to-convert-kilometres-km-to-centimetres-cm/) - In this guide, we will see programs to convert Kilometres to Centimetres in various programming languages such as Java, C, C++, Python, PHP. The kilometres and centimetres both are the unit of lengths. Formula to convert Kilometres to Centimetres cm = km * 100000 Multiply the km by 100000 to get the length in cm. - [Program to Convert Inches to Feet](https://beginnersbook.com/2022/09/program-to-convert-inches-to-feet/) - In this guide, we will see programs to convert inches to feet in various programming languages such as Java, C, C++, Python, PHP. The inches and feet are the unit of lengths. Formula to convert Inches to Feet feet = inches / 12 Divide the value in inches by 12 to get the length in - [Program to Convert Inches to Centimetres](https://beginnersbook.com/2022/09/program-to-convert-inches-to-centimetres/) - In this tutorial, we will write programs in different programming languages to convert inches to centimetres. Inches and centimetres (cm) both are the unit of length. Inches to Centimetres Formula: cm = 2.54 * inches Multiply the value by 2.54. Java Program // Java program to convert Inches into cm public class JavaExample { public - [Flow control in try-catch-finally in Java](https://beginnersbook.com/2013/05/flow-in-try-catch-finally/) - In this guide, you will learn how to use try-catch along with finally block in Java. We will cover various examples to see, how try catch and finally works together during exception handling. Scenario 1: Exception doesn't occur in try block If exception doesn't occur in try block then all the catch blocks are ignored, - [Throw Keyword in Java with Examples](https://beginnersbook.com/2013/12/throw-keyword-example-in-java/) - The throw keyword is used to throw an exception in Java. In this guide, you will learn what is a throw keyword and how to use it in a java program. This article covers various examples to demonstrate the use of throw keyword. What is a throw keyword? In the exception handling guide, we learned - [C strcat() Function with example](https://beginnersbook.com/2017/11/c-strcat-function-with-example/) - The strcat() function is used for string concatenation. It concatenates the specified string at the end of the another specified string. In this tutorial, we will see the strcat() function with example. C strcat() Declaration char *strcat(char *str1, const char *str2) This function takes two pointer as arguments and returns the pointer to the destination - [C strncat() Function with example](https://beginnersbook.com/2017/11/c-strncat-function/) - In the last tutorial we discussed strcat() function, which is used for concatenation of one string to another string. In this guide, we will see a similar function strncat(), which is same as strcat() except that strncat() appends only the specified number of characters to the destination string. C strncat() Function Declaration char *strncat(char *str1, - [C strchr() Function with example](https://beginnersbook.com/2017/11/c-strchr-function/) - The function strchr() searches the occurrence of a specified character in the given string and returns the pointer to it. C strchr() Function char *strchr(const char *str, int ch) str - The string in which the character is searched. ch - The character that is searched in the string str. Return Value of strchr() It - [C strcmp() Function with example](https://beginnersbook.com/2017/11/c-strcmp-function/) - The strcmp() function compares two strings and returns an integer value based on the result. C strcmp() function declaration int strcmp(const char *str1, const char *str2) str1 - The first string str2 - The second string Return value of strcmp() This function returns the following values based on the comparison result: 0 if both the - [C strncmp() Function with example](https://beginnersbook.com/2017/11/c-strncmp-function/) - In the last tutorial we discussed strcmp() function which is used for comparing two strings. In this guide, we will discuss strncmp() function which is same as strcmp(), except that strncmp() comparison is limited to the number of characters specified during the function call. For example strncmp(str1, str2, 4) would compare only the first four - [C strcoll() Function - C tutorial](https://beginnersbook.com/2017/11/c-strcoll-function/) - The strcoll() function is similar to strcmp() function, it compares two strings and returns an integer number based on the result of comparison. C strcoll() declaration int strcoll(const char *str1, const char *str2) str1 - First String str2 - Second String Return value of strcoll() > 0 if the ASCII value of first unmatched character - [C strcpy() Function - C tutorial](https://beginnersbook.com/2017/11/c-strcpy-function/) - The strcpy() function copies one string to another string. C strcpy() function declaration char *strcpy(char *str1, const char *str2) str1 - This is the destination string where the value of other string str2 is copied. First argument in the function str2 - This is the source string, the value of this string is copied to - [C strncpy() Function – C tutorial](https://beginnersbook.com/2017/11/c-strncpy-function/) - The strncpy() function is similar to the strcpy() function, except that it copies only the specified number of characters from source string to destination string. C strncpy() declaration char *strncpy(char *str1, const char *str2, size_t n) str1 - Destination string. The string in which the first n characters of source string str2 are copied. str2 - [C strrchr() Function – C tutorial](https://beginnersbook.com/2017/11/c-strrchr-function/) - The strrchr() function searches the last occurrence of the specified character in the given string. This function works quite opposite to the function strchr() which searches the first occurrence of the character in the string. C strrchr() function declaration char *strrchr(const char *str, int ch) str - The string in which the character ch is - [C strspn() Function](https://beginnersbook.com/2017/11/c-strspn-function/) - The function strspn() searches specified string in the given string and returns the number of the characters that are matched in the given string. C strspn() declaration size_t strspn(const char *str1, const char *str2) str1 - The string in which the characters of string str2 are searched. str2 - Another string, the characters of this - [C strstr() Function – C tutorial](https://beginnersbook.com/2017/11/c-strstr-function/) - The strstr() function searches the given string in the specified main string and returns the pointer to the first occurrence of the given string. C strstr() function declaration char *strstr(const char *str, const char *searchString) str - The string to be searched. searchString - The string that we need to search in string str Return - [C strstr() Function – C tutorial](https://beginnersbook.com/2017/11/c-strstr-function/) - The strstr() function searches the given string in the specified main string and returns the pointer to the first occurrence of the given string. C strstr() function declaration char *strstr(const char *str, const char *searchString) str - The string to be searched. searchString - The string that we need to search in string str Return - [C strcspn() Function – C tutorial](https://beginnersbook.com/2017/11/c-strcspn-function/) - The strcspn() function scans the main string for the given string and returns the number of characters in the main string from beginning till the first matched character is found. C strcspn() declaration size_t strcspn(const char *str1, const char *str2) str1 - The main string to be searched str2 - The characters of this string - [C strcspn() Function – C tutorial](https://beginnersbook.com/2017/11/c-strcspn-function/) - The strcspn() function scans the main string for the given string and returns the number of characters in the main string from beginning till the first matched character is found. C strcspn() declaration size_t strcspn(const char *str1, const char *str2) str1 - The main string to be searched str2 - The characters of this string - [C strlen() Function – C tutorial](https://beginnersbook.com/2017/11/c-strlen-function/) - The function strlen() returns the length (number of characters) of the given string. Function strlen() Declaration size_t strlen(const char *str) str - This is the given string for which we need to compute the length Return value of strlen() This function returns the integer value representing the number of characters in the given string. C - [C strlen() Function – C tutorial](https://beginnersbook.com/2017/11/c-strlen-function/) - The function strlen() returns the length (number of characters) of the given string. Function strlen() Declaration size_t strlen(const char *str) str - This is the given string for which we need to compute the length Return value of strlen() This function returns the integer value representing the number of characters in the given string. C - [Java 8 - Calculate days between two dates](https://beginnersbook.com/2017/10/java-8-calculate-days-between-two-dates/) - We have already seen How to find the number of Days between two dates prior to Java 8. In this tutorial we will see how to calculate the number of days between two dates in Java 8. To calculate the days between two dates we can use the DAYS.between() method of java.time.temporal.ChronoUnit. Syntax of DAYS.between(): - [Java - Add days to Date](https://beginnersbook.com/2017/10/java-add-days-to-date/) - In this tutorial we will see how to add Days to the date in Java. Table of contents 1. Adding Days to the given Date using Calendar class 2. Adding Days to the current date using Calendar class 3. Add One day to a Date in Java 4. Add One day to the current date - [Java - Display time in 12 hour format with AM/PM using SimpleDateFormat](https://beginnersbook.com/2017/10/java-display-time-in-12-hour-format-with-ampm/) - In this tutorial we will see how to display time in 12 hour format with AM/PM using the SimpleDateFormat. 1. Display current date and time in 12 hour format with AM/PM There are two patterns that we can use in SimpleDateFormat to display time. Pattern "hh:mm aa" and "HH:mm aa", here HH is used for - [Java - Display current time in Milliseconds Format](https://beginnersbook.com/2017/10/java-time-in-milliseconds-format/) - Usually we display time in in 12 hour format hh:mm:aa format (e.g. 12:30 PM) or 24 hour format HH:mm (e.g. 13:30), however sometimes we also want to show the milliseconds in the time. To show the milliseconds in the time we include "SSS" in the pattern which displays the Milliseconds. Display Current Time in Milliseconds - [Java - Date Format to display the Day of the week](https://beginnersbook.com/2017/10/java-date-format-to-display-the-day-of-the-week/) - In this tutorial, we will see how to display the Day of the week in the date. By specifying a simple pattern, while formatting a date we can display the day of the week in short form or full name. Example: Display current Day of the Week In this example we are specifying the patterns - [Java LocalDate](https://beginnersbook.com/2017/10/java-localdate/) - Java LocalDate class is introduced in Java 8 in the java.time package. The instance of LocalDate class represents the date without the time zone info. In this guide, we will learn how to use LocalDate class and its methods. 1. LocalDate example to display the current date or any date Lets take a simple example - [Java - Convert Date to LocalDate](https://beginnersbook.com/2017/10/java-convert-date-to-localdate/) - In this tutorial, we will see how to convert Date to LocalDate. The java.util.Date represents date, time of the day in UTC timezone and java.time.LocalDate represents only the date, without time and timezone. java.util.Date - date + time of the day + UTC time zone java.time.LocalDate - only date Keeping these points in mind, we - [Java - Convert LocalDate to Date](https://beginnersbook.com/2017/10/java-convert-localdate-to-date/) - In this guide, we will see how to convert LocalDate to Date. Before we see the code for the conversion, lets see what's the difference between Date and LocalDate. java.util.Date - date + time + timezone java.time.LocalDate - only date So to convert the LocalDate to Date, we must append the time and timezone info - [Java LocalDate - adjustInto() method example](https://beginnersbook.com/2017/10/java-localdate-adjustinto/) - The method adjustInto(Temporal temporal) of LocalDate class makes the Temporal object to have the same date as this object. For example: Lets say we have two instances of LocalDate class date1 and date2. If we call the adjustInto() method like this date2.adjustInto(date1) then the value of date1 would be replaced by the value of date2. - [Java LocalDate – atStartOfDay() method example](https://beginnersbook.com/2017/10/java-localdate-atstartofday/) - The method atStartOfDay() appends the mid night time(the start of the day time) to the local date. There are two versions of this method. LocalDateTime atStartOfDay(): This method returns the LocalDateTime after appending the mid night time at the end of the LocalDate. ZonedDateTime atStartOfDay(ZoneId zone): This method returns the ZonedDateTime after appending the mid - [Java – Convert LocalDate to ZonedDateTime](https://beginnersbook.com/2017/10/java-convert-localdate-to-zoneddatetime/) - In this tutorial, we will see how to convert LocalDate to ZonedDateTime. LocalDate represents the date without time and zone information, ZonedDateTime represents the date with time and zone. To convert the LocalDate to ZonedDateTime, we must add the time and zone id with the local date. Example 1: Converting the LocalDate given in String - [Java LocalDate – compareTo() method example](https://beginnersbook.com/2017/10/java-localdate-compareto-method-example/) - The method compareTo() compares two dates and returns an integer value based on the comparison. Method Signature: public int compareTo(ChronoLocalDate otherDate) It returns 0 if both the dates are equal. It returns positive value if "this date" is greater than the otherDate. It returns negative value if "this date" is less than the otherDate. LocalDate - [Java LocalDate – equals() method example](https://beginnersbook.com/2017/10/java-localdate-equals/) - The equals() method compares two dates with each other and returns boolean value, true and false based on the comparison. We can also use compareTo() method for the same purpose, however compareTo() returns int value instead of boolean value. Method Signature: boolean equals(Object obj) Checks if this date is equal to another date. It returns - [Java LocalTime](https://beginnersbook.com/2017/10/java-localtime/) - The class LocalTime represents the time without time zone information such as 11:20:45. LocalTime can be used to represent time upto nanosecond precision. For example, 15:40.25.123456789 can be represented by an instance of LocalTime. This class is immutable and thread-safe. Java LocalTime class public final class LocalTime extends Object implements Temporal, TemporalAdjuster, Comparable, Serializable Java - [Java Date and Time](https://beginnersbook.com/2017/10/java-date-time/) - In the past, I have shared several tutorials and guides on Java Date and time. In this post, I will share the link of all those articles. Java 8 Date Time API - Guides and Tutorials Java 8 introduces whole new API in the java.time package. There are tons of useful classes in this package - [Java LocalDateTime](https://beginnersbook.com/2017/10/java-localdatetime/) - Java LocalDateTime class is an immutable class that represents the date and time without the timezone information, such as 2017-10-25T11:20:55. In this guide we will see the methods of LocalDateTime class and will see few java programs of various methods of LocalDateTIme class to understand how to use this class. Java LocalDateTime class: public final - [Java DateTimeFormatter](https://beginnersbook.com/2017/11/java-datetimeformatter/) - The DateTimeFormatter class in Java is used for parsing dates in different formats. You can use this class to format date in a specified format or you can use the predefined instances of DateTimeFormatter class. 1. Java - DateTimeFormatter to format the date in specified format In this example, we are formatting the current date - [Java 8 - Adding Days to the LocalDate](https://beginnersbook.com/2017/11/java-8-adding-days-to-the-localdate/) - In this tutorial we will see how to add days to the LocalDate. Java LocalDate Example 1: Adding Days to the current Date In this example, we are adding one day to the current date. We are using now() method of LocalDate class to get the current date and then using the plusDays() method to - [Java 8 Stream - anyMatch() example](https://beginnersbook.com/2017/11/java-8-stream-anymatch-example/) - In this tutorial we will see the example of Java 8 Stream anyMatch() method. This method returns true if any elements of the Stream matches the given predicate. Lets see an example to understand the use of anyMatch() method. Example: Java 8 Stream anyMatch() method import java.util.List; import java.util.function.Predicate; import java.util.ArrayList; class Student{ int stuId; - [Java 8 Stream – noneMatch() example](https://beginnersbook.com/2017/11/java-8-stream-nonematch-example/) - In the last tutorial we discussed java stream anyMatch() method. The stream noneMatch() method works just opposite to the anyMatch() method, it returns true if none of the stream elements match the given predicate, it returns false if any of the stream elements matches the condition specified by the predicate. Java Stream noneMatch() example import - [Java 8 Stream – allMatch() example](https://beginnersbook.com/2017/11/java-8-stream-allmatch-example/) - In the last tutorials we have seen the anyMatch() and noneMatch() methods. In this guide, we will discuss stream allMatch() method, which returns true if all the elements of stream satisfy the given predicate, else it returns false. Example: Stream allMatch() In this example we have a stream of student details that consists student id, - [jshell: Command Not Found on Mac OS X](https://beginnersbook.com/2018/04/jshell-command-not-found-on-mac-os-x/) - If you are trying to access jshell on Mac OS X and getting the following error(jshell: command not found) that means you have to configure the $JAVA_HOME/bin in your bash_profile. Note: To start jshell you must have java 9 installed on your system. This feature is added in java9 version. How to set JAVA_HOME path - [Java 9 Features with Examples](https://beginnersbook.com/2018/04/java-9-features-with-examples/) - Java 9 released on 21st September 2017. It is released with several new cool features. I will try to cover all the features in separate tutorials and provide the links to all those tutorials here. 1. JShell 2. JPMS (Java Platform Module System) 3. JLink (Java Linker) 4. Http/2 client 5. Process API updates 6. - [Java 9 JShell (Java Shell) - REPL](https://beginnersbook.com/2018/04/java-9-jshell-repl/) - JShell stands for java shell. It is also known as REPL (Read Evaluate Print Loop). The purpose of this tool is to provide a easy way to learn Java, but how? Lets look into it. We are aware that we have to write several lines of code to print something on screen, for example - - [java 9 JShell - Working with variables](https://beginnersbook.com/2018/04/java-9-jshell-variables/) - In the last tutorial we learned about JShell, the newly introduced feature of java 9. In this guide, we will see how to work with variables in JShell. JShell - Scratch variable When we do not assign the result of an expression to variable, a scratch variable is created so that the output of expression - [java 9 JShell – Working with Methods](https://beginnersbook.com/2018/04/java-9-jshell-methods/) - In the previous tutorial we learned how to work with variables in JShell. In this guide, we will learn how to create methods in JShell, how to use them and how to modify the definition of already defined method. JShell - Methods Lets see how to define a method in JShell. In the following example, - [Java 9 - Factory method to create Immutable List](https://beginnersbook.com/2018/04/java-9-factory-method-to-create-immutable-list/) - There are couple of useful factory methods introduced in Java 9 to create immutable (unmodifiable) lists. 1. Creating immutable list prior to Java 9 Before we see the factory methods that are introduced in Java 9. Lets see how we used to create immutable lists prior to Java 9. 1.1 Creating empty immutable list before - [Java 9 – Factory methods to create Immutable Set](https://beginnersbook.com/2018/04/java-9-factory-methods-to-create-immutable-set/) - In the last tutorial, we learned how to create immutable lists with ease using the factory methods introduced in Java 9. In this guide, we will see the use of newly introduced factory methods to create immutable Sets. 1. Creating immutable Set prior to Java 9 Before we discuss how to use the factory methods - [Java 9 – Factory methods to create Immutable Map](https://beginnersbook.com/2018/04/java-9-factory-methods-to-create-immutable-map/) - In the previous tutorials we learned about the factory methods introduced in Java 9 to create immutable List and immutable Set. In this guide, we will learn how to create immutable Map and Map.Entry by using Java 9 Factory methods. 1. Creating Immutable Map prior to Java 9 Before we see how to create immutable - [Java 9 - Private methods in Interfaces (with examples)](https://beginnersbook.com/2018/05/java-9-private-methods-in-interfaces-with-examples/) - As we know that Java 8 allowed us to create default and static methods in Interface. The intention was to have new methods added to the interfaces without breaking the classes that already implemented those interfaces. Java 9 has introduced another new feature, Java 9 SE onwards we can have private methods in interfaces. In - [Java 9 - Anonymous Inner classes and Diamond Operator](https://beginnersbook.com/2018/05/java-9-anonymous-inner-classes-and-diamond-operator/) - In this post, we will discuss the diamond operator enhancement introduced in Java SE 9. What is a diamond operator? Diamond operator was introduced as a new feature in java SE 7. The purpose of diamond operator is to avoid redundant code by leaving the generic type in the right side of the expression. // This - [Java 9 - @SafeVarargs Annotation (with examples)](https://beginnersbook.com/2018/05/java-9-safevarargs-annotation/) - Java 7 introduced the @SafeVarargs annotation to suppress the unsafe operation warnings that arises when a method is having varargs (variable number of arguments). The @SafeVarargs annotation can only be used with methods (final or static methods or constructors) that cannot be overriden because an overriding method can still perform unsafe operation on their varargs - [Java 9 - Stream API Enhancements (With Examples)](https://beginnersbook.com/2018/06/java-9-stream-api-enhancements/) - We have already learned that Java 8 introduced the Stream API along with several other cool features. If you are not familiar with Streams then refer this guide: Java 8 - Stream API. Java 9 introduced four new methods for Stream API. These methods are added in java.util.Stream interface. Java 9 - Stream API Improvements - [Learn Java 9 Modules in 15 Minutes](https://beginnersbook.com/2018/09/java-9-modules/) - In this article we will learn the most important feature of Java 9 - "Java 9 Modules". We will cover everything like why we need modules, what is a module, how to create and use Modules in Java. Lets get started. Little background on Modules Java Module System is a long overdue feature of Java. - [Java 8 Stream Min and Max](https://beginnersbook.com/2019/02/java-8-stream-min-and-max/) - In this tutorial, we will learn how to find out the min and max value from a stream of comparable elements such as characters, strings, dates etc. We use the min() and max() methods to find the min & max value in streams. These methods are used for finding min & max values in different - [Java Convert int to long with examples](https://beginnersbook.com/2019/04/java-int-to-long-conversion/) - In this tutorial, we will see how to convert int to long with examples. Since int is smaller data type than long, it can be converted to long with a simple assignment. This is known as implicit type casting or type promotion, compiler automatically converts smaller data type to larger data type. We can also - [Java Convert long to int with examples](https://beginnersbook.com/2019/04/java-long-to-int-conversion/) - In this guide, we will see how to convert long to int with examples. Since long is larger data type than int, we need to explicitly perform type casting for the conversion. Java long to int example In the following example we are converting long data type to int data type using explicit typecasting. Here - [Java Convert char to String with examples](https://beginnersbook.com/2019/04/java-char-to-string-conversion/) - In this tutorial, we will see how to convert a char to string with the help of examples. There are two ways you can do char to String conversion - 1. Using String.valueOf(char ch) method 2. Using Character.toString(char ch) method Java char to String example using String.valueOf(char ch) We can use the valueOf(char ch) method - [Java Convert char to int with examples](https://beginnersbook.com/2019/04/java-char-to-int-conversion/) - In this tutorial, we will see how to convert a char to int with the help of examples. Converting a character to an integer is equivalent to finding the ASCII value (which is an integer) of the given character. Java char to int - implicit type casting Since char is a smaller data type compared - [Java int to char conversion with examples](https://beginnersbook.com/2019/04/java-int-to-char-conversion/) - In the last tutorial, we have discussed char to int conversion. In this guide, we will see how to convert an int to a char with the help of examples. Java int to char conversion example To convert a higher data type to lower data type, we need to do typecasting. Since int is higher - [Java String to boolean Conversion with examples](https://beginnersbook.com/2019/04/java-string-to-boolean-conversion/) - In this guide, we will see how to convert a String to a boolean with the help of examples. When converting a String to a boolean value, if the string contains the value "true" (case doesn't matter) then the boolean value after the conversion would be true, if the string contains any other value other - [Java Binary to Octal Conversion with examples](https://beginnersbook.com/2019/04/java-binary-to-octal-conversion/) - In this tutorial, we will see how to convert a binary number to an octal number with the help of examples. Java binary to octal conversion example To convert a binary number to octal number, we can use the Integer.toOctalString() method, which takes binary number as an argument and returns a string which is the - [Java Octal to Decimal Conversion with examples](https://beginnersbook.com/2019/04/java-octal-to-decimal-conversion/) - In this article, we will see how to convert Octal to Decimal in Java with the help of examples. There are two ways we can convert an octal value to an equivalent decimal value: 1. Using Integer.parseInt() method and passing the base as 8. 2. Writing our own custom method (logic) to convert octal to - [Java main() method explained with examples](https://beginnersbook.com/2021/08/java-main-method-explained-with-examples/) - In this article, we will learn Java main() method in detail. As the name suggest this is the main point of the program, without the main() method the program won't execute. What is a main() method in Java? The main() method is the starting point of the program. JVM starts the execution of program starting - [System.out.println() in Java explained with examples](https://beginnersbook.com/2021/08/system-out-println-in-java-explained-with-examples/) - In java, we use System.out.println() statement to display a message, string or data on the screen. It displays the argument that we pass to it. Let's understand each part of this statement: System: It is a final class defined in the java.lang package.out: It is an instance of PrintStream type and its access specifiers are public - [How to Call a Method in Java](https://beginnersbook.com/2022/05/how-to-call-a-method-in-java/) - In this article, we will learn how to call a method in Java. A method is a set of instructions, created to perform a specific task. Instead of writing the same set of instructions again and again, we simply create a method in java that has those instructions inside the method body and this method - [Java MonthDay Class explained with examples](https://beginnersbook.com/2022/06/java-monthday-class-explained-with-examples/) - The MonthDay class represents the date as the combination of Month and Day such as --11-25. This class only represents the Month and day, it doesn't represents the year, time or time-zone. Java MonthDay class: public final class MonthDay extends Object implements TemporalAccessor, TemporalAdjuster, Comparable, Serializable Java MonthDay class - Method Summary Java MonthDay class - [Java OffsetTime Class explained with examples](https://beginnersbook.com/2022/06/java-offsettime-class-explained-with-examples/) - Java OffsetTime class represents time with an offset from UTC timezone such as 11:23:45+02:00. The time represented by an instance of this class is often viewed as hour-minute-second-offset, however this class can store time upto the precision of nanoseconds. For example a time value "13:45.30.123456789+02:00" can be stored as OffsetTime. Java OffsetTime class: public final - [Java OffsetDateTime Class explained with examples](https://beginnersbook.com/2022/06/java-offsetdatetime-class-explained-with-examples/) - OffsetDateTime represents the date-time with an offset from UTC time such as 2022-06-12T11:25:45+02:00. This class stores date-time with all date & time fields upto precision of nanoseconds, as well as offset from UTC timezone. For example, the value "12th June 2022 at 10:33.49.123456789 +01:00" can be stored in an OffsetDateTime. Java OffsetDateTime class: public final - [Java Clock class explained with examples](https://beginnersbook.com/2022/06/java-clock-class-explained-with-examples/) - Java Clock class gives you access to obtain current date-time using a time-zone. Use of Clock class is not mandatory as all date-time classes have now() method which is used to get current date-time information from system in default time-zone. The main purpose of Clock class is to allow access to an alternate clock which - [Java ZoneId class explained with examples](https://beginnersbook.com/2022/06/java-zoneid-class-explained-with-examples/) - ZoneId class in java represents time-zone such as 'Asia/Kolkata'. There are two main types of Zone Ids: ZoneOffset Ids that consists of 'Z' and start with '+' or '-'. The other type of Ids are offset style Ids such as 'GMT+2' or 'UTC+01:00'. ZoneId class provides a way to convert between Instant and LocalDateTime. java - [Java ZoneOffset class explained with examples](https://beginnersbook.com/2022/06/java-zoneoffset-class-explained-with-examples/) - Java ZoneOffset class allows us to manage time-zones effectively. Each country follows a certain timezone on top of that there is a day-light saving concept that comes into picture. To manage time-zones effectively and correctly, ZoneOffset provides multiple useful methods. ZoneOffset represents the amount of time that a timezone differs from Greenwich/UTC, this is usually - [JDK vs JRE vs JVM: Difference between them](https://beginnersbook.com/2022/06/jdk-vs-jre-vs-jvm-difference-between-them/) - In this tutorial, you will learn the difference between JDK, JRE and JVM. JDK (Java Development Kit) JDK is a superset of JRE, it contains everything that JRE has along with development tools such as compiler, debugger etc. JDK stands for Java Development Kit. To install Java on your system, you need to first install - [How to make an ArrayList read only in Java](https://beginnersbook.com/2022/08/how-to-make-an-arraylist-read-only-in-java/) - A read only ArrayList means that no modification operations is allowed to be performed on ArrayList. This list cannot be modified by adding, removing or updating any element in the ArrayList. This is to prevent any modification be done to the ArrayList. The only operations that are allowed to be performed on read only ArrayList - [Difference between length of Array and size of ArrayList in Java](https://beginnersbook.com/2022/08/difference-between-length-of-array-and-size-of-arraylist-in-java/) - In this tutorial, you will learn the difference between length of Array and size of ArrayList in Java.. Length of Array: // creating an array arr[] to hold 25 elements String arr[] = new String[25]; To find the number of elements in an array, we use length property. This is how we find number of - [Difference between Array and ArrayList](https://beginnersbook.com/2022/08/difference-between-array-and-arraylist/) - In this guide, we will discuss the difference between Array and ArrayList. What is an Array? An array is a collection of elements of similar type, stored in contiguous memory locations. It is one of the simplest data structure where you can access each element of the array by only using its index number. For - [Perform Binary Search on ArrayList in Java](https://beginnersbook.com/2022/08/perform-binary-search-on-arraylist-in-java/) - In this tutorial, you will learn how to perform binary search on ArrayList in Java. 1. Perform binary search on ArrayList using Collections.binarySearch() In this example, we are performing binary search on the given ArrayList arrList. This list is unsorted, however in order to perform binary search the list must be sorted. Before performing binary - [Perform Binary Search on ArrayList in Java](https://beginnersbook.com/2022/08/perform-binary-search-on-arraylist-in-java/) - In this tutorial, you will learn how to perform binary search on ArrayList in Java. 1. Perform binary search on ArrayList using Collections.binarySearch() In this example, we are performing binary search on the given ArrayList arrList. This list is unsorted, however in order to perform binary search the list must be sorted. Before performing binary - [How to Increase the capacity of ArrayList](https://beginnersbook.com/2022/08/how-to-increase-the-capacity-of-arraylist/) - When we create an ArrayList in Java, it is created with a default capacity of 10. However an ArrayList can be automatically resized if more elements are added than the initial capacity of ArrayList. This is useful, as you do not need to worry about the size of ArrayList. However if you are sure about - [When to use ArrayList and LinkedList in Java](https://beginnersbook.com/2022/08/when-to-use-arraylist-and-linkedlist-in-java/) - In this guide, we will discuss, when to use ArrayList and when to use LinkedList in Java. There are multiple similarities between these classes. However there is a significant difference between ArrayList and LinkedList, when we talk about the performance of various operations such as add, update, delete, search etc. When to use ArrayList and - [Java Scanner class with examples](https://beginnersbook.com/2022/08/java-scanner-class-with-examples/) - In this tutorial, you will learn Java Scanner class and how to use it in java programs to get the user input. This is one of the important classes as it provides you various methods to capture different types of user entered data. In this guide, we will discuss java Scanner class methods as well - [Java Scanner class with examples](https://beginnersbook.com/2022/08/java-scanner-class-with-examples/) - In this tutorial, you will learn Java Scanner class and how to use it in java programs to get the user input. This is one of the important classes as it provides you various methods to capture different types of user entered data. In this guide, we will discuss java Scanner class methods as well - [Method Overloading "Reference is Ambiguous" error in Java](https://beginnersbook.com/2022/08/method-overloading-ambiguity-java/) - When working with method overloading, sometimes we encounter compile time error "reference is ambiguous". This error usually occurs when we pass null value while calling overloaded methods. In this guide, we will see few examples to see when this error occurs and how to avoid it. Prerequisite: Method Overloading in Java Method Overloading reference is - [Java Varargs explained with examples](https://beginnersbook.com/2022/08/java-varargs-explained-with-examples/) - Varargs is a term used for variable arguments. In this guide, you will learn what is varargs, how to use it in Java and various examples to understand this concept in detail. What is varargs? Varargs is used when you are not sure how many arguments a method can accept. For example, let say you - [Ambiguity error while overloading Method with Varargs parameter](https://beginnersbook.com/2022/08/ambiguity-method-overloading-varargs-java/) - Sometimes while overloading a method with varargs parameter, we get ambiguous error. In this guide, you will learn when and why we get this error and how to avoid this error. Ambiguity in Varargs in Java while method overloading In the following example, we have are doing method overloading. There are two variants of method - [Passing a List to a Varargs method](https://beginnersbook.com/2022/08/passing-a-list-to-a-varargs-method/) - In this guide, you will learn how to pass a list as an argument to a method with Varargs. As we learned in the Java Varargs detailed guide, that varargs can accept variable arguments. Here, we will see how a list elements can be passed as arguments to a method. Passing a List elements to - [Method Overloading with Autoboxing and Widening in Java](https://beginnersbook.com/2022/08/method-overloading-with-autoboxing-and-widening-in-java/) - In this article, you will learn how Auto-Boxing and Auto-Widening works in method overloading in Java. Auto-boxing: Automatic conversion of primitive data types to the object of their corresponding wrapper classes is known as auto-boxing. For example: conversion from int to Integer, long to Long, double to Double etc. are example of auto-boxing. Widening: When - [Can Static Methods be Overloaded or Overridden in Java?](https://beginnersbook.com/2022/08/can-static-methods-be-overloaded-or-overridden-in-java/) - In this guide, we will discuss whether we can overload or override a static method in Java. Prerequisites: To understand this article, you should have the basic knowledge of following topics. Method Overloading in Java Method Overriding in Java Static Methods in Java Can we overload a static method? Short answer is 'Yes'. We can overload - [Java - Get the index of last occurrence of an element in LinkedList](https://beginnersbook.com/2014/08/java-get-the-index-of-last-occurrence-of-an-element-in-linkedlist/) - Description Program to find out the index of last occurrence of an element in LinkedList. Program import java.util.LinkedList; class LinkedListExample { public static void main(String[] args) { // create a LinkedList LinkedList list = new LinkedList(); // Add elements list.add("AA"); list.add("BB"); list.add("CC"); list.add("AA"); list.add("DD"); list.add("AA"); list.add("EE"); // Display LinkedList elements System.out.println("LinkedList elements: "+list); // get - [Adding element to front of LinkedList in Java](https://beginnersbook.com/2014/08/adding-element-to-front-of-linkedlist-in-java/) - Description Program to add element to front(head) of LinkedList. Program import java.util.LinkedList; class LinkedListExample { public static void main(String[] args) { // create a LinkedList LinkedList list = new LinkedList(); // Add elements list.add("AA"); list.add("BB"); list.add("CC"); list.add("DD"); // Display List element System.out.println("LinkedList Elements:"+list); // Adding element to front of LinkedList /* public boolean offerFirst(E e): - [LinkedList push() and pop() methods - Java](https://beginnersbook.com/2014/08/linkedlist-push-and-pop-methods-java/) - Description Programs to demonstrate push and pop operations on LinkedList. LinkedList.push(E e) public void push(E e): Inserts the element at the front of the list. Example: import java.util.LinkedList; class LinkedListExample { public static void main(String[] args) { // Create a LinkedList of Strings LinkedList list = new LinkedList(); // Add few Elements list.add("Jack"); list.add("Robert"); list.add("Chaitanya"); - [Java - LinkedList poll(), pollFirst() and pollLast() methods](https://beginnersbook.com/2014/08/java-linkedlist-poll-pollfirst-and-polllast-methods/) - Description Example Programs for poll(), pollFirst() and pollLast() methods of LinkedList class. LinkedList.poll() Retrieves and removes the head (first element) of this list. import java.util.LinkedList; class LinkedListPollMethod{ public static void main(String[] args) { // Create a LinkedList of Strings LinkedList list = new LinkedList(); // Add few Elements list.add("Element1"); list.add("Element2"); list.add("Element3"); list.add("Element4"); // Display LinkList - [Java – LinkedList peek(), peekFirst() and peekLast() methods](https://beginnersbook.com/2014/08/java-linkedlist-peek-peekfirst-and-peeklast-methods/) - Description public E peek(): Retrieves, but does not remove, the head (first element) of this list. public E peekFirst(): Retrieves, but does not remove, the first element of this list, or returns null if this list is empty. public E peekLast(): Retrieves, but does not remove, the last element of this list, or returns null - [Clone a HashMap in Java](https://beginnersbook.com/2014/08/clone-a-hashmap-in-java/) - Description A program to clone a HashMap. We will be using following method of HashMap class to perform cloning. public Object clone(): Returns a shallow copy of this HashMap instance: the keys and values themselves are not cloned. Example import java.util.HashMap; class HashMapExample{ public static void main(String args[]) { // Create a HashMap HashMap - [How to check if a HashMap is empty or not?](https://beginnersbook.com/2014/08/how-to-check-if-a-hashmap-is-empty-or-not/) - Description Program to check if a HashMap is empty or not. We are using isEmpty() method of HashMap class to perform this check. Program import java.util.HashMap; class HashMapIsEmptyExample{ public static void main(String args[]) { // Create a HashMap HashMap hmap = new HashMap(); // Checking whether HashMap is empty or not /* isEmpty() - [Java - Get Set view of Keys from HashMap](https://beginnersbook.com/2014/08/java-get-set-view-of-keys-from-hashmap/) - Description Program to get the Set of keys from HashMap. Example import java.util.Iterator; import java.util.HashMap; import java.util.Set; class HashMapExample{ public static void main(String args[]) { // Create a HashMap HashMap hmap = new HashMap(); // Adding few elements hmap.put("Key1", "Jack"); hmap.put("Key2", "Rock"); hmap.put("Key3", "Rick"); hmap.put("Key4", "Smith"); hmap.put("Key5", "Will"); // Getting Set of HashMap - [Difference between StringBuilder and StringBuffer](https://beginnersbook.com/2014/08/stringbuilder-vs-stringbuffer/) - In this article we are gonna discuss the differences between StringBuilder and StringBuffer. Before discussing the differences, lets have a look at what java documentation says about these classes: StringBuffer javadoc: A thread-safe, mutable sequence of characters. A string buffer is like a String, but can be modified. At any point in time it contains - [How to Iterate over a Set/HashSet](https://beginnersbook.com/2014/08/how-to-iterate-over-a-sethashset/) - There are following two ways to iterate through HashSet: 1) Using Iterator 2) Without using Iterator Example 1: Using Iterator import java.util.HashSet; import java.util.Iterator; class IterateHashSet{ public static void main(String[] args) { // Create a HashSet HashSet hset = new HashSet(); //add elements to HashSet hset.add("Chaitanya"); hset.add("Rahul"); hset.add("Tim"); hset.add("Rick"); hset.add("Harry"); Iterator it = hset.iterator(); while(it.hasNext()){ - [How to copy one Set to another Set](https://beginnersbook.com/2014/08/how-to-copy-one-set-to-another-set/) - In this article we are gonna see an example program to copy one Set to another Set. Example In this example we are copying one HashSet to another HashSet, however you can use any other Set like TreeSet, LinkedHashSet etc in the same manner as shown below. import java.util.HashSet; class CopySetExample{ public static void main(String[] - [Delete all the elements from HashSet](https://beginnersbook.com/2014/08/delete-all-the-elements-from-hashset/) - Here we are gonna see how to remove all the elements of HashSet in one go. We can do so by calling clear() method of HashSet class. Example import java.util.HashSet; class EmptyHashSetExample{ public static void main(String[] args) { // Create a HashSet HashSet hset = new HashSet(); //add elements to HashSet hset.add("Element1"); hset.add("Element2"); hset.add("Element3"); hset.add("Element4"); - [Convert HashSet to a List/ArrayList](https://beginnersbook.com/2014/08/convert-hashset-to-a-list-arraylist/) - In this tutorial we will be learning how to convert a HashSet to a List (ArrayList). Program Here we have a HashSet of String elements and we are creating an ArrayList of Strings by copying all the elements of HashSet to ArrayList. Following is the complete code: import java.util.HashSet; import java.util.List; import java.util.ArrayList; class ConvertHashSetToArrayList{ - [Converting a HashSet to an Array](https://beginnersbook.com/2014/08/converting-a-hashset-to-an-array/) - Here is the program for converting a HashSet to an array. Program import java.util.HashSet; class ConvertHashSettoArray{ public static void main(String[] args) { // Create a HashSet HashSet hset = new HashSet(); //add elements to HashSet hset.add("Element1"); hset.add("Element2"); hset.add("Element3"); hset.add("Element4"); // Displaying HashSet elements System.out.println("HashSet contains: "+ hset); // Creating an Array String[] array = new - [How to convert a HashSet to a TreeSet](https://beginnersbook.com/2014/08/how-to-convert-a-hashset-to-a-treeset/) - Description Program to convert a HashSet to a TreeSet Program Here is the complete code for HashSet to TreeSet conversion. We have a HashSet of Strings and we are creating a TreeSet of strings by copying all the elements of HashSet to TreeSet. import java.util.HashSet; import java.util.TreeSet; import java.util.Set; class ConvertHashSettoTreeSet{ public static void main(String[] - [Difference between HashSet and TreeSet](https://beginnersbook.com/2014/08/difference-between-hashset-and-treeset/) - In this article we are gonna discuss the differences between HashSet and TreeSet. HashSet vs TreeSet 1) HashSet gives better performance (faster) than TreeSet for the operations like add, remove, contains, size etc. HashSet offers constant time cost while TreeSet offers log(n) time cost for such operations. 2) HashSet does not maintain any order of - [Difference between HashSet and HashMap](https://beginnersbook.com/2014/08/hashset-vs-hashmap-java/) - In this article we are gonna discuss the differences between HashSet and HashMap classes. HashSet vs HashMap Differences: HashSet HashMap HashSet class implements the Set interface HashMap class implements the Map interface In HashSet we store objects(elements or values) e.g. If we have a HashSet of string elements then it could depict a set of - [HashMap - Get value from key example](https://beginnersbook.com/2014/08/hashmap-get-value-from-key-example/) - Description Program to get value from HashMap when the key is provided. Example import java.util.HashMap; class HashMapDemo{ public static void main(String[] args) { // Create a HashMap HashMap hmap = new HashMap(); //add elements to HashMap hmap.put(1, "AA"); hmap.put(2, "BB"); hmap.put(3, "CC"); hmap.put(4, "DD"); // Getting values from HashMap String val=hmap.get(4); System.out.println("The Value - [how to copy one hashmap content to another hashmap](https://beginnersbook.com/2014/08/how-to-copy-one-hashmap-content-to-another-hashmap/) - In this tutorial we are gonna learn how to copy one HashMap elements to another HashMap. We will be using putAll() method of HashMap class to perform this operation. Complete code as follows: import java.util.HashMap; class HashMapDemo{ public static void main(String[] args) { // Create a HashMap HashMap hmap = new HashMap(); //add - [Java Regular Expressions (java regex) Tutorial with examples](https://beginnersbook.com/2014/08/java-regex-tutorial/) - Regular expressions are used for defining String patterns that can be used for searching, manipulating and editing a text. These expressions are also known as Regex (short form of Regular expressions). Lets take an example to understand it better: In the below example, the regular expression .*book.* is used for searching the occurrence of string - [Java Enum Tutorial with examples](https://beginnersbook.com/2014/09/java-enum-examples/) - An enum is a special type of data type which is basically a collection (set) of constants. In this tutorial we will learn how to use enums in Java and what are the possible scenarios where we can use them. This is how we define Enum public enum Directions{ EAST, WEST, NORTH, SOUTH } Here - [Java Annotations tutorial with examples](https://beginnersbook.com/2014/09/java-annotations/) - Java Annotations allow us to add metadata information into our source code, although they are not a part of the program itself. Annotations were added to the java from JDK 5. Annotation has no direct effect on the operation of the code they annotate (i.e. it does not affect the execution of the program). In - [Java Autoboxing and Unboxing with examples](https://beginnersbook.com/2014/09/java-autoboxing-and-unboxing-with-examples/) - Java 1.5 introduced a special feature of auto conversion of primitive types to the corresponding Wrapper class and vice versa. Autoboxing: Automatic conversion of primitive types to the object of their corresponding wrapper classes is known as autoboxing. For example - conversion of int to Integer, long to Long, double to Double etc. Unboxing: It - [How to get the last element of Arraylist?](https://beginnersbook.com/2014/10/how-to-get-the-last-element-of-arraylist/) - There are times when we need to get the last element of an ArrayList, this gets difficult when we don't know the last index of the list. In this tutorial we are going to see an example to get the last element from ArrayList. Example: Getting the last element from List import java.util.ArrayList; import java.util.List; - [How to remove duplicates from ArrayList in Java](https://beginnersbook.com/2014/10/how-to-remove-repeated-elements-from-arraylist/) - In this tutorial, you will learn how to remove duplicates from ArrayList. Example 1: Removing duplicates from ArrayList using LinkedHashSet In the following example, we are removing the duplicate elements from ArrayList using LinkedHashSet. The steps followed in the program are: 1) Copying all the elements of ArrayList to LinkedHashSet. Why we choose LinkedHashSet? Because - [Difference between list set and map in java?](https://beginnersbook.com/2015/01/difference-between-list-set-and-map-in-java/) - List, Set and Map are the interfaces which implements Collection interface. Here we will discuss difference between List Set and Map in Java. List Vs Set Vs Map 1) Duplicity: List allows duplicate elements. Any number of duplicate elements can be inserted into the list without affecting the same existing values and their indexes. Set - [How to check if a File is hidden in Java](https://beginnersbook.com/2015/01/how-to-check-if-a-file-is-hidden-in-java/) - In this tutorial we would learn how to write a program to check whether a particular file is hidden or not. We would be using isHidden() method of File class to perform this check. This method returns a boolean value (true or false), if file is hidden then this method returns true otherwise it returns - [Cloneable Interface in Java - Object Cloning](https://beginnersbook.com/2015/01/cloneable-interface-in-java-object-cloning/) - In this post we are going to discuss about Object cloning with the help of examples. As the name suggests, object cloning is a process of generating the exact copy of object with the different name. Lets see how this can be done. A Simple example to understand Object cloning public class DogName implements Cloneable - [What is the difference between a process and a thread in Java?](https://beginnersbook.com/2015/01/what-is-the-difference-between-a-process-and-a-thread-in-java/) - This is the most frequently asked question during interviews. In this post we will discuss the differences between thread and process. You must have heard these terms while reading multithreading in java, both of these terms are related to each other. Both processes and threads are independent sequences of execution. The main difference is that - [Daemon thread in Java with example](https://beginnersbook.com/2015/01/daemon-thread-in-java-with-example/) - Daemon thread is a low priority thread (in context of JVM) that runs in background to perform tasks such as garbage collection (gc) etc., they do not prevent the JVM from exiting (even if the daemon thread itself is running) when all the user threads (non-daemon threads) finish their execution. JVM terminates itself when all - [For loop in Java with example](https://beginnersbook.com/2015/03/for-loop-in-java-with-example/) - For loop is used to execute a set of statements repeatedly until a particular condition returns false. In Java we have three types of basic loops: for, while and do-while. In this tutorial you will learn about for loop in Java. You will also learn nested for loop, enhanced for loop and infinite for loop - [While loop in Java with examples](https://beginnersbook.com/2015/03/while-loop-in-java-with-examples/) - In this tutorial, you will learn while loop in java with the help of examples. Similar to for loop, the while loop is used to execute a set of statements repeatedly until the specified condition returns false. Syntax of while loop while(condition) { statement(s); //block of code } The block of code inside the body - [do-while loop in Java with example](https://beginnersbook.com/2015/03/do-while-loop-in-java-with-example/) - In the last tutorial, we discussed while loop. In this tutorial we will discuss do-while loop in java. do-while loop is similar to while loop, however there is a difference between them: In while loop, condition is evaluated before the execution of loop’s body but in do-while loop condition is evaluated after the execution of - [Thread join() method in Java with example](https://beginnersbook.com/2015/03/thread-join-method-in-java-with-example/) - The join() method is used to hold the execution of currently running thread until the specified thread is dead(finished execution). In this tutorial we will discuss the purpose and use of join() method with examples. Why we use join() method? In normal circumstances we generally have more than one thread, thread scheduler schedules the threads, - [Can we start a Thread twice in Java?](https://beginnersbook.com/2015/03/can-we-start-a-thread-twice-in-java/) - Can we start a thread twice in Java? The answer is no, once a thread is started, it can never be started again. Doing so will throw an IllegalThreadStateException. Lets have a look at the below code: public class ThreadTwiceExample implements Runnable { @Override public void run(){ Thread t = Thread.currentThread(); System.out.println(t.getName()+" is executing."); } - [Why don’t we call run() method directly, why call start() method?](https://beginnersbook.com/2015/03/why-dont-we-call-run-method-directly-why-call-start-method/) - We can call run() method if we want but then it would behave just like a normal method and we would not be able to take the advantage of multithreading. When the run method gets called though start() method then a new separate thread is being allocated to the execution of run method, so if - [Java Multithreading Interview Questions and Answers](https://beginnersbook.com/2015/03/java-multithreading-interview-questions-and-answers/) - Earlier I have shared 100+ core java interview questions based on various topics of core java. In this article I am gonna share interview questions based on multithreading and concurrency only. You would face multithreading questions in almost all the interviews as this is one the frequently asked topic during interviews for java professionals. If - [Java Collections Interview Questions and Answers](https://beginnersbook.com/2015/03/java-collections-interview-questions-and-answers/) - Earlier I have shared 100+ tutorials on Java collections framework. In this article I am going to share interview questions on Java collections framework. If you are new to collections, I would recommend you to refer these tutorials before going through the below set of questions as they would help you to learn the basics - [Java - How to convert StringBuffer to String](https://beginnersbook.com/2015/04/convert-stringbuffer-to-string/) - The toString() method of StringBuffer class can be used to convert StringBuffer content to a String. This method returns a String object that represents the contents of StringBuffer. Method: public String toString() Example: Lets take a simple example first – public class ConvertStringBufferToString1 { public static void main(String[] args) { StringBuffer sb = new StringBuffer("beginnersbook"); - [Java - Convert double to string example](https://beginnersbook.com/2015/05/java-double-to-string/) - In this java tutorial, we will learn how to convert double to string in Java. There are several ways we can do this conversion - 1. Java - Convert double to string using String.valueOf(double) method. 2. Convert double to string in Java using toString() method of Double wrapper class. 3. Java - double to string - [Java – ASCII to String conversion](https://beginnersbook.com/2015/05/java-ascii-to-string-conversion/) - In this tutorial we will learn how to convert ASCII values to a String. Example: Converting ASCII to String Here is the complete code wherein we have an array of ASCII values and we are converting them into corresponding char values then transforming those chars to string using toString() method of Character class. package com.beginnersbook.string; - [Java - boolean to String conversion](https://beginnersbook.com/2015/05/java-boolean-to-string/) - There are two methods by which we can convert a boolean to String: 1) Method 1: Using String.valueOf(boolean b): This method accepts the boolean argument and converts it into an equivalent String value. Method declaration: public static String valueOf(boolean b) parameters: b - represent the boolean variable which we want to convert returns: String representation - [Java - float to String conversion](https://beginnersbook.com/2015/05/java-float-to-string/) - We can convert a float to String using any of the following two methods: 1) Method 1: Using String.valueOf(float f): We pass the float value to this method as an argument and it returns the string representation of it. Method declaration: public static String valueOf(float f) parameters: f - represents the float value that we - [Java - StackTrace to String conversion](https://beginnersbook.com/2015/05/java-stacktrace-to-string-conversion/) - There are times when we want to convert the occurred exception to String. In the following program we are converting the stacktrace to String by using Throwable.printStackTrace(PrintWriter pw). Example: Converting Exception StackTrace to String package com.beginnersbook.string; import java.io.PrintWriter; import java.io.StringWriter; public class StacktraceToString { public static void main(String args[]){ try{ - [Java - Writer to String conversion](https://beginnersbook.com/2015/05/java-writer-to-string-conversion/) - package com.beginnersbook.string; import java.io.StringWriter; public class WriterToString { public static void main(String args[]){ // create a new writer StringWriter sw = new StringWriter(); // append a char sw.append("abc"); sw.append(" xyz"); String str = sw.toString(); System.out.println(str); - [Java AWT tutorial for beginners](https://beginnersbook.com/2015/06/java-awt-tutorial/) - AWT stands for Abstract Window Toolkit. It is a platform dependent API for creating Graphical User Interface (GUI) for java programs. Why AWT is platform dependent? Java AWT calls native platform (Operating systems) subroutine for creating components such as textbox, checkbox, button etc. For example an AWT GUI having a button would have a different - [Java Swing Tutorial for beginners](https://beginnersbook.com/2015/07/java-swing-tutorial/) - Swing is a part of Java Foundation classes (JFC), the other parts of JFC are java2D and Abstract window toolkit (AWT). AWT, Swing & Java 2D are used for building graphical user interfaces (GUIs) in java. In this tutorial we will mainly discuss about Swing API which is used for building GUIs on the top - [Swing - JButton tutorial and examples](https://beginnersbook.com/2015/07/swing-jbutton-class/) - JButton class is used for adding platform independent buttons to a swing application. In this tutorial we will learn how to create a button in Swing application and how to tweak their appearance as per the requirement. I have also shared some code snippets that may be useful for you while developing a Swing application. - [Java - How to Sort a HashSet?](https://beginnersbook.com/2015/09/sorting-hashset-java/) - As we know HashSet doesn't sort elements, in fact it displays them in random order. While dealing with HashSet we may come across a situation where we need to sort it explicitly. we need to write a logic to sort them when required. In this article we are going to see an example where we - [Java - Border Layout in AWT](https://beginnersbook.com/2016/03/java-border-layout-in-awt/) - In Border layout we can add components (such as text fields, buttons, labels etc) to the five specific regions. These regions are called PAGE_START, LINE_START, CENTER, LINE_END, PAGE_END. Refer the diagram below to understand their location on a Frame. The diagram above is the output of below code, where I have added five buttons (which - [Tag or marker interfaces in Java](https://beginnersbook.com/2016/03/tag-or-marker-interfaces-in-java/) - An empty interface is known as tag or marker interface. For example Serializable, EventListener, Remote(java.rmi.Remote) are tag interfaces, there are few other tag interfaces as well. These interfaces do not have any field and methods in it. You must be thinking if they are empty why class implements them? What’s the use of it? Class - [Nested or Inner interfaces in Java](https://beginnersbook.com/2016/03/nested-or-inner-interfaces-in-java/) - An interface which is declared inside another interface or class is called nested interface. They are also known as inner interface. Since nested interface cannot be accessed directly, the main purpose of using them is to resolve the namespace by grouping related interfaces (or related interface and class) together. This way, we can only call - [Java – FlowLayout in AWT](https://beginnersbook.com/2016/03/java-flowlayout-in-awt/) - Flow layout is the default layout, which means if you don't set any layout in your code then layout would be set to Flow by default. Flow layout puts components (such as text fields, buttons, labels etc) in a row, if horizontal space is not enough to hold all components then Flow layout adds them - [How to install Eclipse on Mac OS X](https://beginnersbook.com/2016/04/how-to-install-eclipse-on-mac-os-x/) - In this tutorial, we will learn how to install eclipse IDE on Mac OS X. Eclipse IDE (Integrated development environment) is written in Java and mostly used for developing Java applications. In Eclipse IDE, you can write, compile and run your Java code. Download and install Eclipse 1) To download Eclipse IDE, copy the link - [Swing - BorderLayout in Java](https://beginnersbook.com/2016/09/swing-borderlayout-in-java/) - Borderlayout has five areas where we can add components, the areas are: 1) PAGE_START 2) PAGE_END 3) LINE_START 4) LINE_END 5) CENTER In this screenshot we have five buttons that are added to each area of a container. The container has BorderLayout. Button names are same as area names for better understanding, they can be - [Lambda Expression - Iterating Map and List in Java 8](https://beginnersbook.com/2017/01/lambda-expression-iterating-map-and-list-in-java-8/) - I have already covered normal way of iterating Map and list in Java. In this tutorial, we will see how to iterate (loop) Map and List in Java 8 using Lambda expression. Iterating Map in Java 8 using Lambda expression package com.beginnersbook; import java.util.HashMap; import java.util.Map; public class IterateMapUsingLambda { public static void main(String[] args) - [Java - Find files with given extension](https://beginnersbook.com/2017/01/java-find-files-with-given-extension/) - In this tutorial, we will see how to find all the files with certain extensions in the specified directory. Program: Searching all files with ".png" extension In this program, we are searching all ".png" files in the "Documents" directory(folder). I have placed three files Image1.png, Image2.png, Image3.png in the Documents directory. Similarly, we can search - [If, If..else Statement in Java with Examples](https://beginnersbook.com/2017/08/if-else-statement-in-java/) - When we need to execute a set of statements based on a condition then we need to use control flow statements. For example, if a number is greater than zero then we want to print "Positive Number" but if it is less than zero then we want to print "Negative Number". In this case we - [Switch Case statement in Java with example](https://beginnersbook.com/2017/08/java-switch-case/) - Switch case statement is used when we have number of options (or choices) and we may need to perform a different task for each choice. The syntax of Switch case statement looks like this – switch (variable or an integer expression) { case constant: //Java code ; case constant: //Java code ; default: //Java code - [Continue Statement in Java with example](https://beginnersbook.com/2017/08/java-continue-statement/) - Continue statement is mostly used inside loops. Whenever it is encountered inside a loop, control directly jumps to the beginning of the loop for next iteration, skipping the execution of statements inside loop’s body for the current iteration. This is particularly useful when you want to continue the loop but do not want the rest - [Comparator Interface in Java](https://beginnersbook.com/2017/08/comparator-interface-in-java/) - In the last tutorial, we have seen how to sort objects of a custom class using Comparable interface. By using Comparable we can sort the objects based on any data member. For example, lets say we have an Author class has data members: Author name, book name and author age, now if we want to - [PriorityQueue Interface in Java Collections](https://beginnersbook.com/2017/08/java-collections-priorityqueue-interface/) - In the last tutorial, we have seen how a Queue serves the requests based on FIFO(First in First out). Now the question is: What if we want to serve the request based on the priority rather than FIFO? In a practical scenario this type of solution would be preferred as it is more dynamic and - [Deque Interface in Java Collections](https://beginnersbook.com/2017/08/java-collections-deque-interface/) - Deque is a Queue in which you can add and remove elements from both sides. In the Java Queue tutorial we have seen that the Queue follows FIFO (First in First out) and in PriorityQueue example we have seen how to remove and add elements based on the priority. In this tutorial, we will see - [Java 8 - Get Current Date and Time](https://beginnersbook.com/2017/09/java-8-get-current-date-and-time/) - In the past we learned how to get current date and time in Java using Date and Calendar classes. Here we will see how can we get current date & time in Java 8. Java 8 introduces a new date and time API java.time.* which has several classes, but the ones that we can use - [Java Lambda Expressions Tutorial with examples](https://beginnersbook.com/2017/10/java-lambda-expressions-tutorial-with-examples/) - Lambda expression is a new feature which is introduced in Java 8. A lambda expression is an anonymous function. A function that doesn't have a name and doesn't belong to any class. The concept of lambda expression was first introduced in LISP programming language. Java Lambda Expression Syntax To create a lambda expression, we specify - [Method References in Java 8](https://beginnersbook.com/2017/10/method-references-in-java-8/) - In the previous tutorial we learned lambda expressions in Java 8. Here we will discuss another new feature of java 8, method reference. Method reference is a shorthand notation of a lambda expression to call a method. For example: If your lambda expression is like this: str -> System.out.println(str) then you can replace it with - [Java Functional Interfaces](https://beginnersbook.com/2017/10/java-functional-interfaces/) - An interface with only single abstract method is called functional interface. You can either use the predefined functional interface provided by Java or create your own functional interface and use it. You can check the predefined functional interfaces here: predefined functional interfaces they all have only one abstract method. That is the reason,they are also - [Java 8 Interface Changes – default method and static method](https://beginnersbook.com/2017/10/java-8-interface-changes-default-method-and-static-method/) - Prior to java 8, interface in java can only have abstract methods. All the methods of interfaces are public & abstract by default. Java 8 allows the interfaces to have default and static methods. The reason we have default methods in interfaces is to allow the developers to add new methods to the interfaces without - [Java 8 Stream Tutorial](https://beginnersbook.com/2017/10/java-8-stream-tutorial/) - In the previous tutorial we learned the interface changes in java 8. In this guide, we will discuss Stream API which is another new feature of java 8. All the classes and interfaces of this API is in the java.util.stream package. By using streams we can perform various aggregate operations on the data returned from - [Java 8 Stream Filter with examples](https://beginnersbook.com/2017/10/java-8-stream-filter/) - In the previous tutorial, we learned about Java Stream. I would recommend you to read that guide before going through this tutorial. In this guide, we will discuss the Java stream filter. The filter() is an intermediate operation that reads the data from a stream and returns a new stream after transforming the data based - [Java 8 - Filter null values from a Stream](https://beginnersbook.com/2017/10/java-8-filter-null-values-from-a-stream/) - In this tutorial, we will see how to filter the null values from a Stream in Java. Example: A stream with null values In this example, we have a stream with null values. Lets see what happens when we do not filter the null values. import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; public class Example { - [Java 8 - Filter a Map by keys and values](https://beginnersbook.com/2017/10/java-8-filter-a-map-by-keys-and-values/) - In the previous tutorial we learned about Java Stream Filter. In this guide, we will see how to use Stream filter() method to filter a Map by keys and Values. Java 8 - Filter Map by Keys import java.util.Map; import java.util.HashMap; import java.util.stream.Collectors; public class Example { public static void main(String[] args) { Map - [Java 8 forEach method with example](https://beginnersbook.com/2017/10/java-8-foreach/) - In Java 8, we have a newly introduced forEach method to iterate over collections and Streams in Java. In this guide, we will learn how to use forEach() and forEachOrdered() methods to loop a particular collection and stream. Java 8 - forEach to iterate a Map import java.util.Map; import java.util.HashMap; public class Example { - [Java 8 – Stream Collectors Class with examples](https://beginnersbook.com/2017/10/java-8-stream-collectors-class-with-examples/) - Collectors is a final class that extends the Object class. In this tutorial we will see the examples of Java Stream collectors class using lambda expressions, Java Streams and other new features of Java 8. java.lang.Object | |___java.util.stream.Collectors Java - Stream Collectors groupingBy and counting Example In this example, we are grouping the elements of - [Java 8 StringJoiner with example](https://beginnersbook.com/2017/10/java-8-stringjoiner/) - In java 8, a new class StringJoiner is introduced in the java.util package. Using this class we can join more than one strings with the specified delimiter, we can also provide prefix and suffix to the final string while joining multiple strings. In this tutorial we will see several examples of StringJoiner class and at - [Java 8 Optional Class](https://beginnersbook.com/2017/10/java-8-optional-class/) - In Java 8, we have a newly introduced Optional class in java.util package. This class is introduced to avoid NullPointerException that we frequently encounters if we do not perform null checks in our code. Using this class we can easily check whether a variable has null value or not and by doing this we can - [Java 8 features with examples](https://beginnersbook.com/2017/10/java-8-features-with-examples/) - Java 8 got released on March 18, 2014. There are several new features that are introduced in this release. I have covered all the Java 8 features in the separate guides. Here are the links to all the Java 8 tutorials in the systematic order: Java 8 features 1. Java 8 - Lambda Expression 2. - [Java 8 Lambda Comparator example for Sorting List of Custom Objects](https://beginnersbook.com/2017/10/java-8-lambda-comparator-example-for-sorting-list-of-custom-objects/) - We have already seen how to sort an Arraylist of custom Objects without using lambda expression. In this tutorial we will see how to sort a list of custom objects using lambda expression in Java. Before we see the complete example, lets see what is the difference between using lambda vs without using lambda: Without - [How to get current day, month, year, day of week/month/year in java](https://beginnersbook.com/2014/01/how-to-get-current-day-month-year-day-of-weekmonthyear-in-java/) - In this tutorial we will see how to get current date, day, month, year, day of week, day of month and day of year in java. import java.util.Calendar; import java.util.Date; import java.util.TimeZone; class Example { public static void main(String args[]) { Calendar calendar = Calendar.getInstance(TimeZone.getDefault()); //getTime() returns the current date in default time zone Date - [Append to a file in java using BufferedWriter, PrintWriter, FileWriter](https://beginnersbook.com/2014/01/how-to-append-to-a-file-in-java/) - In this tutorial we will learn how to append content to a file in Java. There are two ways to append: 1) Using FileWriter and BufferedWriter: In this approach we will be having the content in one of more Strings and we will be appending those Strings to the file. The file can be appended - [How to delete file in Java - delete() Method](https://beginnersbook.com/2014/01/how-to-delete-file-in-java-delete-method/) - In this tutorial we will see how to delete a File in java. We will be using the delete() method for file deletion. public boolean delete() This method returns true if the specified File deleted successfully otherwise it returns false. Here is the complete code: import java.io.File; public class DeleteFileJavaDemo { public static void main(String[] args) { - [How to rename file in Java - renameTo() method](https://beginnersbook.com/2014/01/how-to-rename-file-in-java-renameto-method/) - Earlier we saw how to create, read, write, append to a file in java. In this tutorial we will see how to rename a file in java using renameTo() method. public boolean renameTo(File dest) It returns true if the file is renamed successfully else it returns false. It throws NullPointerException - If parameter dest is null. - [How to convert String to 24 hour date time format in java](https://beginnersbook.com/2014/01/how-to-convert-string-to-24-hour-date-time-format-in-java/) - We already seen String to Date conversion. In this tutorial we will see how to convert a String to a 24 hour date time format in Java. Java - Convert String to 24 hour format In this example we have three Strings of different formats and we are converting them to a 24 hour date - [Java Date - Convert 12 hour format to 24 hour format and vice versa](https://beginnersbook.com/2014/01/how-to-convert-12-hour-time-to-24-hour-date-in-java/) - In this tutorial we will see how to convert 12 hour format to 24 hour format and 24 hour format to 12 hour format in Java. Java - Convert 12 Hour data time format to 24 hour date time format We can change the pattern in the SimpleDateFormat for the conversion. The pattern dd/MM/yyyy hh:mm:ss - [Abstract method in Java with examples](https://beginnersbook.com/2014/01/abstract-method-with-examples-in-java/) - A method without body (no implementation) is known as abstract method. A method must always be declared in an abstract class, or in other words you can say that if a class has an abstract method, it should be declared abstract as well. In the last tutorial we discussed Abstract class, if you have not - [Java - Default constructor with example](https://beginnersbook.com/2014/01/default-constructor-java-example/) - If you don't implement any constructor in your class, the Java compiler inserts default constructor into your code on your behalf. You will not see the default constructor in your source code(the .java file) as it is inserted during compilation and present in the bytecode(.class file). Are no-arg constructor and default constructor same? This is - [Java - parameterized constructor with example](https://beginnersbook.com/2014/01/parameterized-constructor-in-java-example/) - A Constructor with arguments(or you can say parameters) is known as Parameterized constructor. As we discussed in the Java Constructor tutorial that a constructor is a special type of method that initializes the newly created object. Example of Parameterized Constructor We can have any number of Parameterized Constructor in our class. In this example, I - [How to Copy a File to another File in Java](https://beginnersbook.com/2014/05/how-to-copy-a-file-to-another-file-in-java/) - In this tutorial we will see how to copy the content of one file to another file in java. In order to copy the file, first we can read the file using FileInputStream and then we can write the read content to the output file using FileOutputStream. Example The below code would copy the content - [How to get the last modified date of a file in java](https://beginnersbook.com/2014/05/how-to-get-the-last-modified-date-of-a-file-in-java/) - Here we will learn how to get the last modified date of a file in java. In order to do this we can use the lastModified() method of File class. Following is the signature of this method. public long lastModified() It returns the time that the file denoted by this abstract pathname was last modified. - [How to make a File Read Only in Java](https://beginnersbook.com/2014/05/how-to-make-a-file-read-only-in-java/) - Making a file read only is very easy in java. In this tutorial, we will learn following three things. 1) How to make a file read only 2) How to check whether the existing file is in read only mode or not 3) How to make a read only file writable in java. 1) Changing - [Difference between HashMap and Hashtable](https://beginnersbook.com/2014/06/difference-between-hashmap-and-hashtable/) - What is the Difference between HashMap and Hashtable? This is one of the frequently asked interview questions for Java/J2EE professionals. HashMap and Hashtable both classes implements java.util.Map interface, however there are differences in the way they work and their usage. Here we will discuss the differences between these classes. HashMap vs Hashtable 1) HashMap is non-synchronized. This means if it's used - [How to sort Hashtable in java](https://beginnersbook.com/2014/06/how-to-sort-hashtable-in-java/) - Hashtable doesn't preserve the insertion order, neither it sorts the inserted data based on keys or values. Which means no matter what keys & values you insert into Hashtable, the result would not be in any particular order. For example: Lets have a look at the below program and its output: import java.util.*; public class - [ListIterator in Java with examples](https://beginnersbook.com/2014/06/listiterator-in-java-with-examples/) - In the last tutorial, we discussed Iterator in Java using which we can traverse a List or Set in forward direction. Here we will discuss ListIterator that allows us to traverse the list in both directions (forward and backward). ListIterator Example In this example we are traversing an ArrayList in both the directions. import java.util.ArrayList; - [Difference between Iterator and ListIterator in java](https://beginnersbook.com/2014/06/difference-between-iterator-and-listiterator-in-java/) - Here we will discuss the differences between Iterator and ListIterator. Both of these interfaces are used for traversing but still there are few differences in the way they can be used for traversing a collection. I would recommend you to go through the following tutorials to understand these interfaces better before going through the differences. - [Map.Entry Interface in Java](https://beginnersbook.com/2014/06/map-entry-interface-in-java/) - Map.Entry interface helps us iterating a Map class such as HashMap, TreeMap etc. In this tutorial, we will learn methods and usage of Map.Entry interface in Java. Method of Map.Entry interface 1) boolean equals(Object o): Compares the specified object with this entry for equality. 2) Key getKey(): Returns the key corresponding to this entry. 3) - [Vector Enumeration example in Java](https://beginnersbook.com/2014/06/vector-enumeration-example-in-java/) - In this example, we are iterating a Vector using Enumeration. The steps are as follows: 1) Create a Vector object 2) Add elements to vector using add() method of Vector class. 3) Call elements() method to get the Enumeration of specified Vector 4) Use hashMoreElements() and nextElement() Methods of Enumeration to iterate through the Vector. - [How to Sort Vector using Collections.sort in java - Example](https://beginnersbook.com/2014/06/how-to-sort-vector-using-collections-sort-in-java-example/) - Vector maintains the insertion order which means it displays the elements in the same order, in which they got added to the Vector. In this example, we will see how to sort Vector elements in ascending order by using Collections.sort(). The Steps are as follows: 1) Create a Vector object 2) Add elements to the - [How to Set Vector size example](https://beginnersbook.com/2014/06/how-to-set-vector-size-example/) - We can set the size of a Vector using setSize() method of Vector class. If new size is greater than the current size then all the elements after current size index have null values. If new size is less than current size then the elements after current size index have been deleted from the Vector. - [Search elements in Vector using index - Java example](https://beginnersbook.com/2014/06/search-elements-in-vector-using-index-java-example/) - In this tutorial, we will learn four following ways to search elements in Vector using index value. 1) public int indexOf(Object o): It returns the index of first occurrence of Object o in Vector. 2) public int indexOf(Object o, int startIndex): It returns the index of the first occurrence of the Object o in this - [Replace Vector elements using index - Java example](https://beginnersbook.com/2014/06/replace-vector-elements-using-index-java-example/) - In this tutorial, we will see how to replace Vector elements. We will be using set() method of Vector class to do that. public E set(int index, E element): Replaces the element at the specified position in this Vector with the specified element. Example In this example, we are replacing 2nd and 3rd elements of - [Remove Vector element - Java example](https://beginnersbook.com/2014/06/remove-vector-element-java-example/) - In this example we will see how to remove elements from Vector. We will be using remove(Object o) method of Vector API in order to remove specified elements. public boolean remove(Object o): Removes the first occurrence of the specified element from Vector If the Vector does not contain the element, it is unchanged. Example In - [How to remove Vector elements using index in java example](https://beginnersbook.com/2014/06/how-to-remove-vector-elements-using-index-in-java-example/) - In this tutorial, we will learn how to remove elements from Vector using index. We will be using remove(int index) method of Vector class. public E remove(int index): Removes the element at the specified position in this Vector. Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was - [Remove all elements from Vector in Java - Example](https://beginnersbook.com/2014/06/remove-all-elements-from-vector-in-java-example/) - In this example, we will see how to remove all the elements from a Vector. We will be using clear() method of Vector class to do this. public void clear(): Removes all of the elements from this Vector. The Vector will be empty after this method call. Example Here we are displaying the size of - [Vector ListIterator example in Java](https://beginnersbook.com/2014/06/vector-listiterator-example-in-java/) - We can traverse a Vector in forward and Backward direction using ListIterator. Along with this we can perform several other operation using methods of ListIterator API like displaying the indexes of next and previous elements, replacing the element value, remove elements during iteration etc. Example Here we have a Vector of Strings and we are - [Vector Iterator example in Java](https://beginnersbook.com/2014/06/vector-iterator-example-in-java/) - In the last tutorial we learnt how to traverse a Vector in both the directions(forward & backward) using ListIterator. In this example, we are gonna see how to traverse a Vector using Iterator. The steps are as follows: 1) Create a Vector 2) Add elements to it using add(Element E) method of Vector class 3) - [How to get sub list of Vector example in java](https://beginnersbook.com/2014/06/how-to-get-sub-list-of-vector-example-in-java/) - In this example, we are gonna see how to get a sublist of elements from a Vector. We will be using subList() method of Vector class to do this. More about this method from javadoc: public List subList(int fromIndex, int toIndex): It returns a view of the portion of this List between fromIndex, inclusive, and - [Java - Remove element from a specific index in LinkedList example](https://beginnersbook.com/2014/07/java-remove-element-from-a-specific-index-in-linkedlist-example/) - In this example, we are gonna see how to remove an element from LinkedList. Example We will be using remove(int index) method of LinkedList class to remove an element from a specific index. Method definition and description are as follows: public E remove(int index): Removes the element at the specified position in this list. Shifts - [Java - Remove specific elements from LinkedList example](https://beginnersbook.com/2014/07/java-remove-specific-elements-from-linkedlist-example/) - In the last post we shared a tutorial on how to remove a element from specific index in LinkedList. Here we will learn how to remove a specific element from the LinkedList. Example We will be using remove(Object o) method to perform this remove. More about this method is as follows: public boolean remove(Object o): - [Java - Remove first and last element from LinkedList example](https://beginnersbook.com/2014/07/java-remove-first-and-last-element-from-linkedlist-example/) - In this tutorial we will learn how to remove First and Last elements from LinkedList. In the few last posts we shared following tutorials: 1) Removing elements from a specific index 2) Removing specific element from LinkedList Example We have used removeFirst() method to remove first and removeLast() method to remove last element from LinkedList. - [Java - Remove all elements from LinkedList example](https://beginnersbook.com/2014/07/java-remove-all-elements-from-linkedlist-example/) - In this example we will see how to remove all the elements from LinkedList. We will be using clear() method of LinkedList class to do this. Method definition and description are as follows: public void clear(): Removes all of the elements from this list. The list will be empty after this call returns. Example In - [Java - LinkedList ListIterator example](https://beginnersbook.com/2014/07/java-linkedlist-listiterator-example/) - In this example we will see how to iterate a LinkedList using ListIterator. Using Listterator we can iterate the list in both the directions(forward and backward). Along with traversing, we can also modify the list during iteration, and obtain the iterator's current position in the list. Read more about it at ListIterator javadoc. Example Here - [Java - LinkedList Iterator example](https://beginnersbook.com/2014/07/java-linkedlist-iterator-example/) - In the last post we learnt how to traverse a LinkedList using ListIterator. Here we will learn how to iterate a LinkedList using Iterator. Example The steps we followed in the below program are: 1) Create a LinkedList 2) Add element to it using add(Element E) method 3) Obtain the iterator by calling iterator() method - [Java - Add element at specific index in LinkedList example](https://beginnersbook.com/2014/07/java-add-element-at-specific-index-in-linkedlist-example/) - In this tutorial we will learn how to add a new element at specific index in LinkedList. We will be using add(int index, Element E) method of LinkedList class to perform this operation. More about this method from javadoc: public void add(int index, E element): Inserts the specified element at the specified position in this - [Java - Get sub List from LinkedList example](https://beginnersbook.com/2014/07/java-get-sub-list-from-linkedlist-example/) - Example In this example, we are getting a sublist of LinkedList using subList(int startIndex, int endIndex) method of LinkedList class. It returns a List between the specified index startIndex(inclusive) and endIndex(exclusive). Any changes made to the sublist will be reflected in the original list (We have tested this in the below program by removing an - [Java - Get first and last elements from LinkedList example](https://beginnersbook.com/2014/07/java-get-first-and-last-elements-from-linkedlist-example/) - In this tutorial we will see an example on how to get first and last element from LinkedList. Example Here we have a LinkedList of String type and we are getting first and last element from it using getFirst() and getLast() methods of LinkedList class. Method definition and description are as follows: 1) public E - [Java - Convert a LinkedList to ArrayList](https://beginnersbook.com/2014/07/java-convert-a-linkedlist-to-arraylist/) - Example In this example we are converting a LinkedList to ArrayList. We have a LinkedList of Strings in which we are storing names of 5 peoples. Later after conversion we are displaying the elements of ArrayList to ensure that ArrayList is having same elements that we have in LinkedList. The complete program is as follows: - [How to convert LinkedList to array using toArray() in Java](https://beginnersbook.com/2014/07/how-to-convert-linkedlist-to-array-using-toarray-in-java/) - Converting LinkedList to array is very easy. You can convert a LinkedList of any type (such as double, String, int etc) to an array of same type. In this tutorial we will see an example of such type of conversion. Example Here we are converting a LinkedList of strings to String Array (LinkedList to String[]). - [Java - Add elements at beginning and end of LinkedList example](https://beginnersbook.com/2014/07/java-add-elements-at-beginning-and-end-of-linkedlist-example/) - Example In this example we will learn how to add elements at the beginning and end of a LinkedList. We will be using addFirst() and addLast() method of LinkedList class. Method definition and description are as follows: 1) public void addFirst(E e): Inserts the specified element at the beginning of this list. 2) public void - [Java - Check if a particular element exists in LinkedList example](https://beginnersbook.com/2014/07/java-check-if-a-particular-element-exists-in-linkedlist-example/) - In this example we are gonna see how to check if a particular element exists in LinkedList using contains() method: public boolean contains(Object o): Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (o==null ? e==null : - [Java - Get element from specific index of LinkedList example](https://beginnersbook.com/2014/07/java-get-element-from-specific-index-of-linkedlist-example/) - In this example we are gonna see how to get an element from specific index of LinkedList using get(int index) method: public E get(int index): Returns the element at the specified position in this list. import java.util.LinkedList; public class GetElementExample { public static void main(String[] args) { // Creating LinkedList of String Elements LinkedList linkedlist - [Java - Remove mapping from HashMap example](https://beginnersbook.com/2014/07/java-remove-mapping-from-hashmap-example/) - Example In this example we are gonna see how to remove a specific mapping from HashMap using the key value of Key-value pair. We will be using the following method of HashMap class to perform this operation: public Value remove(Object key): Removes the mapping for the specified key from this map if present and returns - [Java - Remove all mappings from HashMap example](https://beginnersbook.com/2014/07/java-remove-all-mappings-from-hashmap-example/) - Example In the last tutorial we shared how to remove a specific mapping from HashMap based on key. In this example we are going to see how to remove all the mappings from HashMap. We will be using clear() method of HashMap class to do this: public void clear(): Removes all of the mappings from - [Java - HashMap Iterator example](https://beginnersbook.com/2014/07/java-hashmap-iterator-example/) - Example In the previous tutorial we have seen different-2 ways to iterate a HashMap. In this example we are gonna see how to iterate a HashMap using Iterator and display key and value pairs. The steps we followed in the below example are as follows: 1) Create a HashMap and populate it with key-value pairs. - [Java - Get size of HashMap example](https://beginnersbook.com/2014/07/java-get-size-of-hashmap-example/) - In this example we are gonna see how to get the size of HashMap using size() method of HashMap class. Method definition and description are as follows: public int size(): Returns the number of key-value mappings in this map. import java.util.HashMap; public class SizeExample { public static void main(String[] args) { // Creating a HashMap - [Java - Check if a particular value exists in HashMap example](https://beginnersbook.com/2014/07/java-check-if-a-particular-value-exists-in-hashmap-example/) - In this example we are checking whether a particular value exists in HashMap or not. We will be using containsValue() method of HashMap class to perform this check: public boolean containsValue(Object value): Returns true if this map maps one or more keys to the specified value. Complete Code: Here we have a HashMap of integer - [Java - Check if a particular key exists in HashMap example](https://beginnersbook.com/2014/07/java-check-if-a-particular-key-exists-in-hashmap-example/) - In the last tutorial we learnt how to check whether a particular value exists in HashMap. In this example we are gonna see how to check if a particular key is present in HashMap. We will be using containsKey() method of HashMap class to perform this check. The method definition and description are as follows: - [Remove mapping from Hashtable example - Java](https://beginnersbook.com/2014/07/remove-mapping-from-hashtable-example-java/) - In this tutorial we are gonna see how to remove a key-value mapping from Hashtable. We will be using remove(Object key) method of Hashtable class. Example Method used in the below program is: public V remove(Object key): Removes the key (and its corresponding value) from this hashtable. This method does nothing if the key is - [Remove all mappings from Hashtable example - Java](https://beginnersbook.com/2014/07/remove-all-mappings-from-hashtable-example-java/) - In the last tutorial we have seen how to remove a mapping from Hashtable based on key. In this tutorial we will learn how to remove all the mappings from Hashtable and make it empty. Example Method used in the below program: clear() public void clear(): Clears this hashtable so that it contains no keys. - [Hashtable in java with example](https://beginnersbook.com/2014/07/hashtable-in-java-with-example/) - This class implements a hash table, which maps keys to values. Any non-null object can be used as a key or as a value. Hashtable is similar to HashMap except it is synchronized. There are few more differences between HashMap and Hashtable class, you can read them in detail at: Difference between HashMap and Hashtable. - [Hashtable Iterator example - Java](https://beginnersbook.com/2014/07/hashtable-iterator-example-java/) - In this example we will see how to iterate a Hashtable using Iterator. Using Iterator we can display Hashtable key and value separately for each pair of elements. Example There are several methods (of both Hashtable class and Iterator interface) used in the below program. Definition and description of each method have been provided in - [Get size of Hashtable example in Java](https://beginnersbook.com/2014/07/get-size-of-hashtable-example-in-java/) - Example In this example we are gonna see how to get the size of Hashtable. We will be using size() method of Hashtable class to perform this operation. import java.util.Hashtable; public class SizeExample{ public static void main(String[] args) { // Creating a Hashtable instance Hashtable hashtable = new Hashtable(); // Adding key-value pairs - [Check key & Value existence in Hashtable example - Java](https://beginnersbook.com/2014/07/check-key-value-existence-in-hashtable-example-java/) - Example In this example we are gonna see how to check Key and value existence in Hashtable. We will be using following two methods to perform this check: containsKey(Object key): To check if the key present in Hashtable. containsvalue(Object value): To check if the value present in Hashtable. import java.util.Hashtable; public class CheckKeyValueExample { public - [Java Serialization](https://beginnersbook.com/2014/07/java-serialization/) - Here we are gonna discuss how to serialize and de-serialize an object and what is the use of it. What is Java Serialization? Serialization is a mechanism to convert an object into stream of bytes so that it can be written into a file, transported through a network or stored into database. De-serialization is just - [How to Compress a File in GZIP Format](https://beginnersbook.com/2014/07/how-to-compress-a-file-in-gzip-format/) - The below code would compress a specified file to GZip format. In the below example we have a text file in B drive under "Java" Folder and we are compressing and generating the GZip file in the same folder. import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.GZIPOutputStream; public class GZipExample { public static void main( - [Difference between List and Set in Java](https://beginnersbook.com/2014/07/difference-between-list-and-set-in-java/) - List and Set both are interfaces. They both extends Collection interface. In this post we are discussing the differences between List and Set interfaces in java. List Vs Set 1) List is an ordered collection it maintains the insertion order, which means upon displaying the list content it will display the elements in the same - [Super keyword in java with example](https://beginnersbook.com/2014/07/super-keyword-in-java-with-example/) - The super keyword refers to the objects of immediate parent class. Before learning super keyword you must have the knowledge of inheritance in Java so that you can understand the examples given in this guide. The use of super keyword 1) To access the data members of parent class when both parent and child class - [Remove Key-value mapping from TreeMap example](https://beginnersbook.com/2014/07/remove-key-value-mapping-from-treemap-example/) - In this tutorial we are gonna see how to remove a Key-value mapping from TreeMap. We are using remove(Object key) method of TreeMap class to perform this remove. import java.util.TreeMap; public class Details { public static void main(String[] args) { // Create a TreeMap TreeMap treemap = new TreeMap(); // Add key-value pairs - [Remove all mappings from TreeMap example - Java](https://beginnersbook.com/2014/07/remove-all-mappings-from-treemap-example-java/) - This is how to remove all the key-value mappings from TreeMap and make it empty. We are using clear() method of TreeMap class to perform this update. import java.util.TreeMap; public class RemoveAllExample { public static void main(String[] args) { // Create a TreeMap TreeMap treemap = new TreeMap(); // Add key-value pairs to - [TreeMap Iterator example - Java](https://beginnersbook.com/2014/07/treemap-iterator-example-java/) - In this example we are iterating a TreeMap using Iterator and Map.Entry. import java.util.TreeMap; import java.util.Set; import java.util.Map; import java.util.Iterator; public class TreeMapExample { public static void main(String[] args) { // Create a TreeMap TreeMap treemap = new TreeMap(); // Add key-value pairs to the TreeMap treemap.put("Key1","Item1"); treemap.put("Key2","Item2"); treemap.put("Key3","Item3"); treemap.put("Key4","Item4"); treemap.put("Key5","Item5"); // Get - [How to sort a TreeMap by value in java](https://beginnersbook.com/2014/07/how-to-sort-a-treemap-by-value-in-java/) - A TreeMap is always sorted based on its keys, however if you want to sort it based on its values then you can build a logic to do this using comparator. Below is a complete code of sorting a TreeMap by values. import java.util.*; class TreeMapDemo { //Method for sorting the TreeMap based on values - [How to iterate TreeMap in reverse order in Java](https://beginnersbook.com/2014/07/how-to-iterate-treemap-in-reverse-order-in-java/) - By default TreeMap elements are sorted in ascending order of keys. We can iterate the TreeMap in reverse order to display the elements in descending order of keys. Display TreeMap elements in reverse order: import java.util.*; class TreeMapDemo { public static void main(String args[]) { Map treemap = new TreeMap(Collections.reverseOrder()); // Put elements - [How to get the Sub Map from TreeMap example - Java](https://beginnersbook.com/2014/07/how-to-get-the-sub-map-from-treemap-example-java/) - In this example we are gonna see how to get a sub map from TreeMap. We are using subMap() method of TreeMap class. Please refer the comments in the below program for more details. Example import java.util.*; class TreeMapDemo { public static void main(String args[]) { // Create a TreeMap TreeMap treemap = new - [How to get the size of TreeMap example - Java](https://beginnersbook.com/2014/07/how-to-get-the-size-of-treemap-example-java/) - In this tutorial we willl learn how to get the size of a TreeMap. We are using size() method of TreeMap class to get the number of key-value mappings of a TreeMap. Here is the complete code: Example import java.util.TreeMap; class TreeMapSize { public static void main(String args[]) { // Create a TreeMap TreeMap - [java - Right padding a String with Spaces and Zeros](https://beginnersbook.com/2014/07/java-right-padding-a-string-with-spaces-and-zeros/) - In this tutorial we are gonna see how to right pad a string with spaces and zeros: 1) Right pad with spaces public class PadRightExample1 { public static void main(String[] argv) { System.out.println("#" + rightPadding("mystring", 10) + "@"); System.out.println("#" + rightPadding("mystring", 15) + "@"); System.out.println("#" + rightPadding("mystring", 20) + "@"); } public static String rightPadding(String - [java – Left padding a String with Spaces and Zeros](https://beginnersbook.com/2014/07/java-left-padding-a-string-with-spaces-and-zeros/) - In this tutorial we are gonna see how to left pad a string with spaces and zeros: 1) Left pad with spaces class LeftPaddingExample1 { public static void main(String[] args) { System.out.println("#" + padLeftSpaces("mystring", 10) + "@"); System.out.println("#" + padLeftSpaces("mystring", 15) + "@"); System.out.println("#" + padLeftSpaces("mystring", 20) + "@"); } public static String padLeftSpaces(String str, - [How to remove only trailing spaces of a string in Java](https://beginnersbook.com/2014/07/how-to-remove-only-trailing-spaces-of-a-string-in-java/) - In this tutorial we will learn how to trim trailing spaces from the string but not leading spaces. Here is the complete code: class TrimBlanksExample { public static void main(String[] args) { System.out.println("#"+trimTrailingBlanks(" How are you?? ")+"@"); System.out.println("#"+trimTrailingBlanks(" I'm Fine. ")+"@"); } public static String trimTrailingBlanks( String str) { if( str == null) return null; - [How to sort an Array in Java](https://beginnersbook.com/2014/07/how-to-sort-an-array-in-java/) - This is the example of sorting an Array in java. Here we have two arrays, one is an integer array and another one is a String array and we are sorting both of them using Arrays.sort() method. import java.util.Arrays; class SortArrayExample { public static void main(String[] args) { // int Array int[] intArr = new - [Sort an Array in Descending (Reverse) Order - Java](https://beginnersbook.com/2014/07/sort-an-array-in-descending-reverse-order-java/) - The previous tutorial was all about sorting an array in ascending order. In this post we are going to learn how to sort an array in Descending (Reverse) Order. Example Here we have two arrays, one is integer array and another one is String array. We are sorting both the arrays in reverse order. import - [Random shuffling of an array in Java](https://beginnersbook.com/2014/07/random-shuffling-of-an-array-in-java/) - import java.util.Arrays; import java.util.Collections; import java.util.List; class ShuffleArrayExample { public static void main(String[] args) { // String Array String[] stringArray = new String[] { "FF", "PP", "AA", "OO", "DD" }; // converting array to a List List list = Arrays.asList(stringArray); // Shuffling list elements Collections.shuffle(list); System.out.println("String Array: "); for (String str : list) { System.out.println(str); - [Java - Finding minimum and maximum values in an array](https://beginnersbook.com/2014/07/java-finding-minimum-and-maximum-values-in-an-array/) - In this example we are finding out the maximum and minimum values from an int array. class MinMaxExample { public static void main(String args[]){ int array[] = new int[]{10, 11, 88, 2, 12, 120}; // Calling getMax() method for getting max value int max = getMax(array); System.out.println("Maximum Value is: "+max); // Calling getMin() method for getting - [Sort byte array in Java](https://beginnersbook.com/2014/07/sort-byte-array-in-java/) - This is the example of sorting a byte array in Java. Here we have done two types of sorting 1) complete sorting using sort(byte[] a) method 2) Selective sorting using sort(byte[] a, int fromIndex, int toIndex) method - It sorts the specified range only. Refer comments in the program for more detail. import java.util.Arrays; class - [Sorting char array in Java example](https://beginnersbook.com/2014/07/sorting-char-array-in-java-example/) - In this example we are sorting a char array. We have demonstrated two types of sorting in the program 1) Complete sorting using sort(char[] a) method 2) Sorting specified range of characters only using sort(char[] a, int fromIndex, int toIndex) method. import java.util.Arrays; class SortCharArray { public static void main(String[] args) { // Creating a - [Sorting double array in Java example](https://beginnersbook.com/2014/07/sorting-double-array-in-java-example/) - import java.util.Arrays; class SortingDoubleArray { public static void main(String[] args) { // Creating a Double Array double[] doubleArray = new double[] { 13.1, 2.5, 2.2, 41.1, 1.1 }; // Displaying Array before Sorting System.out.println("**Double Array Before Sorting**"); for (double d: doubleArray){ System.out.println(d); } // Sorting the Array Arrays.sort(doubleArray); System.out.println("**Double Array After Sorting**"); for (double d: - [Sorting float array in Java example](https://beginnersbook.com/2014/07/sorting-float-array-in-java-example/) - In this tutorial we are gonna learn how to sort a float array. import java.util.Arrays; class SortingFloatArrayExample { public static void main(String[] args) { // Creating a Float Array float[] floatArray = new float[] { 21.1f, 9.9f, 9.8f, 7.5f, 2.1f }; // Displaying Array before Sorting System.out.println("**Float Array Before Sorting**"); for (float temp: floatArray){ System.out.println(temp); - [@Override annotation in Java](https://beginnersbook.com/2014/07/override-annotation-in-java/) - @Override annotation is used when we override a method in sub class. Generally novice developers overlook this feature as it is not mandatory to use this annotation while overriding the method. Here we will discuss why we should use @Override annotation and why it is considered as a best practice in java coding. Lets take - [@Deprecated annotation in java](https://beginnersbook.com/2014/07/deprecated-annotation-in-java/) - @Deprecated annotation is used for informing compiler that the particular method, class or field is deprecated and it should generate a warning when someone try to use any of the them. What is the meaning of "Deprecated"? A deprecated class or method is like that. It is no longer important. It is so unimportant, in - [Convert String Object to Boolean Object in Java](https://beginnersbook.com/2014/07/convert-string-object-to-boolean-object-in-java/) - Description How to convert String object to Boolean object. Example In this example we are gonna see two methods of String to Boolean object conversion. class StringObjToBooleanObj { public static void main(String[] args) { // String Objects String str = "false"; // Case does not matter for conversion String str2 = "TrUe"; /* Method 1: - [Convert String to boolean primitive in Java: parseBoolean() method](https://beginnersbook.com/2014/07/convert-string-to-boolean-primitive-in-java/) - Description How to convert String object to boolean primitive in Java. Example: Complete conversion code In this example we are converting string to boolean using parseBoolean() method of Boolean class. class StringToboolean { public static void main(String[] args) { // String Objects String str = "false"; // Case does not matter for conversion String str2 - [Convert boolean Primitive to Boolean object in Java](https://beginnersbook.com/2014/07/convert-boolean-primitive-to-boolean-object-in-java/) - Description Program to convert boolean primitive to Boolean object Example class BooleanPrimToBooleanObj { public static void main(String[] args) { boolean bvar = true; /* Method 1: By passing boolean value to * the constructor of Boolean class */ Boolean bObj = new Boolean(bvar); System.out.println(bObj); /* Method 2: By passing boolean value to the * valueOf() - [Cast Boolean Object to boolean in Java - booleanValue() Method](https://beginnersbook.com/2014/07/cast-boolean-object-to-boolean-in-java-booleanvalue-method/) - Description Program to convert Boolean object to boolean primitive in java Example class BooleanObjToBooleanPrim { public static void main(String[] args) { // Creating an object of Boolean Class Boolean bObj = new Boolean("true"); // Case does not matter Boolean bObj2 = new Boolean("FaLsE"); /* Boolean object to boolean conversion * using booleanValue() method */ boolean - [Compare boolean values in java - compareTo() Method](https://beginnersbook.com/2014/07/compare-boolean-values-in-java-compareto-method/) - Description Program to compare boolean values. Example In this example we are going to see how to compare two boolean values by using compareTo() method of Boolean class. class CompareBooleanValues { public static void main(String[] args) { // Creating Objects of Boolean class Boolean bObj = new Boolean("true"); // Case does not matter Boolean bObj2 - [Boolean.hashCode() Method in Java](https://beginnersbook.com/2014/08/boolean-hashcode-method-in-java/) - Description Program to get hash code for Boolean object. We are using hashCode() method of Boolean class for this purpose, it returns integer 1231 if this object represents true; returns the integer 1237 if this object represents false. Example class BooleanHashCodeEx { public static void main(String[] args) { // Boolean objects Boolean bObj, bObj2; // - [Get absolute value of float, int, double and long using Math.abs in Java](https://beginnersbook.com/2014/08/get-absolute-value-of-float-int-double-and-long-using-math-abs-in-java/) - Description In this tutorial we are gonna see a program to find out the absolute values of float, int, double and long variables in java. public static double abs(double a): Returns the absolute value of a double value. public static float abs(float a): Returns the absolute value of a float value. public static long abs(long - [Append all the elements of a List to LinkedList - Java](https://beginnersbook.com/2014/08/append-all-the-elements-of-a-list-to-linkedlist-java/) - Description Program to add all the elements of a List to the LinkedList using addAll() method of LinkedList class. Example import java.util.ArrayList; import java.util.LinkedList; import java.util.List; class LinkedListAddAll { public static void main(String[] args) { // create a LinkedList LinkedList list = new LinkedList(); // Add elements to the LinkedList list.add("AA"); list.add("BB"); list.add("CC"); list.add("DD"); // - [Adding an element to LinkedList using add(E e) method - Java](https://beginnersbook.com/2014/08/adding-an-element-to-linkedlist-using-adde-e-method-java/) - Description Program to add a new element to LinkedList using add(E e) method of LinkedList class. Example import java.util.LinkedList; class LinkedListAdd { public static void main(String[] args) { // create a LinkedList LinkedList list = new LinkedList(); // Adding elements to the LinkedList list.add("Harry"); list.add("Ajeet"); list.add("Tom"); list.add("Steve"); // Displaying LinkedList elements System.out.println("LinkedList elements: "+list); // - [Clone a generic LinkedList in Java](https://beginnersbook.com/2014/08/clone-a-generic-linkedlist-in-java/) - Example import java.util.LinkedList; class LinkedListClone { public static void main(String[] args) { // create a LinkedList LinkedList list = new LinkedList(); // Adding elements to the LinkedList list.add("Element1"); list.add("Element2"); list.add("Element3"); list.add("Element4"); // Displaying LinkedList elements System.out.println("LinkedList elements: "+list); // Creating another list LinkedList list2 = new LinkedList(); // Clone list to list2 /* public Object - [Iterate a LinkedList in reverse sequential order - java](https://beginnersbook.com/2014/08/iterate-a-linkedlist-in-reverse-sequential-order-java/) - Description Program to iterate a LinkedList in reverse order using descendingIterator() method of LinkedList class. Program import java.util.LinkedList; import java.util.Iterator; class LinkedListDemo { public static void main(String[] args) { // create a LinkedList LinkedList list = new LinkedList(); // Adding elements to the LinkedList list.add("Element1"); list.add("Element2"); list.add("Element3"); list.add("Element4"); // Displaying LinkedList elements System.out.println("LinkedList elements: "+list); - [Constructor Overloading in Java with examples](https://beginnersbook.com/2013/05/constructor-overloading/) - Like methods, constructors can also be overloaded. In this guide we will see Constructor overloading with the help of examples. Before we proceed further let's understand what is constructor overloading and why we do it. Constructor overloading is a concept of having more than one constructor with different parameters list, in such a way so - [100+ Core Java Interview Questions](https://beginnersbook.com/2013/05/java-interview-questions/) - Hi Friends, In this article, we have shared 100+ java interview questions for both beginners and experienced folks. If you are a java beginner, I highly recommend you to checkout my java tutorial. Table of Contents Basic Questions OOPs interview Questions Exception handling interview Questions Java Multithreading interview Questions Serialization interview Questions String Interview Questions - [JUnit (Java Unit Testing) interview questions and answers](https://beginnersbook.com/2013/10/junit-interview-questions-answers/) - Hello Guys, The below Junit interview questions and answers are for both freshers as well as for experienced folks. The reason behind this is that generally interviewers start with the basic questions (fresher level) and go for questions related to advanced topics ( experienced level) later. The whole FAQs are divided in two sections. This is the - [hybrid inheritance in java with example program](https://beginnersbook.com/2013/10/hybrid-inheritance-java-program/) - A hybrid inheritance is a combination of more than one types of inheritance. For example when class A and B extends class C & another class D extends class A then this is a hybrid inheritance, because it is a combination of single and hierarchical inheritance. Let me show you this diagrammatically: C ↑ | - [Hierarchical Inheritance in java with example program](https://beginnersbook.com/2013/10/hierarchical-inheritance-java-program/) - When more than one classes inherit a same class then this is called hierarchical inheritance. For example class B, C and D extends a same class A. Lets see the diagram representation of this: As you can see in the above diagram that when a class has more than one child classes (sub classes) or - [Convert ArrayList to Array in Java](https://beginnersbook.com/2013/12/how-to-convert-arraylist-to-string-array-in-java/) - In this tutorial, you will learn how to convert ArrayList to Array in Java. We will see two ways to do the conversion: In the first program, we will do the conversion without using any method. In the second program, we will use toArray() method of ArrayList class to do the conversion. Example 1: ArrayList - [How to Convert an array to ArrayList in java](https://beginnersbook.com/2013/12/how-to-convert-array-to-arraylist-in-java/) - In the last tutorial, you learned how to convert an ArrayList to Array in Java. In this guide, you will learn how to convert an array to ArrayList. Method 1: Conversion using Arrays.asList() Syntax: ArrayList arraylist= new ArrayList(Arrays.asList(arrayname)); Example: In this example, we are using Arrays.asList() method to convert an Array to ArrayList. Here, we - [How to sort ArrayList in descending order in Java](https://beginnersbook.com/2013/12/sort-arraylist-in-descending-order-in-java/) - In this tutorial, you will learn how to sort an ArrayList in descending order. Example 1: Sorting an ArrayList in Descending order We are using Collections.reverseOrder() method along with Collections.sort() in order to sort the list in decreasing order. In this example, we are using the following statement for sorting the list in reverse order. - [Multilevel inheritance in java with example](https://beginnersbook.com/2013/12/multilevel-inheritance-in-java-with-example/) - When a class extends a class, which extends anther class then this is called multilevel inheritance. For example class C extends class B and class B extends class A then this type of inheritance is known as multilevel inheritance. Lets see this in a diagram: It's pretty clear with the diagram that in Multilevel inheritance - [Java ArrayList of Object Sort Example (Comparable & Comparator)](https://beginnersbook.com/2013/12/java-arraylist-of-object-sort-example-comparable-and-comparator/) - In this tutorial, you will learn how to sort an ArrayList of Objects by property using comparable and comparator interface. If you are looking for sorting a simple ArrayList of String or Integer then you can refer the following tutorials - Sorting of ArrayList and ArrayList Sorting of ArrayList in descending order We generally use - [How to loop LinkedList in Java](https://beginnersbook.com/2013/12/how-to-loop-linkedlist-in-java/) - In the last tutorial we discussed LinkedList and it's methods with example. Here we will see how to loop/iterate a LinkedList. There are four ways in which a LinkedList can be iterated - For loop Advanced For loop Iterator While Loop Example: In this example we have a LinkedList of String Type and we are looping - [Difference between ArrayList and Vector in Java](https://beginnersbook.com/2013/12/difference-between-arraylist-and-vector-in-java/) - ArrayList and Vector both use Array as a data structure internally. However there are key differences between these classes. In this guide, you will learn the differences between ArrayList and Vector. ArrayList Vs Vector: Differences between them ArrayList Vector ArrayList is non-synchronized, which means multiple threads can work on ArrayList at the same time. For - [TreeMap in Java with Example](https://beginnersbook.com/2013/12/treemap-in-java-with-example/) - TreeMap is Red-Black tree based NavigableMap implementation. It is sorted according to the natural ordering of its keys. TreeMap class implements Map interface similar to HashMap class. The main difference between them is that HashMap is an unordered collection while TreeMap is sorted in the ascending order of its keys. TreeMap is unsynchronized collection class which means - [Copy Elements of One ArrayList to Another ArrayList in Java](https://beginnersbook.com/2013/12/how-to-copy-and-add-all-list-elements-to-arraylist-in-java/) - In this tutorial, we will write a java program to copy elements of one ArrayList to another ArrayList in Java. We will be using addAll() method of ArrayList class to do that. public boolean addAll(Collection c) When we call this method like this: newList.addAll(oldList); It appends all the elements of oldList to the newList. It - [ArrayList clone() method in Java](https://beginnersbook.com/2013/12/how-to-clone-an-arraylist-to-another-arraylist/) - In this tutorial, we will see examples of ArrayList clone() method. This method creates a shallow copy of an ArrayList. Syntax: newList = oldList.clone() Creates a shallow copy of oldList and assign it to newList. Example 1: Creating a copy of an ArrayList using clone() In this example, we have an ArrayList of String type - [How to get sublist of an ArrayList with example](https://beginnersbook.com/2013/12/how-to-get-sublist-of-an-arraylist-with-example/) - In this tutorial, we will see how to get a sublist from an existing ArrayList. We will be using the subList() method of ArrayList class. Syntax: List subList(int fromIndex, int toIndex) Here fromIndex is inclusive and toIndex is exclusive. There are few important points regarding this method which I have shared at the end of - [How to swap two elements in an ArrayList](https://beginnersbook.com/2013/12/how-to-swap-two-elements-in-an-arraylist/) - This tutorial will help you understand how to swap two elements in an ArrayList. We are using Collections.swap() method for swapping. public static void swap(List list, int i1, int i2) This method swaps the element of index i1 with the element of index i2. It throws IndexOutOfBoundsException - if either i1 or i2 is less than - [How to synchronize ArrayList in java with example](https://beginnersbook.com/2013/12/how-to-synchronize-arraylist-in-java-with-example/) - We have already discussed a bit about synchronization when we shared the tutorial on Vector vs ArrayList. As we are aware that ArrayList is non-synchronized and should not be used in multi-thread environment without explicit synchronization. This post is to discuss how to synchronize ArrayList in Java. There are two ways to synchronize explicitly: Using - [How to empty an ArrayList in Java](https://beginnersbook.com/2013/12/how-to-empty-an-arraylist-in-java/) - There are two ways to empty an ArrayList - By using ArrayList.clear() method or with the help of ArrayList.removeAll() method. Although both methods do the same task the way they empty the List is quite different. Lets see the below example first then we will see the implementation and difference between clear() and removeAll(). package beginnersbook.com; - [How to find length of ArrayList in Java](https://beginnersbook.com/2013/12/how-to-find-length-of-arraylist-in-java/) - You can find the length (or size) of an ArrayList in Java using size() method. The size() method returns the number of elements present in the ArrayList. Syntax of size() method: public int size() Program to find length of ArrayList using size() In this program, we are demonstrating the use of size() method. As you - [How to join/combine two ArrayLists in java](https://beginnersbook.com/2013/12/how-to-joincombine-two-arraylists-in-java/) - In this tutorial we will see how to join (or Combine) two ArrayLists in Java. We will be using addAll() method to add both the ArrayLists in one final ArrayList. Example: In this example we are merging two ArrayLists in one single ArrayList and then displaying the elements of final List. package beginnersbook.com; import java.util.ArrayList; - [Difference between ArrayList and HashMap in Java](https://beginnersbook.com/2013/12/difference-between-arraylist-and-hashmap-in-java/) - ArrayList and HashMap are two commonly used collection classes in Java. Even though both are the part of collection framework, the way they store and process the data is entirely different. In this post we will see the main differences between these two collections. ArrayList vs HashMap in Java 1) Implementation: ArrayList implements List Interface while - [How to serialize ArrayList in java](https://beginnersbook.com/2013/12/how-to-serialize-arraylist-in-java/) - ArrayList is serializable by default. This means you need not to implement Serializable interface explicitly in order to serialize an ArrayList. In this tutorial we will learn how to serialize and de-serialize an ArrayList. Example: Serialization: Run the below class and it will create a file myfile which will be having ArrayList object in form of Stream of - [How to override toString method for ArrayList in Java](https://beginnersbook.com/2013/12/how-to-override-tostring-method-for-arraylist-in-java/) - When we are dealing with ArrayList of Objects then it is must to Override the toString() method in order to get the output in desired format. In this tutorial we will see how to override the toString() method for ArrayList in Java. Example: We have two classes here "Student" and "Demo". Student class has only - [How to compare two ArrayList in Java](https://beginnersbook.com/2013/12/how-to-compare-two-arraylist-in-java/) - In this tutorial we will learn how to compare two ArrayList. We would be using contains() method for comparing two elements of different ArrayList. public boolean contains(Object o) It returns true if the list contains the Object o else it returns false. Example: In this example we have two ArrayList al1 and al2 of String type. - [LinkedHashMap in Java](https://beginnersbook.com/2013/12/linkedhashmap-in-java/) - LinkedHashMap is a Hash table and linked list implementation of the Map interface, with predictable iteration order. This implementation differs from HashMap in that it maintains a doubly-linked list running through all of its entries. This linked list defines the iteration ordering, which is normally the order in which keys were inserted into the map - [TreeSet Class in Java with example](https://beginnersbook.com/2013/12/treeset-class-in-java-with-example/) - TreeSet is similar to HashSet except that it sorts the elements in the ascending order while HashSet doesn't maintain any order. TreeSet allows null element but like HashSet it doesn't allow. Like most of the other collection classes this class is also not synchronized, however it can be synchronized explicitly like this: SortedSet s = - [LinkedHashSet Class in Java with Example](https://beginnersbook.com/2013/12/linkedhashset-class-in-java-with-example/) - Earlier we have shared tutorials on HashSet and TreeSet. LinkedHashSet is also an implementation of Set interface, it is similar to the HashSet and TreeSet except the below mentioned differences: HashSet doesn't maintain any kind of order of its elements. TreeSet sorts the elements in ascending order. LinkedHashSet maintains the insertion order. Elements gets sorted - [How to synchronize HashMap in Java with example](https://beginnersbook.com/2013/12/how-to-synchronize-hashmap-in-java-with-example/) - HashMap is a non-synchronized collection class. If we need to perform thread-safe operations on it then we must need to synchronize it explicitly. In this tutorial we will see how to synchronize HashMap. Example: In this example we have a HashMap it is having integer keys and String type values. In order to synchronize - [How to sort HashMap in Java by Keys and Values](https://beginnersbook.com/2013/12/how-to-sort-hashmap-in-java-by-keys-and-values/) - As we know that HashMap doesn't preserve any order by default. If there is a need we need to sort it explicitly based on the requirement. In this tutorial we will learn how to sort HashMap by keys using TreeMap and by values using Comparator. HashMap Sorting by Keys In this example we are sorting - [How to serialize HashMap in java](https://beginnersbook.com/2013/12/how-to-serialize-hashmap-in-java/) - HashMap class is serialized by default which means we need not to implement Serializable interface in order to make it eligible for Serialization. In this tutorial we will learn How to write HashMap object and it's content into a file and How to read the HashMap object from the file. Before I share the complete code - [How to loop HashMap in java](https://beginnersbook.com/2013/12/how-to-loop-hashmap-in-java/) - In this tutorial we will learn how to loop HashMap using following methods: For loop While loop + Iterator Example: In the below example we are iterating the HashMap using both the methods (for loop and while loop). In while loop we have used the iterator. package beginnersbook.com; import java.util.HashMap; import java.util.Map; import java.util.Iterator; public - [Java ArrayList add(int index, E element) example](https://beginnersbook.com/2013/12/java-arraylist-addint-index-e-element-example/) - Simple add() method is used for adding an element at the end of the list however there is another variant of add method which is used for adding an element to the specified index. public void add(int index, Object element) This method adds the element at the given index. Example package beginnersbook.com; import java.util.ArrayList; public - [Java ArrayList addAll(Collection c) Method example](https://beginnersbook.com/2013/12/java-arraylist-addallcollection-c-method-example/) - In this tutorial we will see the usage of addAll() method of java.util.ArrayList class. This method is used for adding all the elements of a list to the another list. public boolean addAll(Collection c) It adds all the elements of specified Collection c to the current list. Example In this example we are adding all - [Java ArrayList contains() Method example](https://beginnersbook.com/2013/12/java-arraylist-contains-method-example/) - ArrayList contains() method is used for checking the specified element existence in the given list. public boolean contains(Object element) It returns true if the specified element is found in the list else it gives false. Example Here we are testing the contains() method on two arraylists, First we have created an ArrayList of Strings, added - [Java ArrayList get() Method example](https://beginnersbook.com/2013/12/java-arraylist-get-method-example/) - ArrayList get(int index) method is used for fetching an element from the list. We need to specify the index while calling get method and it returns the value present at the specified index. public Element get(int index) This method throws IndexOutOfBoundsException if the index is less than zero or greater than the size of the - [Java ArrayList indexOf() Method example](https://beginnersbook.com/2013/12/java-arraylist-indexof-method-example/) - Java.util.ArrayList class method indexOf(Object o) is used to find out the index of a particular element in a list. Method indexOf() Signature public int indexOf(Object o) This method returns -1 if the specified element is not present in the list. ArrayList indexOf() Method example In the following example we have an arraylist of strings and - [Java ArrayList ensureCapacity() Method example](https://beginnersbook.com/2013/12/java-arraylist-ensurecapacity-method-example/) - ArrayList internally implements growable dynamic array which means it can increase and decrease its size automatically. If we try to add an element to a already full ArrayList then it automatically re-sized internally to accommodate the new element however sometimes its not a good approach. Consider a scenario when there is a need to add - [Java ArrayList lastIndexOf(Object 0bj) Method example](https://beginnersbook.com/2013/12/java-arraylist-lastindexofobject-0bj-method-example/) - The method lastIndexOf(Object obj) returns the index of last occurrence of the specified element in the ArrayList. It returns -1 if the specified element does not exist in the list. public int lastIndexOf(Object obj) This would return the index of last Occurrence of element Obj in the ArrayList. Example In the below example we have - [Java ArrayList remove(int index) Method example](https://beginnersbook.com/2013/12/java-arraylist-remove-method-example/) - Method remove(int index) is used for removing an element of the specified index from a list. It removes an element and returns the same. It throws IndexOutOfBoundsException if the specified index is less than zero or greater than the size of the list (index size of ArrayList). public Object remove(int index) Example package beginnersbook.com; import - [Java - private constructor example](https://beginnersbook.com/2013/12/java-private-constructor-example/) - The use of private constructor is to serve singleton classes. A singleton class is one which limits the number of objects creation to one. Using private constructor we can ensure that no more than one object can be created at a time. By providing a private constructor you prevent class instances from being created in - [Java - Constructor Chaining with example](https://beginnersbook.com/2013/12/java-constructor-chaining-with-example/) - Calling a constructor from the another constructor of same class is known as Constructor chaining. The real purpose of Constructor Chaining is that you can pass parameters through a bunch of different constructors, but only have the initialization done in a single place. This allows you to maintain your initializations from a single location, while - [Java - Constructor in Interface?](https://beginnersbook.com/2013/12/java-constructor-in-interface/) - This is a most frequently asked java interview question. The answer is No, interface cannot have constructors. In this post we will discuss why constructors are not allowed in interface? As we know that all the methods in interface are public abstract by default which means the method implementation cannot be provided in the interface - [Copy all the elements of one Vector to another Vector example](https://beginnersbook.com/2013/12/copy-all-the-elements-of-one-vector-to-another-vector-example/) - In this example we will see how to copy all the elements of a Vector to another Vector. This process replaces the existing elements of the second vector with the corresponding element of first vector. For e.g. If we are copying vector v1 to vector v2 then first element of v2 will be replaced by - [Java String charAt() Method example](https://beginnersbook.com/2013/12/java-string-charat-method-example/) - The Java String charAt(int index) method returns the character at the specified index in a string. The index value that we pass in this method should be between 0 and (length of string-1). For example: s.charAt(0) would return the first character of the string represented by instance s. Java String charAt method throws IndexOutOfBoundsException, if - [Java String compareToIgnoreCase() Method example](https://beginnersbook.com/2013/12/java-string-comparetoignorecase-method-example/) - The Java String compareToIgnoreCase() method compares two strings lexicographically and returns 0 if they are equal. As we know compareTo() method does the same thing, however there is a difference between these two methods. Unlike compareTo() method, the compareToIgnoreCase() method ignores the case (uppercase or lowercase) while comparing strings. Java String compareToIgnoreCase() Method Method Signature: - [Java String concat() Method example](https://beginnersbook.com/2013/12/java-string-concat-method-example/) - Java string concat() method concatenates multiple strings. This method appends the specified string at the end of the given string and returns the combined string. We can use concat() method to join more than one strings. The concat() method signature public String concat(String str) This method concatenates the string str at the end of the - [Java - String contentEquals() Method example](https://beginnersbook.com/2013/12/java-string-contentequals-method-example/) - The method contentEquals() compares the String with the String Buffer and returns a boolean value. It returns true if the String matches to the String buffer else it returns false. boolean contentEquals(StringBuffer sb) Example In this example we have two Strings and two String Buffers. We are comparing the Strings with String Buffers using the - [Java - String copyValueOf() Method example](https://beginnersbook.com/2013/12/java-string-copyvalueof-method-example/) - The method copyValueOf() is used for copying an array of characters to the String. The point to note here is that this method does not append the content in String, instead it replaces the existing string value with the sequence of characters of array. It has two variations: 1) static copyValueOf(char[] data): It copies the - [Java String endsWith() Method with example](https://beginnersbook.com/2013/12/java-string-endswith-method-example/) - Java String endsWith(String suffix) method checks whether the String ends with a specified suffix. This method returns a boolean value true or false. If the specified suffix is found at the end of the string then it returns true else it returns false. The endsWith() Method Signature: public boolean endsWith(String suffix) Java String endsWith() Method - [Java String equals() and equalsIgnoreCase() Methods example](https://beginnersbook.com/2013/12/java-string-equals-and-equalsignorecase-methods-example/) - In this tutorial we will discuss equals() and equalsIgnoreCase() methods. Both of these methods are used for comparing two strings. The only difference between them is that the equals() methods considers the case while equalsIgnoreCase() methods ignores the case during comparison. For e.g. The equals() method would return false if we compare the strings "TEXT" - [Java String lastIndexOf() Method with example](https://beginnersbook.com/2013/12/java-string-lastindexof-method-example/) - In the last tutorial we discussed indexOf() method, which is used to find out the occurrence of a specified char or a substring in the given String. In this tutorial we will discuss lastIndexOf() method which is used to find out the index of last occurrence of a character or a substring in a given - [Java String length() Method with examples](https://beginnersbook.com/2013/12/java-string-length-method-example/) - Java String length() method is used to find out the length of a String. This method counts the number of characters in a String including the white spaces and returns the count. Java String length() Method int length() This method returns an integer number which represents the number of characters (length) in a given string - [Java - String toLowerCase() and toUpperCase() Methods](https://beginnersbook.com/2013/12/java-string-tolowercase-method-example/) - The method toLowerCase() converts the characters of a String into lower case characters. It has two variants: String toLowerCase(Locale locale): It converts the string into Lowercase using the rules defined by specified Locale. String toLowerCase(): It is equivalent to toLowerCase(Locale.getDefault()). Locale.getDefault() gets the current value of the default locale for this instance of the Java - [Java - String getChars() Method example](https://beginnersbook.com/2013/12/java-string-getchars-method-example/) - The method getChars() is used for copying String characters to an Array of chars. public void getChars(int srcBegin, int srcEnd, char[] dest, int destBegin) Parameters description: srcBegin - index of the first character in the string to copy. srcEnd - index after the last character in the string to copy. dest - Destination array of - [Java - String getBytes() Method example](https://beginnersbook.com/2013/12/java-string-getbytes-method-example/) - The getBytes() method encodes a given String into a sequence of bytes and returns an array of bytes. The method can be used in below two ways: public byte[] getBytes(String charsetName): It encodes the String into sequence of bytes using the specified charset and return the array of those bytes. It throws UnsupportedEncodingException - If the specified - [Java - String toCharArray() Method example](https://beginnersbook.com/2013/12/java-string-tochararray-method-example/) - The method toCharArray() returns an Array of chars after converting a String into sequence of characters. The returned array length is equal to the length of the String and the sequence of chars in Array matches the sequence of characters in the String. public char[] toCharArray() Example: toCharArray() method In this example we are converting - [Java - String matches() Method example](https://beginnersbook.com/2013/12/java-string-matches-method-example/) - Method matches() checks whether the String is matching with the specified regular expression. If the String fits in the specified regular expression then this method returns true else it returns false. Below is the syntax of the method: public boolean matches(String regex) It throws PatternSyntaxException - if the specified regular expression is not valid. Example: matches() method - [Java Convert String to Double examples](https://beginnersbook.com/2013/12/how-to-convert-string-to-double-in-java/) - In this guide we will see how to convert String to Double in Java. There are three ways to convert String to double. 1. Java - Convert String to Double using Double.parseDouble(String) method 2. Convert String to Double in Java using Double.valueOf(String) 3. Java Convert String to double using the constructor of Double class - - [How To Convert InputStream To String In Java](https://beginnersbook.com/2013/12/how-to-convert-inputstream-to-string-in-java/) - Here is the complete example of how to read and convert an InputStream to a String. The steps involved are: 1) I have initialized the InputStream after converting the file content to bytes using getBytes() method and then using the ByteArrayInputStream which contains an internal buffer that contains bytes that may be read from the - [How to create a File in Java](https://beginnersbook.com/2014/01/how-to-create-a-file-in-java/) - In this tutorial we will see how to create a file in Java using createNewFile() method. This method creates an empty file, if the file doesn't exist at the specified location and returns true. If the file is already present then this method returns false. It throws: IOException - If an Input/Output error occurs during file - [How to read file in Java – BufferedInputStream](https://beginnersbook.com/2014/01/how-to-read-file-in-java-bufferedinputstream/) - In this example we will see how to read a file in Java using FileInputStream and BufferedInputStream. Here are the detailed steps that we have taken in the below code: 1) Created a File instance by providing the full path of the file(which we will read) during File Object creation. 2) Passed the file instance - [How to read file in Java using BufferedReader](https://beginnersbook.com/2014/01/how-to-read-file-in-java-using-bufferedreader/) - In this tutorial we will see two ways to read a file using BufferedReader. Method 1: Using readLine() method of BufferedReader class. public String readLine() throws IOException It reads a line of text. Method 2: Using read() method public int read() throws IOException It reads a character of text. Since it returns an integer value, - [How to write to a file in java using FileOutputStream](https://beginnersbook.com/2014/01/how-to-write-to-a-file-in-java-using-fileoutputstream/) - Earlier we saw how to create a file in Java. In this tutorial we will see how to write to a file in java using FileOutputStream. We would be using write() method of FileOutputStream to write the content to the specified file. Here is the signature of write() method. public void write(byte[] b) throws IOException - [How to write to file in Java using BufferedWriter](https://beginnersbook.com/2014/01/how-to-write-to-file-in-java-using-bufferedwriter/) - Earlier we discussed how to write to a file using FileOutputStream. In this tutorial we will see how to write to a file using BufferedWriter. We will be using write() method of BufferedWriter to write the text into a file. The advantage of using BufferedWriter is that it writes text to a character-output stream, buffering - [Method overriding in java with example](https://beginnersbook.com/2014/01/method-overriding-in-java-with-example/) - Declaring a method in sub class which is already present in parent class is known as method overriding. Overriding is done so that a child class can give its own implementation to a method which is already provided by the parent class. In this case the method in parent class is called overridden method and - [Difference between method Overloading and Overriding in java](https://beginnersbook.com/2014/01/difference-between-method-overloading-and-overriding-in-java/) - In this tutorial we will discuss the difference between overloading and overriding in Java. If you are new to these terms then refer the following posts: Method overloading in java Method overriding in java Overloading vs Overriding in Java Overloading happens at compile-time while Overriding happens at runtime: The binding of overloaded method call to - [Exception handling in Method overriding with example](https://beginnersbook.com/2014/01/exception-handling-in-method-overriding-with-example/) - In the last post we discussed about method overriding. In this post we will see how to do exception handling for overriding and overridden methods. Rule: An overriding method (the method of child class) can throw any unchecked exceptions, regardless of whether the overridden method (method of base class) throws exceptions or not. However the - [Java - Get time in milliseconds using Date, Calendar and ZonedDateTime](https://beginnersbook.com/2014/01/how-to-get-time-in-milliseconds-in-java/) - In this tutorial we will see how to get current time or given time in milliseconds in Java. There are three ways to get time in milliseconds in java. 1) Using public long getTime() method of Date class. 2) Using public long getTimeInMillis() method of Calendar class 3) Java 8 - ZonedDateTime.now().toInstant().toEpochMilli() returns current time - [How to get current timestamp in java](https://beginnersbook.com/2014/01/how-to-get-current-timestamp-in-java/) - Its quite easy to get the current timestamp in java. In this tutorial we will see how to get the timestamp using Date and Timestamp class. Here are the steps that we have followed in the below example: 1) Created the object of Date class. 2) Got the current time in milliseconds by calling getTime() - [Polymorphism in Java with example](https://beginnersbook.com/2013/03/polymorphism-in-java/) - Polymorphism is one of the OOPs feature that allows us to perform a single action in different ways. For example, lets say we have a class Animal that has a method sound(). Since this is a generic class so we can't give it a implementation like: Roar, Meow, Oink etc. We had to give a generic - [Basics: All about Java threads](https://beginnersbook.com/2013/03/java-threads/) - What are Java Threads? A thread is a: Facility to allow multiple activities within a single process Referred as lightweight process A thread is a series of executed statements Each thread has its own program counter, stack and local variables A thread is a nested sequence of method calls Its shares memory, files and per-process - [Thread life cycle in java and thread scheduling](https://beginnersbook.com/2013/03/thread-life-cycle-in-java/) - In previous post I have covered almost all the terms related to Java threads. Here we will learn Thread life cycle in java, we'll also see thread scheduling. Recommended Reads: Multithreading in Java Thread Life cycle in Java The start method creates the system resources, necessary to run the thread, schedules the thread to run, - [Types of polymorphism in java- Runtime and Compile time polymorphism](https://beginnersbook.com/2013/04/runtime-compile-time-polymorphism/) - In the last tutorial we discussed Polymorphism in Java. In this guide we will see types of polymorphism. There are two types of polymorphism in java: 1) Static Polymorphism also known as compile time polymorphism 2) Dynamic Polymorphism also known as runtime polymorphism Compile time Polymorphism (or Static polymorphism) Polymorphism that is resolved during compiler - [Nested try catch block in Java - Exception handling](https://beginnersbook.com/2013/04/nested-try-catch/) - When a try catch block is present in another try block then it is called the nested try catch block. Each time a try block does not have a catch handler for a particular exception, then the catch blocks of parent try block are inspected for that exception, if match is found that that catch - [Java Finally block - Exception handling](https://beginnersbook.com/2013/04/java-finally-block/) - In the previous tutorials I have covered try-catch block and nested try block. In this guide, we will see finally block which is used along with try-catch. A finally block contains all the crucial statements that must be executed whether exception occurs or not. The statements present in this block will always execute regardless of - [How to throw exception in java with example](https://beginnersbook.com/2013/04/throw-in-java/) - In Java we have already defined exception classes such as ArithmeticException, NullPointerException, ArrayIndexOutOfBounds exception etc. These exceptions are set to trigger on different-2 conditions. For example when we divide a number by zero, this triggers ArithmeticException, when we try to access the array element out of its bounds then we get ArrayIndexOutOfBoundsException. We can define - [Difference between throw and throws in java](https://beginnersbook.com/2013/04/difference-between-throw-and-throws-in-java/) - In this guide, we will discuss the difference between throw and throws keywords. Before going though the difference, refer my previous tutorials about throw and throws. Throw vs Throws in java 1. Throws clause is used to declare an exception, which means it works similar to the try-catch block. On the other hand throw keyword - [User defined exception in java](https://beginnersbook.com/2013/04/user-defined-exception-in-java/) - In java we have already defined, exception classes such as ArithmeticException, NullPointerException etc. These exceptions are already set to trigger on pre-defined conditions such as when you divide a number by zero it triggers ArithmeticException, In the last tutorial we learnt how to throw these exceptions explicitly based on your conditions using throw keyword. In - [Java Date Format examples](https://beginnersbook.com/2013/04/java-date-format/) - Java DateFormat class is an abstract class. This class provides various methods to format the date and time. In this guide, we will see the several examples of DateFormat class and later I will list down the methods and fields of this class. There is another class SimpleDateFormat that is used for the same purpose - [Convert String to date in Java](https://beginnersbook.com/2013/04/java-string-to-date-conversion/) - In this tutorial we will see how to convert a String to Date in Java. Convert String to Date: Function After this section I have shared a complete example to demonstrate String to Date conversion in various date formats. For those who just want a function for this conversion, here is the function code: public - [Java - Calculate number of days between two dates](https://beginnersbook.com/2013/04/number-of-days-calculation-between-two-dates/) - In this tutorial we will see how to calculate the number of days between two dates. Program to find the number of Days between two Dates In this program we have the dates as Strings. We first parses them into Dates and then finds the difference between them in milliseconds. Later we are convert the - [How to get the previous & next day date from a given date in Java](https://beginnersbook.com/2013/04/get-the-previous-day-date-and-next-day-date-from-the-given-date/) - This tutorial is divided into three sections as follows: 1) Calculate the number of days between two dates 2) Get the previous day date and the next day date from the given date 3) Compare two dates with each other You're reading part 2 pf above mentioned tutorials: Here we are providing an input date in - [Compare two dates with each other in Java](https://beginnersbook.com/2013/04/dates-comparison-in-java/) - This tutorial is divided into three sections as follows: 1) Calculate the number of days between two dates 2) Get the previous day date and the next day date from the given date 3) Compare two dates with each other You're reading part 3 of above mentioned tutorials: In the below example we are providing the - [Java date difference](https://beginnersbook.com/2013/04/java-date-difference/) - Most of the Java application involves date format data and related computations. Calculating difference between two date values is one of the important and frequently performed operation. Following code shows how we can obtain difference between two date values. We will check if the date difference between provided two dates is more than 30 months. - [Types of inheritance in Java: Single,Multiple,Multilevel & Hybrid](https://beginnersbook.com/2013/05/java-inheritance-types/) - Below are Various types of inheritance in Java. We will see each one of them one by one with the help of examples and flow diagrams. 1) Single Inheritance Single inheritance is damn easy to understand. When a class extends another one class only then we call it a single inheritance. The below flow diagram - [Does Java support Multiple inheritance?](https://beginnersbook.com/2013/05/java-multiple-inheritance/) - When one class extends more than one classes then this is called multiple inheritance. For example: Class C extends class A and B then this type of inheritance is known as multiple inheritance. Java doesn't allow multiple inheritance. In this article, we will discuss why java doesn't allow multiple inheritance and how we can use - [Date comparison in java: compare two dates of different formats](https://beginnersbook.com/2013/05/java-date-comparison/) - While developing an application there are certain scenarios where you may need to compare two dates which are in different format. Here I am sharing a code which compares two provided dates which can be in any format. As you can see in the below example that we have created a method where you need - [Java SimpleDateFormat Class explained with examples](https://beginnersbook.com/2013/05/simple-date-format-java/) - Java SimpleDateFormat class is used for formatting date and time. In the previous tutorial we have seen the examples of DateFormat class which is also used for the same purpose, the SimpleDateFormat class is a sub class of DateFormat class. In this guide, we will see how to format date and time using this class, - [Date validation in java](https://beginnersbook.com/2013/05/java-date-validation/) - This purpose of this post is to provide step-by-step guidance to develop a utility that will have the following functionality: 1) This utility will help to validate a date format entered by the user. 2) If the user entered data is valid then it will be convertible to a format that can be easily inserted - [Convert Date to String in Java](https://beginnersbook.com/2013/05/java-date-string-conversion/) - Earlier we saw, how to convert String to Date in Java. This post is a continuation of that post and here we will learn Date to String conversion in Java. Java Code: Convert Date to String in Java After this section I have shared a complete code of Date to String conversion. The below function - [Java Date Validation Example](https://beginnersbook.com/2013/05/java-date-format-validation/) - In this tutorial, we will see how to validate a date to check whether it is in valid format or not. Java Date Validation: Checks whether a Date is valid or not In this example, we are checking whether a given date is valid or not. In the method validateJavaDate(String) we have specified the date - [Java calendar class: add/subtract Year, months, days, hour, minutes](https://beginnersbook.com/2013/05/java-calendar-class/) - Java’s Calendar class provides a set of methods for manipulation of temporal information. In addition to fetch the system’s current date and time, it also enables functionality for date and time arithmetic. Adding Time Period (Months and days) to a Date Suppose you want to add a time period to a date. How will you - [Date Formatting In Java With Time Zone](https://beginnersbook.com/2013/05/java-date-timezone/) - This tutorial will help you getting the current time, date and day in any given format for any particular time zone in java. Listed below are some IDs for some common Time zones in the US: Time Zone Java Time Zone ID Hawaiian Standard Time US/Hawaii Alaska Standard Time US/Alaska Pacific Standard Time US/Pacific Mountain - [How to Parse Date in Desired format - Java Date](https://beginnersbook.com/2013/05/java-parse-date/) - This post is to discuss few important points about parse() method. If you are looking for String to Date and Date to String conversion then refer the following posts: Convert String to Date in Java Convert Date to String in Java Converting strings to desired date format is a time consuming and tedious process in - [Java date](https://beginnersbook.com/2013/05/java-date/) - In java, we have several classes to handle and perform date and time operations. These operations can be performed on date, time or timezone. In this guide, I have provided the links to all the tutorials and Java 8 date time API guides collection. Java 8 Date/Time API java.time.LocalTime classjava.time.LocalDate classjava.time.LocalDateTime classjava.time.ZoneId classjava.time.ZonedDateTime classjava.time.ZoneOffset classjava.time.OffsetTime - [OOPs concepts - What is Aggregation in java?](https://beginnersbook.com/2013/05/aggregation/) - Aggregation is a special form of association. It is a relationship between two classes like association, however its a directional association, which means it is strictly a one way association. It represents a HAS-A relationship. Aggregation Example in Java For example consider two classes Student class and Address class. Every student has an address so - [Java Access Modifiers - Public, Private, Protected & Default](https://beginnersbook.com/2013/05/java-access-modifiers/) - You must have seen public, private and protected keywords while practising java programs, these are called access modifiers. An access modifier restricts the access of a class, constructor, data member and method in another class. In java we have four access modifiers: 1. default 2. private 3. protected 4. public 1. Default access modifier When - [Difference Between Abstract Class and Interface in Java](https://beginnersbook.com/2013/05/abstract-class-vs-interface-in-java/) - In this article, we will discuss the difference between Abstract Class and Interface in Java with examples. I have covered the abstract class and interface in separate tutorials of OOPs Concepts so I would recommend you to read them first, before going though the differences. 1. Abstract class in java 2. Interface in Java Abstract Class - [How to get current date and time in java](https://beginnersbook.com/2013/05/current-date-time-in-java/) - By using SimpleDateFormat and Date/Calendar class, we can easily get current date and time in Java. In this tutorial we will see how to get the current date and time using Date and Calendar class and how to get it in the desired format using SimpleDateFormat class. Current date and time in Java - Two - [Java finally block when return statement is encountered](https://beginnersbook.com/2013/05/java-finally-return/) - In my last tutorial, we discussed about finally block, which is used with a try block and always execute whether exception occurs or not. Here we will see few examples to understand the behaviour of finally block when a return statement is encountered in try block. Lets see this code snippet, What do you think? - [Java - static variable with example](https://beginnersbook.com/2013/05/static-variable/) - A static variable is common to all the instances (or objects) of the class because it is a class level variable. In other words you can say that only a single copy of static variable is created and shared among all the instances of the class. Memory allocation for such variables only happens once when - [Java static constructor - Is it really Possible to have them in Java?](https://beginnersbook.com/2013/05/static-constructor/) - Have you heard of static constructor in Java? I guess yes but the fact is that they are not allowed in Java. A constructor can not be marked as static in Java. Before I explain the reason let's have a look at the following piece of code: public class StaticTest { /* See below - I - [Java static import with example](https://beginnersbook.com/2013/05/java-static-import/) - Static import allows you to access the static member of a class directly without using the fully qualified name. To understand this topic, you should have the knowledge of packages in Java. Static imports are used for saving your time by making you type less. If you hate to type same thing again and again - [Abstract Class in Java with example](https://beginnersbook.com/2013/05/java-abstract-class-method/) - A class that is declared using "abstract" keyword is known as abstract class. It can have abstract methods(methods without body) as well as concrete methods (regular methods with body). A normal class(non-abstract class) cannot have abstract methods. In this guide we will learn what is a abstract class, why we use it and what are - [Interface in java with example programs](https://beginnersbook.com/2013/05/java-interface/) - In the last tutorial we discussed abstract class which is used for achieving partial abstraction. Unlike abstract class an interface is used for full abstraction. Abstraction is a process where you show only "relevant" data and "hide" unnecessary details of an object from the user(See: Abstraction). In this guide, we will cover what is an - [How to Catch multiple exceptions](https://beginnersbook.com/2013/05/catch-multiple-exceptions/) - In the previous tutorial, I have covered how to handle exceptions using try-catch blocks. In this guide, we will see how to handle multiple exceptions and how to write them in a correct order so that user gets a meaningful message for each type of exception. Catching multiple exceptions Lets take an example to understand - [Java Virtual Machine (JVM)](https://beginnersbook.com/2013/05/jvm/) - Java is a high level programming language. A program written in high level language cannot be run on any machine directly. First, it needs to be translated into that particular machine language. The javac compiler does this thing, it takes java program (.java file containing source code) and translates it into machine code (referred as - [Servlet interview questions and answers](https://beginnersbook.com/2013/05/servlet-interview-questions/) - Here are the frequently asked questions on Servlets. I have provided the brief and to the point answer of each question which will help you get selected in the the technical interview round. Q 1. What is servlet? Servlet is a server side programming language which is used for generating dynamic web pages. It generates - [JDBC(Java Database Connectivity) interview questions](https://beginnersbook.com/2013/05/jdbc-interview-questions/) - Q) What is JDBC (Java Database Connectivity)? JDBC is Java Database Connectivity. It allows you to have a single API for connecting to, manipulating, and retrieving information from a multiple Databases like MySQL, Oracle, DB2, etc. Q) What is JDBC Driver ? JDBC driver is used to established a connection with the database so that you can - [JUnit (Java Unit Testing) interview questions](https://beginnersbook.com/2013/05/junit-interview-questions/) - This is Part 2 of Q&A. Read first part here - JUnit (Java Unit Testing) interview questions and answers - Part1. Question1: What is Junit? Answer: Java + unit testing = Junit Junit is open source testing framework developed for unit testing java code and is now the default framework for testing Java development. It has - [Servlet Tutorial for beginners](https://beginnersbook.com/2013/05/servlet-tutorial/) - Next ❯ Servlet is a java program that runs inside JVM on the web server. It is used for developing dynamic web applications. Before we proceed further lets understand what is dynamic web application? A web application can be described as collection of web pages (e.g. a website) and when we call it dynamic, it - [Servlet Architecture: Basics of Servlets](https://beginnersbook.com/2013/05/servlet-architecture/) - A Servlet is a class, which implements the javax.servlet.Servlet interface. However instead of directly implementing the javax.servlet.Servlet interface we extend a class that has implemented the interface like javax.servlet.GenericServlet or javax.servlet.http.HttpServlet. Servlet Exceution This is how a servlet execution takes place when client (browser) makes a request to the webserver. Servlet architecture includes: a) Servlet Interface To - [Servlet Class Hierarchy](https://beginnersbook.com/2013/05/servlet-class-hierarchy/) - The Servlet interface is the root interface of the servlet class hierarchy. All Servlets need to either directly or indirectly implement the Servlet interface. The GenericServlet class of the Servlet API implements the Servlet interface. In addition to the Servlet interface, the GenericServlet class implements the ServletConfig interface of the Servlet API and the Serializable - [How to create and run Servlet in Eclipse IDE](https://beginnersbook.com/2017/07/how-to-create-and-run-servlet-in-eclipse-ide/) - ❮ PreviousNext ❯ This is a complete guide for installing Eclipse, setting up apache tomcat server and running your first hello world servlet application. Download Eclipse IDE Install Eclipse on Windows Go to this link https://www.eclipse.org/downloads. Under "Get Eclipse Oxygen" ❯ Click "Download Packages"❯ Download "Eclipse IDE for Java Developers". You would see two options - [W3 total cache plugin settings to speed up website](https://beginnersbook.com/2013/01/w3-total-cache-plugin-settings-speed-up-website/) - Hi All, I believe you already know that Google considers more than 200 signals, while determining ranking of a webpage for particular keyword and website speed is one of them. yes you heard it right, Google is more concerned about website speed. As per Google faster sites create happy user and if the site is - [Yet Another Related Posts Plugin (YARPP) for WordPress](https://beginnersbook.com/2013/09/related-posts-plugin-yarpp-wordpress/) - YARPP ( Yet another related Posts plugin) is one of the best WordPress plugin for displaying related posts on your blog. We have already mentioned it in our list of best related posts plugin. There are number of WordPress plugins which does this task pretty well but here we are gonna see how it is - [Fix YARPP Issues by using YARPP Experiments Plugin](https://beginnersbook.com/2013/10/yarpp-experiments-plugin/) - Earlier we shared about YARPP plugin, which is one of the best plugin for displaying related posts on your WordPress blog. This post is to discuss about another useful plugin by mitcho (Michael Yoshitaka Erlewine) called YARPP experiments. Download Links: Download YARPP Plugin Download YARPP Experiments Below are the few features of this plugin, which can - [SQL - CREATE TABLE Statement](https://beginnersbook.com/2014/05/sql-create-table-statement/) - CREATE TABLE statement is used for creating tables in a database. Tables are organized in rows and columns. Where columns are the attributes and rows are known as records. Syntax: CREATE TABLE tableName ( columnName_1 data_type, columnName_2 data_type, columnName_3 data_type, columnName_4 data_type, .... .... PRIMARY KEY (Column_Name(s)) ); CREATE TABLE Example SQL> CREATE TABLE EMPLOYEES( - [SQL - DROP Table Statement to delete the entire table](https://beginnersbook.com/2014/05/sql-drop-table-statement-to-delete-the-entire-table/) - The DROP TABLE statement is used for deleting an entire table. This statement deletes the table definition, data, constraints and all the info that is associated or stored in table. Syntax: DROP TABLE TableName; For e.g. Lets say we have a table named "EMPLOYEES". This is how we can see the table definition. SQL> DESC - [UPDATE Query in SQL](https://beginnersbook.com/2014/05/update-query-in-sql/) - Update Query is used for updating existing rows(records) in a table. In last few tutorials we have seen how to insert data in table using INSERT query and how to fetch the data using SELECT Query and Where clause. What if we want to update an exiting record? this is where update query comes into - [DELETE Query in SQL](https://beginnersbook.com/2014/05/delete-query-in-sql/) - Delete Query is used for deleting the existing rows(records) from table. Generally DELETE query is used along with WHERE clause to delete the certain number of rows that fulfills the specified condition. However DELETE query can be used without WHERE clause too, in that case the query would delete all the rows of specified table. - [LIKE Clause in SQL](https://beginnersbook.com/2014/05/like-clause-in-sql/) - Like clause is used for fetching similar values from table(s). For e.g. you may want to fetch all the names from a table that starts with alphabet "A" and ends with alphabet "X", in such case you can use like clause in SQL query. In this tutorial we will see variations and use of Like - [Group By clause in SQL](https://beginnersbook.com/2014/05/group-by-clause-in-sql/) - Group by clause is used for grouping the similar data after fetching it from tables(s). In this tutorial we will learn how to use GROUP BY clause in SQL. Syntax SELECT column_name1, column_name2,... FROM TableName WHERE clause GROUP BY column_namei, column_namej...; Example Lets say this is my "EMPLOYEE_DETAILS" table. As you can see it has - [NOT NULL Constraint in SQL](https://beginnersbook.com/2014/05/not-null-constraint-in-sql/) - NOT NULL constraint makes sure that a column does not hold NULL value. When we don't provide value for a particular column while inserting a record into a table, by default it takes NULL value. By specifying NULL constraint, we can be sure that a particular column(s) cannot have NULL values. How to specify the - [DEFAULT Constraint in SQL](https://beginnersbook.com/2014/05/default-constraint-in-sql/) - The DEFAULT constraint provides a default value to a column when there is no value provided while inserting a record into a table. Lets see how to specify this constraint and how it works. Specify DEFAULT constraint while creating a table Here we are creating a table "STUDENTS", we have a requirement to set the - [UNIQUE Constraint in SQL](https://beginnersbook.com/2014/05/unique-constraint-in-sql/) - UNIQUE Constraint enforces a column or set of columns to have unique values. If a column has a Unique constraint, it means that particular column cannot have duplicate values in a table. Set UNIQUE Constraint while creating a table For SQL Server / MS Access / Oracle: Syntax: CREATE TABLE ( UNIQUE, - [Installing Perl on Windows, Mac, Linux and Unix](https://beginnersbook.com/2017/02/installing-perl-on-windows-mac-linux-and-unix/) - In most of the cases, you have it already installed on your System as several Operating systems have it pre-installed. To check whether you have it on your system, you can go to command prompt (terminal in mac) and type "perl -v" without quotes. If you have it on your system then you should see - [Data Types in Perl](https://beginnersbook.com/2017/02/data-types-in-perl/) - Perl has three data types: Scalars, arrays of scalars and hashes (also known as associative arrays, dictionaries or maps). In perl we need not to specify the type of data, the interpreter would choose it automatically based on the context of data. For e.g. In the following code, I am assigning an integer and a - [Perl Variables](https://beginnersbook.com/2017/02/perl-variables/) - There are three types of variables in perl: Scalar, arrays of scalars and hashes. Lets learn them one by one with the help of examples. Scalars Scalars are single data unit. A scalar can be integer, float, string etc. Scalar variables are prefixed with "$" sign. Lets have a look at the following perl script - [Perl Operators - Complete guide](https://beginnersbook.com/2017/02/perl-operators-complete-guide/) - An operator is a character that represents an action, for example + is an arithmetic operator that represents addition. Operators in perl are categorised as following types: 1) Basic Arithmetic Operators 2) Assignment Operators 3) Auto-increment and Auto-decrement Operators 4) Logical Operators 5) Comparison operators 6) Bitwise Operators 7) Quote and Quote-like Operators 1) Basic - [While loop in Perl with example](https://beginnersbook.com/2017/02/while-loop-in-perl-with-example/) - In the last tutorial, we discussed for loop in Perl. In this tutorial we will discuss while loop. As discussed in previous tutorial, loops are used to execute a set of statements repeatedly until a particular condition is satisfied. Syntax of while loop: while(condition) { statement(s); } Flow of Execution of the while Loop In - [Perl - do-while loop with example](https://beginnersbook.com/2017/02/perl-do-while-loop-with-example/) - In the last tutorial, we discussed while loop. In this tutorial we will discuss do-while loop in Perl. do-while loop is similar to while loop, however there is a difference between them: In while loop, condition is evaluated before the execution of loop's body but in do-while loop condition is evaluated after the execution of - [Perl - foreach loop with example](https://beginnersbook.com/2017/02/perl-foreach-loop-with-example/) - The foreach loop is used for iterating arrays/lists. Syntax of foreach loop: foreach var (list) { statement(s); } Flow of Execution of the foreach Loop In foreach loop, the loop continues execution until all the elements of the specified array gets processed. Example #!/usr/local/bin/perl @friends = ("Ajeet", "Tom", "Steve", "Lisa", "Kev"); foreach $str (@friends){ print - [Until loop in Perl with example](https://beginnersbook.com/2017/02/until-loop-in-perl-with-example/) - Until loop behaves just opposite to the while loop in perl, while loop continues execution as long as the condition is true. In until loop, the loop executes as long as the condition is false. Syntax of until loop: until(condition) { statement(s); } Flow of Execution of the until Loop The condition is evaluated first, - [JSP Actions - Java Server Pages](https://beginnersbook.com/2013/06/jsp-tutorial-actions/) - JSP Actions lets you perform some action. Directives vs Actions Directives are used during translation phase while actions are used during request processing phase. Unlike Directives Actions are re-evaluated each time the page is accessed. The following are the action elements used in JSP: 1. Action Like include page directive this action is also used - [jsp:useBean, jsp:setProperty and jsp:getProperty Action Tags](https://beginnersbook.com/2013/11/jsp-usebean-setproperty-getproperty-action-tags/) - In this tutorial we will see how to use a bean class in JSP with the help of jsp:useBean, jsp:setProperty and jsp:getProperty action tags. Syntax of jsp:useBean: Syntax of jsp:setProperty: Syntax of jsp:getProperty: A complete example of useBean, setProperty and getProperty 1) We - [Exception handling in JSP](https://beginnersbook.com/2013/11/jsp-exception-handling/) - Before going through exception handling in JSP, let's understand what is exception and how it is different from errors. Exception: These are nothing but the abnormal conditions which interrupts the normal flow of execution. Mostly they occur because of the wrong data entered by user. It is must to handle exceptions in order to give meaningful - [JSP Expression Language (EL) - JSP Tutorial](https://beginnersbook.com/2013/11/jsp-expression-language-el/) - Expression language (EL) has been introduced in JSP 2.0. The main purpose of it to simplify the process of accessing data from bean properties and from implicit objects. EL includes arithmetic, relational and logical operators too. Synatx of EL: ${expression} whatever present inside braces gets evaluated at runtime and being sent to the output stream. - [JSP include action with parameter example](https://beginnersbook.com/2013/12/jsp-include-with-parameter-example/) - Earlier we have shared how to include a page to another JSP page using include directive and include action tag. We have also discussed the difference between include directive and include action tag. In this post we will see how to pass parameters to included page while using jsp include action tag (). In order - [JSP include directive with parameters example](https://beginnersbook.com/2013/12/jsp-include-directive-with-parameters-example/) - In the last tutorial we discussed JSP include action with parameters. Here we will see how to pass parameters when using JSP include directive. Example In this example we are passing three string parameters to the included JSP page. index.jsp Passing Parameters to Include directive - [How to validate and invalidate session in JSP](https://beginnersbook.com/2013/12/how-to-validate-and-invalidate-session-in-jsp/) - We have already seen invalidate() method in session implicit object tutorial. In this post we are going to discuss it in detail. Here we will see how to validate/invalidate a session. Example Lets understand this with the help of an example: In the below example we have three jsp pages. index.jsp: It is having four - [JSP Custom tags with example - JSP Tutorial](https://beginnersbook.com/2014/01/jsp-custom-tags-with-example-jsp-tutorial/) - User-defined tags are known as custom tags. In this tutorial we will see how to create a custom tag and use it in JSP. To create a custom tag we need three things: 1) Tag handler class: In this class we specify what our custom tag will do when it is used in a JSP - [How to access body of Custom tags in JSP tutorial](https://beginnersbook.com/2014/01/how-to-access-body-of-custom-tags-in-jsp-tutorial/) - In the last tutorial we learnt how to create and use custom tags in JSP. In this tutorial we will see how to access the body of custom tag. For e.g. If our custom tag is xyz then we would learn to access the content between and Body of custom - [Java program to calculate area of Triangle](https://beginnersbook.com/2014/01/java-program-to-calculate-area-of-triangle/) - Here we will see how to calculate area of triangle. We will see two following programs to do this: 1) Program 1: Prompt user for base-width and height of triangle. 2) Program 2: No user interaction: Width and height are specified in the program itself. Program 1: /** * @author: BeginnersBook.com * @description: Program to - [Java program to calculate area of Square](https://beginnersbook.com/2014/01/java-program-to-calculate-area-of-square/) - In this tutorial we will learn how to calculate area of Square. Following are the two ways to do it: 1) Program 1: Prompting user for entering the side of the square 2) Program 2: Side of the square is specified in the program' s source code. Program 1: /** * @author: BeginnersBook.com * @description: - [Java Program to Calculate Area of Rectangle](https://beginnersbook.com/2014/01/java-program-to-calculate-area-of-rectangle/) - In this tutorial we will see how to calculate Area of Rectangle. Program 1: User would provide the length and width values during execution of the program and the area would be calculated based on the provided values. /** * @author: BeginnersBook.com * @description: Program to Calculate Area of rectangle */ import java.util.Scanner; class AreaOfRectangle - [Java program to sum the elements of an array](https://beginnersbook.com/2014/01/java-program-to-sum-the-elements-of-an-array/) - In this tutorial we will see how to sum up all the elements of an array. Program 1: No user interaction /** * @author: BeginnersBook.com * @description: Get sum of array elements */ class SumOfArray{ public static void main(String args[]){ int[] array = {10, 20, 30, 40, 50, 10}; int sum = 0; //Advanced for - [java program to find factorial of a given number using recursion](https://beginnersbook.com/2014/01/java-program-to-find-factorial-of-a-given-number-using-recursion/) - Here we will write programs to find out the factorial of a number using recursion. Program 1: Program will prompt user for the input number. Once user provide the input, the program will calculate the factorial for the provided input number. /** * @author: BeginnersBook.com * @description: User would enter the 10 elements * and - [java program to check palindrome string using recursion](https://beginnersbook.com/2014/01/java-program-to-check-palindrome-string-using-recursion/) - Program: Check whether String is palindrome using recursion package beginnersbook.com; import java.util.Scanner; class PalindromeCheck { //My Method to check public static boolean isPal(String s) { // if length is 0 or 1 then String is palindrome if(s.length() == 0 || s.length() == 1) return true; if(s.charAt(0) == s.charAt(s.length()-1)) /* check for first and last char - [Java program to check prime number](https://beginnersbook.com/2014/01/java-program-to-check-prime-number/) - The number which is only divisible by itself and 1 is known as prime number, for example 7 is a prime number because it is only divisible by itself and 1. This program takes the number (entered by user) and then checks whether the input number is prime or not. The program then displays the - [Java program to display prime numbers from 1 to 100 and 1 to n](https://beginnersbook.com/2014/01/java-program-to-display-prime-numbers/) - The number which is only divisible by itself and 1 is known as prime number. For example 2, 3, 5, 7...are prime numbers. Here we will see two programs: 1) First program will print the prime numbers between 1 and 100 2) Second program takes the value of n (entered by user) and prints the - [Java Program to display first n or first 100 prime numbers](https://beginnersbook.com/2014/01/java-program-to-display-first-n-or-first-100-prime-numbers/) - Program to display first n prime numbers import java.util.Scanner; class PrimeNumberDemo { public static void main(String args[]) { int n; int status = 1; int num = 3; //For capturing the value of n Scanner scanner = new Scanner(System.in); System.out.println("Enter the value of n:"); //The entered value is stored in the var n n = - [Java program to print Floyd's triangle - Example](https://beginnersbook.com/2014/04/java-program-to-print-floyds-triangle-example/) - Example Program: This program will prompt user for number of rows and based on the input, it would print the Floyd's triangle having the same number of rows. /* Program: It Prints Floyd's triangle based on user inputs * Written by: Chaitanya from beginnersbook.com * Input: Number of rows * output: floyd's triangle*/ import java.util.Scanner; - [Java program for linear search - Example](https://beginnersbook.com/2014/04/java-program-for-linear-search-example/) - Example Program: This program uses linear search algorithm to find out a number among all other numbers entered by user. /* Program: Linear Search Example * Written by: Chaitanya from beginnersbook.com * Input: Number of elements, element's values, value to be searched * Output:Position of the number input by user among other numbers*/ import java.util.Scanner; - [Java program to perform binary search - Example](https://beginnersbook.com/2014/04/java-program-to-perform-binary-search/) - Example Program to perform binary search on a list of integer numbers This program uses binary search algorithm to search an element in given list of elements. /* Program: Binary Search Example * Written by: Chaitanya from beginnersbook.com * Input: Number of elements, element's values, value to be searched * Output:Position of the number input - [Java program to generate random number - Example](https://beginnersbook.com/2014/04/java-program-to-generate-random-number-example/) - Example Program to generate random numbers In the below program, we are using the nextInt() method of Random class to serve our purpose. /* Program: Random number generator * Written by: Chaitanya from beginnersbook.com * Input: None * Output:Random number between o and 200*/ import java.util.*; class GenerateRandomNumber { public static void main(String[] args) { - [How to convert a char array to a string in Java?](https://beginnersbook.com/2014/06/how-to-convert-a-char-array-to-a-string-in-java/) - There are two ways to convert a char array (char[]) to String in Java: 1) Creating String object by passing array name to the constructor 2) Using valueOf() method of String class. Example: This example demonstrates both the above mentioned ways of converting a char array to String. Here we have a char array ch - [How To Convert Char To String and a String to char in Java](https://beginnersbook.com/2014/06/how-to-convert-char-to-string-and-a-string-to-char-in-java/) - In this tutorial, we will see programs for char to String and String to char conversion. Program to convert char to String We have following two ways for char to String conversion. Method 1: Using toString() method Method 2: Usng valueOf() method class CharToStringDemo { public static void main(String args[]) { // Method 1: Using - [Java Program to find duplicate Characters in a String](https://beginnersbook.com/2014/07/java-program-to-find-duplicate-characters-in-a-string/) - This program would find out the duplicate characters in a String and would display the count of them. import java.util.HashMap; import java.util.Map; import java.util.Set; public class Details { public void countDupChars(String str){ //Create a HashMap Map map = new HashMap(); //Convert the String to char array char[] chars = str.toCharArray(); /* logic: char - [Java Program to get input from user](https://beginnersbook.com/2014/07/java-program-to-get-input-from-user/) - In this tutorial we are gonna see how to accept input from user. We are using Scanner class to get the input. In the below example we are getting input String, integer and a float number. For this we are using following methods: 1) public String nextLine(): For getting input String 2) public int nextInt(): - [Java program to get IP address](https://beginnersbook.com/2014/07/java-program-to-get-ip-address/) - In this example we are gonna see how to get IP address of a System. The steps are as follows: 1) Get the local host address by calling getLocalHost() method of InetAddress class. 2) Get the IP address by calling getHostAddress() method. import java.net.InetAddress; class GetMyIPAddress { public static void main(String args[]) throws Exception { - [Java program to convert decimal to binary](https://beginnersbook.com/2014/07/java-program-to-convert-decimal-to-binary/) - There are three following ways to convert Decimal number to binary number: 1) Using toBinaryString() method of Integer class. 2) Do conversion by writing your own logic without using any predefined methods. 3) Using Stack Method 1: Using toBinaryString() method class DecimalBinaryExample{ public static void main(String a[]){ System.out.println("Binary representation of 124: "); System.out.println(Integer.toBinaryString(124)); System.out.println("\nBinary representation - [Java program for bubble sort in Ascending & descending order](https://beginnersbook.com/2014/07/java-program-for-bubble-sort-in-ascending-descending-order/) - In this tutorial we are gonna see how to do sorting in ascending & descending order using Bubble sort algorithm. Bubble sort program for sorting in ascending Order import java.util.Scanner; class BubbleSortExample { public static void main(String []args) { int num, i, j, temp; Scanner input = new Scanner(System.in); System.out.println("Enter the number of integers to - [How to insert CSS into HTML](https://beginnersbook.com/2014/05/how-to-insert-css-into-html/) - Cascading Style Sheets (CSS) is a style sheet language used for describing the look and formatting of a document written in a markup language. While most often used to style web pages and interfaces written in HTML and XHTML. There are three ways to insert CSS style sheet into HTML. 1) Using External style sheet: - [CSS Selectors: element, Id and Class](https://beginnersbook.com/2014/05/css-selectors-element-id-and-class/) - What is a selector? Selectors helps identify the html element. Whenever we modify the property value for an html page, these values must be associated with an selector. For e.g. In the last tutorial we have seen an example like this: p { color: red; font-size: 16px; } Here p is selector which selects all - [How to build a website - A complete & free Guide for beginners](https://beginnersbook.com/2012/12/how-to-build-website/) - First of all, let me tell you that anyone can build a website, there is no specific skills required for it. you won't need to pay anything to website designer. Even I didn't have any knowledge when I started building this website, I kept on learning things and come up with this design. whatever I - [How to Create a free website on WordPress](https://beginnersbook.com/2013/10/create-a-free-website-on-wordpress/) - In this guide we have shared the steps to create a free website on WordPress.com Platform. There is a big difference between WordPress.org and WordPress.com, I will cover the differences in separate post, for now you should only know that you can build a free website on WordPress.com not on WordPress.org. Here, we will show - [How to Create a free Website on BlogSpot](https://beginnersbook.com/2013/10/create-a-free-website-on-blogspot/) - This guide will help you to create a free website on blogspot, you need not to buy domain and hosting services. Blogspot is a platform which allows you to build and host website for free, it owns by Google so you do not have to worry about server down time and other issues. Moreover, there are - [How to Change Domain name - Move WordPress site to New Domain](https://beginnersbook.com/2013/11/change-domain-name-without-losing-traffic-and-seo/) - You might be aware that we have recently changed our domain name. It was not at all an easy task and we got to learn so many things during the whole process of domain change. We have moved our WordPress site from the old domain (easysteps2buildwebsite.com) to a new domain (beginnersbook.com). We heard positive comments - [Java Program to Check Whether a Number is Even or Odd](https://beginnersbook.com/2014/02/java-program-to-check-even-or-odd-number/) - In this article, we will write two java programs to check whether a number is even or odd. If a number is perfectly divisible by 2 (number % 2 ==0) then the number is called even number, else the number is called odd number. Perfectly divisible by 2 means that when the number is divided - [Bitwise Operators in C with Examples](https://beginnersbook.com/2022/09/bitwise-operators-in-c-with-examples/) - Bitwise operators perform operations on bit level. For example, a bitwise & (AND) operator on two numbers x & y would convert these numbers to their binary equivalent and then perform the logical AND operation on them. C language supports following Bitwise operators: Bitwise Operators Truth Table: 1. Bitwise & (AND) operator In the Bitwise - [Conditional (Ternary) Operator in C with Examples](https://beginnersbook.com/2022/09/conditional-ternary-operator-in-c-with-examples/) - Conditional Operator also known as Ternary operator is the only operator in C programming that involves three operands. This is a most popular and widely used one liner alternative of if-else statement. Syntax of Ternary Operator: variable = Condition ? Expression1 : Expression2; If the Condition is true then the Expression1 executes. If the Condition - [Assignment Operators in C with Examples](https://beginnersbook.com/2022/09/assignment-operators-in-c-with-examples/) - Assignment operators are used to assign value to a variable. The left side of an assignment operator is a variable and on the right side, there is a value, variable, or an expression. It computes the outcome of the right side and assign the output to the variable present on the left side. C supports - [Arithmetic Operators in C with Examples](https://beginnersbook.com/2022/09/arithmetic-operators-in-c-with-examples/) - Arithmetic operators are used to perform arithmetic operations on the operands. For example, x + y is an addition arithmetic operation, where x and y are operands and + symbol is an arithmetic operator. C supports following arithmetic operators: 1. Addition(+) Operator Example It adds two operands. In the following example, we have two integer - [Unary Operator in C with Examples](https://beginnersbook.com/2022/09/unary-operator-in-c-with-examples/) - Unary operators work on a single operand. C programming language supports the following unary operators: Unary minus (-) Increment (++) Decrement (--) NOT (!) Address Operator (&) Sizeof() operator 1. Unary Minus (-) Operator Example The unary minus operator is used to change the sign of an operand. It changes a positive operand to negative - [Difference between Star and Mesh Topology](https://beginnersbook.com/2022/09/difference-between-star-and-mesh-topology/) - In this guide, we will discuss the differences between Star and Mesh Topologies. Star Topology: In Star topology, each device in the network is connected to a central device called hub, thus forming a star like pattern. This is the reason it is called star topology. Devices communicate with each other through the hub. If - [Difference between Star and Bus Topology](https://beginnersbook.com/2022/09/difference-between-star-and-bus-topology/) - In this guide, we will discuss the differences between Star and Bus Topologies. Star Topology: In Star topology, n devices can be connected to a network using n number of links. Each device is connected to a central device known as hub. This hub acts as an intermediary between sender and receiver device. The sender - [Difference between Ring and Mesh Topology](https://beginnersbook.com/2022/09/difference-between-ring-and-mesh-topology/) - In this guide, we will discuss the differences between Ring and Mesh Topologies. Mesh Topology: In mesh topology each device is connected to every other device on the network through a direct one to one connection. This connection is dedicated for these two devices and no third device can send or receive data through this - [Difference between Star and Ring Topology](https://beginnersbook.com/2022/09/difference-between-star-and-ring-topology/) - In this guide, we will discuss the differences between Star and Ring Topologies. Star Topology: In Star topology each device in the network is connected to a central device called hub. If one device wants to send data to other device in the network, it has to first send the data to hub and then - [Difference Between View and Table with examples](https://beginnersbook.com/2022/08/difference-between-view-and-table-with-examples/) - In this article, we will discuss the difference between view and table. Both of these terms are commonly used in relational database. What is a view? A view is a result of a SQL query. The result look like a table, however this table is not physically present in the database, rather the data displayed - [Difference between Denormalization and Normalization](https://beginnersbook.com/2022/08/difference-between-denormalization-and-normalization/) - In this guide, you will learn the difference between Denormalization and Normalization. What is Denormalization Denormalization is a process of adding redundant data to tables in order to get faster response time for read operations. However this better performance comes with a cost of storing redundant data that occupies additional storage in the database. Denormalization - [Denormalization in DBMS](https://beginnersbook.com/2022/08/denormalization-in-dbms/) - Denormalization is a process of adding redundant data to normalized tables in order to avoid unnecessary join operations. This improves the performance of read operations as there is no need to join multiple tables, however this requires extra storage space for redundant data, also it can cause data inconsistencies in database, if the redundant data - [Indexing in DBMS - Types of Indexes in Database](https://beginnersbook.com/2022/08/indexing-in-dbms-types-of-indexes-in-database/) - A database index is a data structure that helps in improving the speed of data access. However it comes with a cost of additional write operations and storage space to store the database index. The database index helps quickly locate the data in database without having to search every row of database. The process of - [Decomposition in DBMS - Lossless and Lossy with examples](https://beginnersbook.com/2022/08/decomposition-in-dbms-lossless-and-lossy-with-examples/) - Decomposition is a process of dividing a relation into multiple relations to remove redundancy while maintaining the original data. In this guide, you will learn decomposition in DBMS with the help of examples. Types of decomposition: 1. Lossless decomposition 2. Lossy decomposition 1. Lossless decomposition A lossless decomposition of a relation ensures that: a) No - [DBMS - Recursive Relationship in ER Diagrams](https://beginnersbook.com/2022/08/dbms-recursive-relationship-in-er-diagrams/) - A relationship between two entities is called recursive relationship if the two entities are of similar type. For example: A relationship between a manager and an engineer is a recursive relationship because both manager and employee are employees of the company. Similarly a relationship "marries" between two person is recursive relationship as a person marries - [Data Replication in DBMS](https://beginnersbook.com/2022/08/data-replication-in-dbms/) - Data replication is a process of making the multiple copies of database available on servers. This is done to achieve distributed database. This is to minimize the load on the database and provide better performance to the users. In Data replication, the various users can access data from different sites available on distributed system, however - [Starvation in DBMS](https://beginnersbook.com/2022/08/starvation-in-dbms/) - Starvation is a situation when one transaction keeps on waiting for another transaction to release the lock. This is also called LiveLock. As we already learned in transaction management that a transaction acquires lock before performing a write operation on data item, if the data item is already locked by another transaction then the transaction - [ACID properties in DBMS](https://beginnersbook.com/2015/04/acid-properties-in-dbms/) - To ensure the integrity and consistency of data during a transaction (A transaction is a unit of program that updates various data items, read more about it here), the database system maintains four properties. These properties are widely known as ACID properties. Atomicity This property ensures that either all the operations of a transaction reflect - [Introduction to SQL](https://beginnersbook.com/2018/11/introduction-to-sql/) - SQL is a language which is used to interact with relational database management system. Before we learn what is a SQL and what we can do with the SQL, let's learn the basics first. What is a database Database is a organized collection of data. For example a database of a college would be having - [Types of DBMS (Database Management System)](https://beginnersbook.com/2022/08/types-of-dbms/) - DBMS is a software that manages the data for efficient storage and fast retrievals of data from database. MySQL, IBM Db2, Oracle, PostgreSQL etc. are all DBMS softwares that manages the data. In this guide, you will learn various types of DBMS (Database Management System). Types of DBMS There are 4 types of DBMS: 1. - [SQL Rename Database using ALTER DATABASE Statement](https://beginnersbook.com/2022/08/sql-rename-database/) - You can rename a database using ALTER DATABASE statement. Limitations and restrictions of renaming a database 1. Database cannot be renamed to an existing database name. As every database name must be unique so the new name should be unique and should not already exists in the database management system. 2. System databases cannot be - [SQL SELECT Database - USE Statement](https://beginnersbook.com/2014/05/sql-select-database-statement/) - In an ideal scenario, there are several databases present on an a database server. In order to perform an operation on data, you must first select the database using USE DbName statement and then you can perform an operation on a table, view or indexes. It is important to select the database as more than - [SQL DROP DATABASE Statement](https://beginnersbook.com/2014/05/sql-drop-database-statement/) - The SQL DROP database statement is used to delete the existing database from the database management system. This statement permanently deletes the specified database from the system which includes all the tables, schemas, views and all the data that is stored inside the specified database. SQL DROP database syntax DROP DATABASE databaseName; There are two - [Structure in C programming with examples](https://beginnersbook.com/2014/01/c-structures-examples/) - Structure is a group of variables of different data types represented by a single name. Let's take an example to understand the need of a structure in C programming. Why we need structure in C ? Let's say we need to store the data of students like student name, age, address, id etc. One way - [Difference between include directive and include tag in JSP](https://beginnersbook.com/2013/12/difference-between-include-directive-and-include-tag-in-jsp/) - Include directive and include action tag both are used for including a file to the current JSP page. However there is a difference in the way they include file. Before I explain the difference between them, let's discuss them briefly. JSP Include Directive index.jsp JSP include Directive example - [Include Directive in JSP](https://beginnersbook.com/2013/11/jsp-include-directive/) - In this tutorial, you will learn include directive in JSP with example. Include directive is used to copy the content of one page to another. It’s like including the code of one file into another. The include directive includes the original content of the included resource at page translation time (The phase where JSP gets - [JSP Directives - Page, Include and TagLib](https://beginnersbook.com/2013/05/jsp-tutorial-directives/) - JSP Directives control the processing of an entire JSP page. It gives directions to the server regarding processing of a page. There are three types of directives available in JSP: page, include and taglib. In this guide, you will learn all the three JSP directives in detail with the help of examples. Syntax of Directives: - [Exception Implicit Object in JSP with examples](https://beginnersbook.com/2013/11/jsp-implicit-object-exception-with-examples/) - In this tutorial, you will learn exception implicit object in JSP. It is an instance of java.lang.Throwable and mainly used for exception handling in JSP. JSP exception implicit object is only available for error pages, which means a JSP page should have isErrorPage set to true in order to use exception implicit object. JSP exception - [pageContext Implicit Object in JSP with examples](https://beginnersbook.com/2013/11/jsp-implicit-object-pagecontext-with-examples/) - In this guide, you will learn pageContext implicit object in JSP. It is an instance of javax.servlet.jsp.PageContext. JSP pageContext implicit object can be used to get attribute, set attribute or remove attribute at any of the following scopes. JSP Page – Scope: PAGE_CONTEXT HTTP Request – Scope: REQUEST_CONTEXT HTTP Session – Scope: SESSION_CONTEXT Application Level - [Out Implicit Object in JSP with examples](https://beginnersbook.com/2013/11/jsp-implicit-object-out-with-examples/) - In this tutorial, you will learn out implicit object in JSP with the help of examples. It is an instance of javax.servlet.jsp.JspWriter. This allows user to access Servlet output stream. The output which needs to be sent to the client (browser) is passed through this object. Simply put, the JSP out implicit object is used - [Session Implicit Object in JSP with examples](https://beginnersbook.com/2013/11/jsp-implicit-object-session-with-examples/) - In this tutorial, you will learn session implicit object in JSP. JSP session implicit object is the most frequently used implicit object in JSP. The main use of session is to gain access to all the user's data till the user session is active. Methods of session Implicit Object setAttribute(String, object): This method is used - [Application Implicit Object in JSP with examples](https://beginnersbook.com/2013/11/jsp-implicit-object-application-with-examples/) - In this tutorial, you will learn application implicit object in JSP. It is an instance of javax.servlet.ServletContext. It is used for getting initialization parameters and for sharing the attributes & their values across the entire JSP application, which means any attribute set by application implicit object is available to all the JSP pages. Application implicit - [Config Implicit Object in JSP with examples](https://beginnersbook.com/2013/11/jsp-implicit-object-config-with-examples/) - In this tutorial, you will learn config implicit object in JSP. It is an instance of javax.servlet.ServletConfig. The JSP config implicit object is used for getting configuration information for a particular JSP page. Using application implicit object we can get application-wide initialization parameters, however using Config we can get initialization parameters of an individual servlet mapping. - [Response Implicit Object in JSP with examples](https://beginnersbook.com/2013/11/jsp-implicit-object-response-with-examples/) - In this tutorial, you will learn response implicit object in JSP. It is an instance of javax.servlet.http.HttpServletRequest and mainly used for modifying the response which is being sent to the browser after processing the client's request. Quick links: This is a long guide, where we are discussing the methods of response implicit object first. If you - [Request Implicit Object in JSP with examples](https://beginnersbook.com/2013/11/jsp-implicit-object-request-with-examples/) - In this tutorial, you will learn request implicit object in JSP. It is used to get the data on a JSP page which has been entered by user on the previous JSP page. Methods of request Implicit Object getParameter(String name) - This method is used to get the value of a request's parameter. For example at - [JSP Implicit Objects](https://beginnersbook.com/2013/11/jsp-implicit-objects/) - JSP implicit objects are created by JSP Engine during translation phase (while translating JSP to Servlet). They are being created inside service method so we can directly use them within Scriptlet without initializing and declaring them. There are total 9 implicit objects available in JSP. Implicit Objects and their corresponding classes: Implicit Object Class out - [JSP Declaration tag](https://beginnersbook.com/2013/11/jsp-declaration-tag/) - JSP Declaration tag is a block of java code used for declaring class wide variables and methods. The code placed inside declaration tag gets initialized during JSP initialization phase and has class scope. JSP container keeps this code outside of the service method _jspService() to make them class level variables and methods. As we know - [JSP Expression Tag](https://beginnersbook.com/2013/11/jsp-expression-tag/) - JSP Expression tag evaluates the expression placed in it, converts the result into String and send the result back to the client through response object. Simply put, it writes the result to the client(browser). Syntax of expression tag in JSP: JSP Expression tag Example 1: Expression of values Here we are simply - [JSP Scriptlet Tag (Scripting elements)](https://beginnersbook.com/2013/05/jsp-tutorial-scriptlets/) - JSP scriptlet tag also known as Scriptlets are nothing but java code enclosed within tags. The main purpose of scriptlet tag is to add java code into a JSP page. JSP container moves the statements enclosed in scriptlet tag to _jspService() method while generating servlet from JSP. The reason of copying this - [How to run JSP in Eclipse IDE using Apache Tomcat Server](https://beginnersbook.com/2017/06/jsp-in-eclipse-ide-apache-tomcat-server/) - In this tutorial, you will learn how to create a simple JSP file and run it on Eclipse IDE using Apache Tomcat Server. Step 1: In order to run JSP in Eclipse IDE, you need to have Apache tomcat Server configured in Eclipse IDE. If you don't have it installed, then refer this tutorial: How to - [Java Server Pages (JSP) Life Cycle](https://beginnersbook.com/2013/05/jsp-tutorial-life-cycle/) - JSP pages are saved with .jsp extension which lets the server know that this is a JSP page and needs to go through JSP life cycle stages. In my previous post about JSP introduction, I explained that JSP is not processed as such, they first gets converted into Servelts and then the corresponding servlet gets - [Introduction to Java Server Pages - JSP Tutorial](https://beginnersbook.com/2013/05/jsp-tutorial-introduction/) - JSP is a server side technology that does all the processing at server. It is used for creating dynamic web applications, using java as programming language. It is an extension of servlet because it provides more functionality than servlet by allowing users to use expression language and JSTL. Basically, any html file can be converted - [Java Program to check Palindrome string using Stack and Queue](https://beginnersbook.com/2014/01/java-program-to-check-palindrome-string/) - In this tutorial, you will learn how to write a java program check whether the given String is Palindrome or not. There are following three ways to check for palindrome string. 1) Using Stack 2) Using Queue 3) Using for/while loop Program 1: Palindrome check Using Stack In this example, user enter a string. The - [Array of Structures in C](https://beginnersbook.com/2022/07/array-of-structures-in-c/) - In this guide, you will learn array of structures in C. An array of structures is an array with structure as elements. An int array stores the elements of int type. Similarly an array of structures store the structures of same type as elements. For example: Here, stu[5] is an array of structures. This array - [C Program to Access Array Elements Using Pointer](https://beginnersbook.com/2022/07/c-program-to-access-array-elements-using-pointer/) - In this C program, you will learn how to access array elements using pointer. Program to access array elements using pointer In this program, we have an array of integers, the name of the array is numbers. In pointer notation, numbers[0] is equivalent to *numbers. This is because the array name represents the base address - [C Program to Find the Frequency of Characters in a String](https://beginnersbook.com/2022/07/c-program-to-find-the-frequency-of-characters-in-a-string/) - In this tutorial, you will learn how to write a C program to find the frequency of characters in a string. We will see two programs. The first program prints the frequency of specified character. In the second program, we are printing the frequency of each character in a string. Example 1: Program to find - [Java Program to Add two Numbers](https://beginnersbook.com/2017/09/java-program-to-add-two-numbers/) - In this tutorial, you will learn how to write a Java program to add two numbers. We will see three programs: In the first program, the values of the two numbers are given. In the second program, user is asked to enter the two numbers and the program calculates the sum of the input numbers. - [Two dimensional (2D) arrays in C programming with example](https://beginnersbook.com/2014/01/2d-arrays-in-c-example/) - An array of arrays is known as 2D array. The two dimensional (2D) array in C programming is also known as matrix. A matrix can be represented as a table of rows and columns. Let's take a look at the following C program, before we discuss more about two Dimensional array. Simple Two dimensional(2D) Array - [Entity Relationship Diagram - ER Diagram in DBMS](https://beginnersbook.com/2015/04/e-r-model-in-dbms/) - An Entity–relationship model (ER model) describes the structure of a database with the help of a diagram, which is known as Entity Relationship Diagram (ER Diagram). An ER model is a design or blueprint of a database that can later be implemented as a database. The main components of E-R model are: entity set and - [C Preprocessor Directives](https://beginnersbook.com/2022/07/c-preprocessor-directives/) - C preprocessor is a macro processor, which is used by the compiler to make the appropriate changes to the code before the compilation begins. C preprocessors are not part of the compiler, it is just an additional step that is performed by the C compiler before the compilation. As the name suggests, it instructs the - [typedef in C](https://beginnersbook.com/2022/07/typedef-in-c/) - The typedef is a reserved word (keyword) in the C programming language. It is used to create an additional name for another existing data type. It does not create a new data type rather give a simple alias to the existing data type so it can be easily referred in the program. In this guide, - [Instance and schema in DBMS](https://beginnersbook.com/2015/04/instance-and-schema-in-dbms/) - In this guide, you will learn about instance and schema in DBMS. DBMS Schema Definition of schema: Design of a database is called the schema. For example: An employee table in database exists with the following attributes: EMP_NAME EMP_ID EMP_ADDRESS EMP_CONTACT -------- ------ ----------- ----------- This is the schema of the employee table. Schema defines - [Data Abstraction in DBMS](https://beginnersbook.com/2015/04/levels-of-abstraction-in-dbms/) - Database systems are made-up of complex data structures. To ease the user interaction with database, the developers hide internal irrelevant details from users. This process of hiding irrelevant details from user is called data abstraction. The term "irrelevant" used here with respect to the user, it doesn't mean that the hidden data is not relevant - [View of Data in DBMS](https://beginnersbook.com/2015/04/view-in-dbms/) - In this guide, you will learn view of data in DBMS. View of data in DBMS Abstraction is one of the main features of database systems. Hiding irrelevant details from user and providing abstract view of data to users, helps in easy and efficient user-database interaction. In the previous tutorial, we discussed the three level - [Advantages and Disadvantages of DBMS: DBMS vs file System](https://beginnersbook.com/2015/04/dbms-vs-file-system/) - In this guide, you will learn advantages and disadvantages of DBMS. We will first discuss what is a file processing system and how Database management systems are better than file processing systems. Drawbacks of File system Data redundancy: Data redundancy refers to the duplication of data, lets say we are managing the data of a - [Database Applications - DBMS](https://beginnersbook.com/2015/04/database-applications/) - In this guide, you will learn the various DBMS applications. These applications help you understand the use of DBMS in various fields. DBMS applications Applications where we use Database Management Systems are: Telecom: There is a database to keeps track of the information regarding calls made, network usage, customer details etc. Without the database systems - [Introduction to DBMS](https://beginnersbook.com/2015/04/dbms-introduction/) - DBMS stands for Database Management System. We can break it like this DBMS = Database + Management System. Database is a collection of data and Management System is a set of programs to store and retrieve those data. Based on this we can define DBMS like this: DBMS is a collection of inter-related data and - [C Program to Calculate Average Using Array](https://beginnersbook.com/2022/07/c-program-to-calculate-average-using-array/) - In this tutorial, you will learn how to write a C program to calculate average using array. This is a very simple program, here you can ask user to enter array elements, then calculate the average of input numbers by dividing the sum of elements, by the number of elements. Program to calculate average using - [C Program to Store Information of Students Using Structure](https://beginnersbook.com/2022/07/c-program-to-store-information-of-students-using-structure/) - In this tutorial, you will learn how to use structure to store information of students in C. Program to store information of students using structure In this program we have a structure student with four members name, rollNum, address and marks. We have created an array of structure with size 3 (s[3]), in order to - [C Program to Add Two Complex Numbers](https://beginnersbook.com/2022/07/c-program-to-add-two-complex-numbers/) - In this tutorial, you will learn how to write a C program to add two complex numbers. A complex number has two parts: real and imaginary. For example, in a complex number 10 + 15i the real part is 10 and the imaginary part is 15. When two complex numbers are added, the real and - [C Program to Print an Integer entered by the user](https://beginnersbook.com/2017/09/c-program-to-print-an-integer-entered-by-a-user/) - In this tutorial, you will learn how to write a C program to print an integer entered by user. This is a very simple program. You just need to capture the user input using scanf, and store it in an int variable, then you can use printf to print the value of the variable. C - [C Program to Add two numbers](https://beginnersbook.com/2017/09/c-program-to-add-two-numbers/) - In this tutorial, you will learn how to write a C program to add two numbers. This is a very basic C program where user is asked to enter two integers and then program takes those inputs, stores them in two separate variables and displays the sum of these integers. We will write two programs - [C Program to Print Pyramid Star Pattern](https://beginnersbook.com/2022/07/c-program-to-print-pyramid-star-pattern/) - In this tutorial, you will learn how write a C program to print the Pyramid star pattern. This is how a Pyramid star pattern looks like: Number of rows = 7 Output: * * * * * * * * * * * * * * * * * * * * * * * - [C Program to Print Left Triangle Star Pattern](https://beginnersbook.com/2022/07/c-program-to-print-left-triangle-star-pattern/) - In this tutorial, we will write a C program to print the Left Triangle Star Pattern. This is also called mirrored Right Triangle Star Pattern. This is how a left triangle pattern looks like: Number of rows = 6 Output: * * * * * * * * * * * * * * * - [C Program to Print Right Triangle Star Pattern](https://beginnersbook.com/2022/07/c-program-to-print-right-triangle-star-pattern/) - In this tutorial, you will learn how to write a C program to print the right triangle star pattern. This is how a right triangle pattern looks like: Number of rows = 6 Output: * * * * * * * * * * * * * * * * * * * * * - [Format Specifier in C](https://beginnersbook.com/2022/07/format-specifier-in-c/) - Format specifier in C is a String, starting with '%' symbol that specifies the type of data that is being printed using printf() or read using scanf(). For example: In the following statement the %d is a format specifier that specifies that the data type of the variable num is int. printf("%d", num); Format Specifier - [Comments in C with examples](https://beginnersbook.com/2022/07/comments-in-c-with-examples/) - In this guide, you will learn how to use comments in C programming language. We will discuss types of comments with examples in this tutorial. What are Comments in C? Comment is a piece of text which doesn't have any impact on the output of the program, it is there for documentation purposes. Comments are - [C Identifiers](https://beginnersbook.com/2022/07/c-identifiers/) - In this guide, you will learn about C identifiers. As the name suggests an identifier in C is a unique name that is used to identify a variable, array, function, structure etc. For example: in int num =10; declaration, name "num" is an identifier for this int type variable. Identifier must be unique so that - [C Keywords - Reserved Words](https://beginnersbook.com/2014/01/c-keywords-reserved-words/) - In C, we have 32 keywords, which have their predefined meaning and cannot be used as a variable name. These words are also known as "reserved words". It is good practice to avoid using these keywords as variable name. These are - Basics usage of these keywords - if, else, switch, case, default - Used - [Data Types in C](https://beginnersbook.com/2022/07/data-types-in-c/) - Data type specifies which type of data can be stored in a variable. For example, an int variable store integer value, char variable store characters, float variable store float value etc. These int, char and float keywords are data types that basically defines the type of data. In this guide, you will learn about data - [Variables in C](https://beginnersbook.com/2022/07/variables-in-c/) - A variable represents a memory location that stores the data. For example: an int variable num has a value 10 (int num = 10), here the variable name is "num" that represents the location in the memory where this value 10 is stored. As the name suggests, the value of a variable can be changed - [Functions printf() and scanf() in C](https://beginnersbook.com/2022/07/functions-printf-and-scanf-in-c/) - The printf() and scanf() functions are the most commonly used functions in C Programming. These functions are widely used in majority of the C programs. In this tutorial, you will learn, what are these functions, how to use them in C programs. The scanf() and printf() functions are used for input and output in c - [C Program Structure - First C Program](https://beginnersbook.com/2014/01/c-program-structure/) - A C program source code can be written in any text editor; however the file should be saved with .c extension. Lets write the First C program. First C Program /* Demo Program written by Chaitanya on BeginnersBook.com*/ #include int main() { int num; printf("Enter your age: "); scanf("%d", &num); if (num - [How to install Turbo C++: Compile and Run a C Program](https://beginnersbook.com/2014/01/install-turbo-c/) - First thing you need to understand is that computer (Machine) can only understand Machine language (Stream of 0s and 1s). In order to convert your C program source code to Machine code, you need to compile it. Compiler is the one, which converts source code to Machine code. In simple words you can say that - [Features of C Programming Language](https://beginnersbook.com/2022/07/features-of-c-programming-language/) - In this article, you will learn the features of C language. C is one of the widely used general purpose programming language. Features of C language 1. Simple C language is simple and easy to learn. The syntax of C is simple and gives flexibility to the programmer with its wide variety of in-built functions - [History of C Language](https://beginnersbook.com/2022/07/history-of-c-language/) - C is a general purpose computer programming language. A general purpose language is a language that is widely used in various domains and not specific to a particular domain. C programming language was created in 1972 by Dennis Ritchie at AT&T bell laboratories in U.S.A. Founder: Dennis Ritchie is known as the founder of C - [C Tutorial - Learn C Programming with examples](https://beginnersbook.com/2014/01/c-tutorial-for-beginners-with-examples/) - Learning C programming is easy if you follow the tutorials in the given order and practice C programs along the way. This C tutorial is designed for beginners so you won't face any difficulty even if you have no prior knowledge in C language. C is a general purpose computer programming language. A general purpose - [C Program to Write a Sentence to a File](https://beginnersbook.com/2022/07/c-program-to-write-a-sentence-to-a-file/) - In this tutorial, you will learn how to write a C program to write a sentence to a file. Program to write a sentence to a file In this we are writing the a line entered by user into the mentioned file. Variable fptr is a file pointer, since we want to write into the - [C Program to Read the First Line From a File](https://beginnersbook.com/2022/07/c-program-to-read-the-first-line-from-a-file/) - In this tutorial, you will learn how to write a C program to read the first line from a file. Program to Read the First Line From a File In this program, the header file is used because we are using the exit() function that belongs to this file. If the file is found - [jQuery Tutorial for beginners | Learn jQuery](https://beginnersbook.com/2019/05/learn-jquery-tutorial/) - I have written several tutorials on jQuery starting from the basics to the advanced levels. I have consolidated all the tutorials and prepared a list of tutorials in a systematic manner. Here I will share the list that contains the links to all those tutorials on jQuery in a well designed sequence, which will help - [C Program to Calculate the Power of a Number](https://beginnersbook.com/2022/07/c-program-to-calculate-the-power-of-a-number/) - In this tutorial, you will learn how to write C program to calculate power of a number. There are two ways you can calculate power of a number, using loop or using pow() function. Example 1: Program to calculate power of a number using loop In this example, we are using while loop and inside - [C Program to Count Number of Digits in an Integer](https://beginnersbook.com/2022/07/c-program-to-count-number-of-digits-in-an-integer/) - In this tutorial, you will learn how to write a C program to count number of digits in an integer. For example number 3456 has 4 digits, number 555 has 3 digits etc. Program to count number of digits in an integer The logic used in this program is pretty simple. The user input is - [C Program to Check Whether a Number is Prime or Not](https://beginnersbook.com/2022/07/c-program-to-check-whether-a-number-is-prime-or-not/) - In this tutorial, you will learn how to write a C program to check whether a number is prime or not. A positive number is called prime number if it is divisible by 1 and itself. For example: 13, 19, 23 are prime numbers because they are divisible by 1 and themselves. Program to check - [C Program to Display Characters from A to Z Using Loop](https://beginnersbook.com/2022/07/c-program-to-display-characters-from-a-to-z-using-loop/) - In this guide, you will learn how to write a C program to display the characters from 'A' to 'Z' using loop. Example 1: Program to print characters from 'A' to 'Z' using loop In this example, we are using a for loop to print alphabets from 'A' to 'Z'. We have a char type - [C Program to Find LCM of two Numbers](https://beginnersbook.com/2022/07/c-program-to-find-lcm-of-two-numbers/) - In this tutorial, you will learn how to write a C program to find LCM of two numbers. What is LCM? LCM stands for lowest common multiple. LCM of two integers num1 and num2 is the smallest positive integer that is perfectly divisible by both the numbers, perfectly means the remainder is zero. For example, - [C Program to Find GCD of two Numbers](https://beginnersbook.com/2022/07/c-program-to-find-gcd-of-two-numbers/) - In this tutorial, you will learn how to write a C program to find GCD of two numbers. What is GCD? GCD stands for "Greatest common divisor". GCD of two integer numbers is the largest integer that can exactly divide both the numbers, exactly means that the remainder is zero. It is also called HCF - [C Program to Generate Multiplication Table](https://beginnersbook.com/2022/07/c-program-to-generate-multiplication-table/) - In this tutorial, you will learn how to write a C program to generate multiplication table. We will see two programs in this article. In the first program, we are printing the multiplication table for the entered number. In the second example, we are displaying the multiplication table upto the specified range. Example 1: Program - [C Program to check whether a Character is an Alphabet or not](https://beginnersbook.com/2017/09/c-program-to-check-whether-a-character-is-an-alphabet-or-not/) - In this tutorial, you will learn how to write a C program to check whether a character entered by user is an alphabet or not. Example: Program to check whether a character is an Alphabet or not In the following example, user is asked to enter a character, which is stored in a char variable - [Java Program to remove all the white spaces from a string](https://beginnersbook.com/2022/07/java-program-to-remove-all-the-white-spaces-from-a-string/) - In this tutorial, you will learn how to write a java program to remove all the whitespaces from a string. To do that we are using replaceAll() method and inside which we are using regex to replace all white spaces with blank. Java Program to remove all the white spaces from a string In this - [jQuery detach()](https://beginnersbook.com/2022/07/jquery-detach/) - The jQuery detach() method removes the selected elements but keeps the data and events. This method also keeps the copy of removed elements which can reinserted whenever needed. Note: If you want to remove the elements along with the data and events, use remove() method instead. If you only want to remove the content of - [jQuery empty()](https://beginnersbook.com/2022/07/jquery-empty/) - The jQuery empty() method removes the content of the selected elements. If the selected elements have any child nodes, empty() method removes those child nodes as well. This method doesn't remove the element itself, it just removes the content of the element. Note: If you want to remove the elements along with the data and - [jQuery remove()](https://beginnersbook.com/2022/07/jquery-remove/) - The jQuery remove() method removes the selected elements along with the data and events associated with the element. If the selected element has any child node associated with it, remove() method removes those child nodes as well. Note: If you only want to remove the selected element and do not want to remove the data - [jQuery prepend()](https://beginnersbook.com/2022/07/jquery-prepend/) - The jQuery prepend() method inserts the specified content at the the beginning of selected elements. This works just opposite to the append() method that we discussed earlier here. Syntax of prepend() method $(selector).prepend(content) Here, content represents the specified data that is inserted at the start of the selected elements. This content can include HTML tags, - [jQuery css()](https://beginnersbook.com/2022/07/jquery-css/) - The jQuery css() method is used to get or set style properties of selected elements. When css() method is used to return style properties: It returns the css property value of the first matched element. Syntax: $(selector).css(property) When css() method is used to set style properties: It sets the specified css property values for all - [jQuery val()](https://beginnersbook.com/2022/07/jquery-val/) - jQuery val() is used to return or set the value of selected elements. When val() method is used to return value, it returns the value of the first element from the selected elements. Syntax of val() method when it is used for get value: $(selector).val() When val() method is used to set the value, it - [jQuery text()](https://beginnersbook.com/2022/07/jquery-text/) - The jQuery text() method is used to set or return the text content of selected elements. This is different from the jQuery html() method that we discussed in earlier. The jQuery html() method sets or returns content of selected elements with html tags while text() method returns or sets content without the html tags (just - [SQL Data Types](https://beginnersbook.com/2022/07/sql-data-types/) - SQL Data type defines the values that a column can accept, for example if a column of the table has an int data type, then it can only accept integer values. You can specify the data type of the columns while creating the table. SQL Data Types classification Data Types in SQL are classified in - [SQL Tutorial for Beginners: Learn SQL](https://beginnersbook.com/2022/07/sql-tutorial-for-beginners-learn-sql/) - This SQL tutorial is design for beginners as well as advanced professionals. Each tutorial is started from basic level so a SQL beginner will be able to understand each and every concept covered in this SQL tutorial. SQL stands for Structured Query Language. SQL is a language which is used to interact with relational database - [jQuery insertAfter() Method](https://beginnersbook.com/2022/07/jquery-insertafter-method/) - The jQuery insertAfter() method inserts the specified html elements after the selected elements. If the specified html element already exists, then the existing element will be moved from the current position and inserted after the selected elements. Syntax of jQuery insertAfter() method $(content).insertAfter(selector) content: This is a mandatory parameter. This contains HTML elements that are - [jQuery attr() Method](https://beginnersbook.com/2022/07/jquery-attr-method/) - The jQuery attr() method is used to set or get the attributes or values of the selected elements. Syntax of attr() method This returns the value of the specified attribute: $(selector).attr(attribute) This sets the attribute and value of the selected elements: $(selector).attr(attribute,value) This sets the attribute and value of the selected elements using a function: - [jQuery insertBefore() Method](https://beginnersbook.com/2022/07/jquery-insertbefore-method/) - The jQuery insertBefore() method inserts the specified html elements before the selected elements. If the specified html element is already present in the html page then, the existing element will be moved from the current position and inserted before the selected elements. Syntax of jQuery insertBefore() method $(content).insertBefore(selector) content: This is a mandatory parameter. This - [jQuery clone() Method](https://beginnersbook.com/2022/07/jquery-clone-method/) - The jQuery clone() method copies the selected elements, including everything associated with them such as event handlers, child elements, text, attributes, values etc. It then inserts the copy of the selected elements in the html page body. Syntax of jQuery clone() method $(selector).clone(true|false) $(selector): It selects the elements that are copied by the clone() method. - [jQuery appendTo() Method](https://beginnersbook.com/2022/07/jquery-appendto-method/) - The jQuery appendTo() method inserts the specified html elements at the end of the selected elements. Syntax of jQuery appendTo() Method $(content).appendTo(selector) content: This is the mandatory parameter. This contains HTML elements that are inserted at the end of selected elements by appendTo() method. This content must always have html tags. Important Note: If content - [jQuery append() Method](https://beginnersbook.com/2022/07/jquery-append-method/) - The jQuery append() method inserts the specified content at the end of the selected elements. Syntax of jQuery append() method $(selector).append(content,function(n)) content: This specifies the content which you want to append at the end of the selected elements, it can be HTML elements, jQuery objects, DOM elements. You must specify this parameter as it is - [jQuery before() Method](https://beginnersbook.com/2022/07/jquery-before-method/) - The jQuery before() method inserts the specified content before the selected elements. This works similar to after() method except that it inserts the content before the selected element. Syntax of jQuery before() method $(selector).after(content, function(n)) Here, content represents the content that is inserted before the selected elements. This content can be HTML elements, jQuery objects - [jQuery after() Method](https://beginnersbook.com/2022/07/jquery-after-method/) - The jQuery after() method inserts the specified content after the selected elements. Syntax of jQuery after() method $(selector).after(content, function(n)) Here, content represents the content that is inserted after the selected elements. This content can be HTML elements, jQuery objects or DOM elements or a simple text/value. $(selector): This selects the elements after which the content - [jQuery toggleClass() Method](https://beginnersbook.com/2022/07/jquery-toggleclass-method/) - The jQuery toggleClass() method alternates between adding and removing specified classes from selected elements. For example, if a paragraph (p element) has class "highlight" then using toggleClass("highlight") method on p elements will remove the "highlight" class and again using the toggleClass("highlight") will add the class again and so on. This works like an on/off switch, - [jQuery removeClass() Method](https://beginnersbook.com/2022/07/jquery-removeclass-method/) - The jQuery removeClass() method is used to remove one or more classes from the selected elements. It works just opposite to the addClass() method which adds the class to selected elements. Syntax of removeClass() method $(selector).removeClass(classname1 classname2 ...) $(selector): It selects the elements that require class removal. Read more about selector here. classname1, classname2 and - [jQuery hasClass() Method](https://beginnersbook.com/2022/07/jquery-hasclass-method/) - In this tutorial, you will learn how to use jQuery hasClass() method. This method checks if a specified class assigned to the specified element. Syntax of hasClass() method $(selector).hasClass(classname) Here, classname specifies the class that needs to be checked. This method returns true if the element selected by the selector, has the classname assigned to - [jQuery html() method](https://beginnersbook.com/2019/05/jquery-html/) - jQuery html() method is used to set or return the content of the selected elements. When html() method is used to set the content of the selected elements, it overwrites the content of all the matched selected elements. For example, the code $("p").html("BeginnersBook"); will change the content of all the paragraphs to "BeginnersBook". When html() - [jQuery addClass() method](https://beginnersbook.com/2022/07/jquery-addclass-method/) - The jQuery addClass() method is used to add the class names to the selected elements. This is especially useful when you want to add styles to the existing elements on a page. For example, let's say you want to change the font size and colour of the first paragraph. You can create a desired css - [Java Program to find the longest repeating sequence in a string](https://beginnersbook.com/2022/07/java-program-to-find-the-longest-repeating-sequence-in-a-string/) - In this tutorial, you will learn how to write a java program to find the longest repeating sequence in a string. For example, if the given string is "abracadabra" then the longest repeating sequence in this string would be "abra". Highlighting longest re-occurring sequence in the string: abrakadabra. Program to find the longest reoccurring sequence - [Java Program to find longest substring without repeating characters](https://beginnersbook.com/2022/07/java-program-to-find-longest-substring-without-repeating-characters/) - In this tutorial, you will learn how to write a java program to find longest substring without repeating characters. For example, if a string is "TEXT", the longest substring in "TEXT" without repeating character is: "TEX". Similarly longest substring with non-repeating characters in a string "AAAAA" is "A". Here we will write a java program - [Java Program to find all subsets of a string](https://beginnersbook.com/2022/07/java-program-to-find-all-subsets-of-a-string/) - In this article, you will learn how to write a java program to find all subsets of a String. If the number of characters in a given string is n then the number of possible subsets of that string would be: n(n+1)/2. For example: if the length of a string is 4 then the number - [Java Program to divide a String in 'n' equal parts](https://beginnersbook.com/2022/07/java-program-to-divide-a-string-in-n-equal-parts/) - In this article, we will write a java program to divide a string in 'n' equal parts. There are few things which we need to check before we divide the given string in equal parts. First thing we can check is to divide the number of characters in the string by the 'n', if the - [File Organization in DBMS](https://beginnersbook.com/2022/06/file-organization-in-dbms/) - In this article, you will learn what is file organization and what are benefits of doing it. We already know that data is stored in database, when we refer this data in terms of RDBMS we call it collection of inter-related tables. However in layman terms you can say that the data is stored in - [Validation Based Protocol in DBMS](https://beginnersbook.com/2022/07/validation-based-protocol-in-dbms/) - Validation based protocol avoids the concurrency of the transactions and works based on the assumption that if no transactions are running concurrently then no interference occurs. This is why it is also called Optimistic Concurrency Control Technique. In this protocol, a transaction doesn't make any changes to the database directly, instead it performs all the - [Timestamp based Ordering Protocol in DBMS](https://beginnersbook.com/2022/07/timestamp-based-ordering-protocol/) - In the previous chapter, you learned lock based protocol in DBMS to maintain the integrity of database. In this chapter, you will learn Timestamp based ordering protocol. What is Timestamp Ordering Protocol? Timestamp ordering protocol maintains the order of transaction based on their timestamps.A timestamp is a unique identifier that is being created by the - [Lock based Protocol in DBMS](https://beginnersbook.com/2022/07/lock-based-protocol-in-dbms/) - A lock is kind of a mechanism that ensures that the integrity of data is maintained. It does that, by locking the data while a transaction is running, any transaction cannot read or write the data until it acquires the appropriate lock. There are two types of a lock that can be placed while accessing - [Concurrency Control in DBMS](https://beginnersbook.com/2017/09/concurrency-control-in-dbms/) - When more than one transactions are running simultaneously there are chances of a conflict to occur which can leave database to an inconsistent state. To handle these conflicts we need concurrency control in DBMS, which allows transactions to run simultaneously but handles them in such a way so that the integrity of data remains intact. - [Deadlock in DBMS](https://beginnersbook.com/2015/04/deadlock-in-dbms/) - A deadlock is a condition wherein two or more tasks are waiting for each other in order to be finished but none of the task is willing to give up the resources that other task needs. In this situation no task ever gets finished and is in waiting state forever. Coffman conditions Coffman stated four - [Log-Based Recovery in DBMS](https://beginnersbook.com/2022/07/log-based-recovery-in-dbms/) - In the previous chapters, you learned how to identify a recoverable schedule and what kind of failures can occur in DBMS. In this chapter, you will learn how to recover a failed transaction using Log-based recovery in DBMS. When a transaction fails, it is important to rollback the transaction so that changes made by failed - [Failure Classification in DBMS](https://beginnersbook.com/2022/07/failure-classification-in-dbms/) - In DBMS there are several transactions running in a specified schedule. However sometimes these transactions fail due to several reasons. In previous tutorial, we learned how to identify a recoverable schedule. In this guide, we will discuss the types of failures that can occur in DBMS. Failures in DBMS are classified as follows: Transaction failureUnderlying - [Recoverability of Schedule in DBMS](https://beginnersbook.com/2022/07/recoverability-of-schedule-in-dbms/) - In this guide, you will learn a very important concept in DBMS: Recoverability of Schedule. There are times when few transactions in a schedule fail, due to a software or hardware issue. In that case, it becomes important to rollback these failed transactions along with those successful transactions that have used the value updated by - [DBMS View Serializability](https://beginnersbook.com/2018/12/dbms-view-serializability/) - In the last tutorial, we learned Conflict Serializability. In this article, we will discuss another type of serializability which is known as View Serializability. What is View Serializability? View Serializability is a process to find out that a given schedule is view serializable or not. To check whether a given schedule is view serializable, we - [DBMS Architecture](https://beginnersbook.com/2018/11/dbms-architecture/) - In the previous tutorials, we learned basics of DBMS. In this guide, we will see the DBMS architecture. Database management systems architecture will help us understand the components of database system and the relation among them. The architecture of DBMS depends on the computer system on which it runs. For example, in a client-server DBMS - [DBMS vs RDBMS: Difference between DBMS and RDBMS](https://beginnersbook.com/2022/07/dbms-vs-rdbms-difference-between-dbms-and-rdbms/) - In this guide, you will learn the difference between DBMS (Database Management System) and RDBMS (Relational Database Management System). What is a DBMS (Database Management System)? Database management system is nothing but a software that maintains the data on a system. It allows the user to perform various operations on the data such as read, - [DBMS SQL Insert Statement](https://beginnersbook.com/2022/07/dbms-sql-insert-statement/) - INSERT statement is used to insert the data into the table in database. You can insert values of specified columns or an entire record containing the values for all the columns of the table. In this guide, you will learn how to use SQL Insert statement with examples. Syntax: For inserting an entire row with - [DBMS SQL Select Statement](https://beginnersbook.com/2022/07/dbms-sql-select-statement/) - SELECT statement is used to fetch (retrieve) the data from the database. In this tutorial, you will learn how to retrieve the desired data from the database using SELECT statement. Syntax: SELECT column1, column2, ... FROM table_name; DBLS SQL Select Examples: Let's say we have a table STUDENT that has 5 rows and the table - [DBMS: SQL Drop Table](https://beginnersbook.com/2022/07/dbms-sql-drop-table/) - DROP TABLE statement is used to delete the existing table from the database. There is another statement TRUNCATE TABLE which is also used to delete the entire table. The difference between these two statements is that TRUNCATE TABLE deletes all the rows from the table but table still exists in the database, however the DROP - [DBMS: SQL Create Table](https://beginnersbook.com/2022/07/dbms-sql-create-table/) - CREATE TABLE statement is used to create a table in database. This statement creates a table with the specified column and datatypes. Syntax: CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, .... columnN datatype ); Example: The following SQL query creates a table STUDENT in the database with four attributes (columns): STU_ID to - [DBMS: SQL Operator](https://beginnersbook.com/2022/07/dbms-sql-operator/) - In this article, you will learn the various operators that can be used in SQL queries. Operators in SQL can be categorised as follows: Arithmetic operatorComparison operatorLogical operator 1. SQL Arithmetic Operators Arithmetic Operator Examples: This can be simply used to add two numbers: SELECT 50 + 30; Result: 80 Similarly subtraction operator can be - [DBMS: SQL Commands DDL, DML, DCL, TCL, and DQL](https://beginnersbook.com/2022/07/dbms-sql-commands-ddl-dml-dcl-tcl-and-dql/) - SQL commands are instructions to the database to perform a specific operation. For example, you can use SELECT command to read the data from database, you can use UPDATE command to update data in database. There are several commands that are available in SQL for various type of tasks and these commands are divided in - [DBMS: Advantages of SQL](https://beginnersbook.com/2022/07/dbms-advantages-of-sql/) - In this article, we will discuss the advantages of SQL. We have already seen the several features of SQL in characteristics of SQL. Here, we will cover some of the advantages that we get while using SQL as a database language. 1. Fast Response Time You can quickly retrieve large amount of data from database ## Pages - [Tutorials For Beginners - BeginnersBook](https://beginnersbook.com/) - Java › Java Examples › Java Collections › Servlet › Java String › jQuery › C › C Examples › Java Swing › C++ › DBMS › Perl › JSP › JSTL › JSON › Java I/O › MongoDB › Kotlin › WordPress › - [Java Tutorial for Beginners](https://beginnersbook.com/java-tutorial-for-beginners-with-examples/) - This java tutorial would help you learn Java like a pro. I have shared 1000+ tutorials on various topics of Java, including core java and advanced Java concepts along with several Java programming examples to help you understand better. All the tutorials are provided in a easy to follow systematic manner. It is for everyone, - [Privacy Policy - BeginnersBook.com](https://beginnersbook.com/privacy/) - If you have any questions or require any more information about beginnersbook privacy policy, please feel free to email us at help@beginnersbook.com. At Beginnersbook, we take privacy of our visitors very seriously. This "Privacy Policy" page will help you understand, what personal information is collected by Beginnersbook and how it is used. We take extreme - [Collections in Java with Example Programs](https://beginnersbook.com/java-collections-tutorials/) - The Java Collections Framework is a collection of interfaces and classes, which helps in storing and processing the data efficiently. This framework has several useful classes which have tons of useful functions which makes a programmer task super easy. I have written several tutorials on Collections in Java. All the tutorials are shared with examples - [Search the web](https://beginnersbook.com/search-the-web/) - [Search](https://beginnersbook.com/search/) - [All tutorials](https://beginnersbook.com/tutorials/) - I have shared several tutorials on beginnersbook.com. Here is the list of all tutorials. Java Tutorials on Java topics. Java Tutorial Java OOPs Concepts Java Exception handling Java multithreading Java String Java Collections Java Regular Expressions Tutorial Java Serialization Java Annotations Tutorial Java Enum Tutorial Java autoboxing and unboxing tutorial Java I/O Tutorial Java 8 - [Get in touch with us](https://beginnersbook.com/contact-us/) - We love hearing from readers and visitors. We really appreciate you taking the time to get in touch. Please fill the form. Loading... - [Java I/O tutorial with examples](https://beginnersbook.com/java-io-tutorial-with-examples/) - I have written several tutorials on Java I/O. You can find out the links of all the tutorials below. The tutorials are explained with the help of very basic and simple examples so that even a beginner can learn with ease. I will continue to write more tutorials on I/O and will add the links - [SQL tutorial for beginners with examples](https://beginnersbook.com/sql-tutorial-for-beginners-with-examples/) - SQL stands for Structured Query Language. It is used for fetching, storing and modifying the data in relational database. Below are the tutorial links, start learning SQL in the given order. Happy learning!! Database Statements CREATE database statement DROP database statement SELECT database statement Table Statements CREATE table statement DROP table statement Query SELECT Query UPDATE - [JSP tutorial for beginners with examples - Java Server Pages](https://beginnersbook.com/jsp-tutorial-for-beginners/) - Java Server Pages (JSP) is a server side technology for developing dynamic web pages. This is mainly used for implementing presentation layer (GUI Part) of an application. A complete JSP code is more like a HTML with bits of java code in it. JSP is an extension of servlets and every JSP page first gets - [JSTL functions and Core Tags- JSTL(JSP Standard Tag Lib) Tutorial](https://beginnersbook.com/jsp-jstl-tutorial-jstl-functions-and-core-tags/) - JSTL stands for JSP standard tag Library which is a collection of very useful core tags and functions. These tags and functions will help you write JSP code efficiently.JSTL Core TagsBelow is the collection of tutorials on JSTL core tags. Each tutorial is explained with the help of screenshots and proper examples. The following line ## Categories - [SEO](https://beginnersbook.com/category/seo/) - [Tech Pages](https://beginnersbook.com/category/technology/) - [WordPress](https://beginnersbook.com/category/wordpress/) - [JAVA Guide](https://beginnersbook.com/category/technology/java-guide/) - [Java Servlet tutorial](https://beginnersbook.com/category/technology/java-servlet-tutorial/) - [JSP tutorial](https://beginnersbook.com/category/jsp-tutorial/) - [JSTL](https://beginnersbook.com/category/jsp-tutorial/jstl/) - [Java Examples](https://beginnersbook.com/category/java-examples/) - [c-programming](https://beginnersbook.com/category/c-programming/) - [CSS Tutorials](https://beginnersbook.com/category/css-tutorials/) - [SQL](https://beginnersbook.com/category/sql/) - [C Programs](https://beginnersbook.com/category/c-programs/) - [JSON](https://beginnersbook.com/category/json/) - [DBMS](https://beginnersbook.com/category/dbms/) - [Perl](https://beginnersbook.com/category/perl/) - [C++ Programs](https://beginnersbook.com/category/c-programs-2/) - [java](https://beginnersbook.com/category/learn-java/) - [Learn C++](https://beginnersbook.com/category/learn-c/) - [MongoDB Tutorial](https://beginnersbook.com/category/mongodb-tutorial/) - [Kotlin Tutorial](https://beginnersbook.com/category/kotlin-tutorial/) - [Python Examples](https://beginnersbook.com/category/python-examples/) - [Python Tutorial](https://beginnersbook.com/category/python-tutorial/) - [DS Tutorial](https://beginnersbook.com/category/ds-tutorial/) - [XML Tutorial](https://beginnersbook.com/category/xml-tutorial/) - [Computer Network](https://beginnersbook.com/category/computer-network/) - [jQuery](https://beginnersbook.com/category/jquery/) - [Excel](https://beginnersbook.com/category/excel/) - [Programs](https://beginnersbook.com/category/programs/) - [Q&A](https://beginnersbook.com/category/qna/) - [History](https://beginnersbook.com/category/qna/history/) ## Tags - [Java Basics](https://beginnersbook.com/tag/java-basics/) - [](https://beginnersbook.com/tag/399/) - [Java-Multithreading](https://beginnersbook.com/tag/java-multithreading/) - [Java-Array](https://beginnersbook.com/tag/java-array/) - [Java-AWT](https://beginnersbook.com/tag/java-awt/) - [C-Library](https://beginnersbook.com/tag/c-library/) - [C-String](https://beginnersbook.com/tag/c-string/) - [Java8-Features](https://beginnersbook.com/tag/java8-features/) - [Java-9](https://beginnersbook.com/tag/java-9/) - [Java-Conversion](https://beginnersbook.com/tag/java-conversion/) - [Java-Date](https://beginnersbook.com/tag/java-date/) - [Java-IO](https://beginnersbook.com/tag/java-io/) - [Java-StringBuilder](https://beginnersbook.com/tag/java-stringbuilder/) - [Collections](https://beginnersbook.com/tag/java-collections/) - [Java-HashSet](https://beginnersbook.com/tag/java-hashset/) - [Java-HashMap](https://beginnersbook.com/tag/java-hashmap/) - [Java-TreeSet](https://beginnersbook.com/tag/java-treeset/) - [Java-ArrayList](https://beginnersbook.com/tag/java-arraylist/) - [Java-Set](https://beginnersbook.com/tag/java-set/) - [Java-LinkedList](https://beginnersbook.com/tag/java-linkedlist/) - [Java-Swing](https://beginnersbook.com/tag/java-swing/) - [WP-Plugins](https://beginnersbook.com/tag/wp-plugins/) - [Exception-Handling](https://beginnersbook.com/tag/exception-handling/) - [Interview-Preparation](https://beginnersbook.com/tag/interview-preparation/) - [Java-Strings](https://beginnersbook.com/tag/java-strings/) - [Java-OOPs](https://beginnersbook.com/tag/java-oops/) - [Java-TreeMap](https://beginnersbook.com/tag/java-treemap/) - [Java-HashTable](https://beginnersbook.com/tag/java-hashtable/) - [Java-Vector](https://beginnersbook.com/tag/java-vector/) - [Java-LinkedHashSet](https://beginnersbook.com/tag/java-linkedhashset/) - [C-Function](https://beginnersbook.com/tag/c-function/) - [Java Numbers](https://beginnersbook.com/tag/java-numbers/) - [StringBuffer](https://beginnersbook.com/tag/stringbuffer/) - [Java Math](https://beginnersbook.com/tag/java-math/) - [Integer](https://beginnersbook.com/tag/integer/)