Java - String charAt Example - How to get first and last characters

The charAt(int index) method of java.lang.String class can be used to retrieve a character from given index. The method returns a character, you can see its return type is char. The index starts from zero and ranges to length() - 1 where length() return the length of String. It's similar to an array where the first element is stored at zeroth index and the last element is stored at length -1 index because String is nothing but backed by a character array. If the value of the index is invalid i.e. it's lower than zero or negative or higher than length - 1 then this method throws an IndexOutOfBoundsException. In this article, I'll show you a couple of example of how to use the charAt() method to retrieve a character from String in Java.

2 Ways to Add Binary Numbers in Java - Coding

In the last article, I have shown you how to subtract binary numbers in Java and today, you will learn the opposite i.e. how to add binary numbers in Java. You can do binary addition in Java either by writing your own logic or by taking advantage of the Java API, which allows you to convert a binary String into a binary number. Though, if you want you can also use the logic I have shared in my earlier post about how to check binary numbers to verify input before converting it to a binary number. In this article, we'll take a look at both methods of adding two binary numbers in Java.

JDBC - How to get Row and Column Count From ResultSet in Java

One of the common problem in JDBC is that there is no way to get the total number of records returned by an SQL query. When you execute a Statement, PreparedStatement, or CallableStatement using execute()or executeQuery() they return ResultSet and it doesn't have any method to return the total number of records it is holding. The only way to find the total number of records is keeping the count while you are iterating over ResultSet while fetching the result. This way, you can print the total number of rows returned the SQL query but only after you have processed all records and not before, which may not be the right way and incur significant performance cost if the query returns a large number of rows.

Java - Convert String to Boolean Example

There are two ways to convert a String to boolean in Java, first, by using Boolean.parseBoolean() method and second, by using Boolean.valueOf() method.The parseBoolean() method returns an equivalent boolean value of given String, for example, if you pass "true" it will return the primitive boolean value true. Similarly, if you pass "false" it will return false. The good thing about this method is that it is case insensitive, which means if you pass "true", "TRUE", or "True" you will still get a true boolean value.

How to Subtract two Binary Numbers in Java - Solution

Binary subtraction is very similar to binary addition which we have learned in the last article. In this tutorial, you will learn how to subtract two binary numbers. Similar to the last article, we'll see two ways, first by converting binary String to a binary number and then doing subtraction. You can use the Java API Integer.toString(number, radix) for that. On second solution you will learn to develop the logic to perform binary subtraction in Java program by using rules you might have learned in your computer classes. Here is a little summary of how binary subtraction works.