How to find String length in java string method

Get String length with String length() method To find String length in java there is a method length(). This method is used to get the length of the string. The signature of length method is: public int length() The length method returns the length of the string. it counts the number of Unicode in string. … Read more

Byte Streams in Java

In java programming, to perform input and output of 8-bit, Byte stream is used. Most common byte streams classes are, FileInputStream and FileOutputStream. FileInputStream : FileInputStream is used for reads one byte at a time . FileOutputStream : FileOutputStream is used for writes one byte at a time Writing Bytes Example: Write a program, to write a bytes to … Read more

Inheritance in Java-Types and Examples

Inheritance in Java is the process of acquiring the properties of one class object into another class object. It allows the hierarchical classification. Inheritance also provides the facility of reusability. In Java programming, a class that is inherited is called a superclass or sub class or parent class and class that does the inheriting is … Read more

Java program to swap two numbers

Java program to swap two numbers is a very basic example and can be used in any programming language. This is a beginner-level question for all programmers. Here different ways are given for swapping two numbers. All below java programs shows only method to implement this. Swapping of two numbers can be done in any … Read more

One dimensional array in java with examples

Here we will discuss One dimensional array in java and cover basic examples What is One dimensional (Single dimensional) array in java An array is a collection of similar elements. All array elements are stored in the contiguous memory location. One dimensional or single-dimensional array is an array with one dimension. One dimensional array declaration … Read more

String in Java- Constructor methods and examples

Java String is defined in java.lang.String. Java String is a sequence of characters quoted in double quote (” “). Java String Constructors Sr No Constructor and description 1 String() Create a new empty string object 2 String(byte[] bytes) Construct a string object with byte array 3 String(char[] value) Construct a string object with character array … Read more

Producer Consumer Problem in Java

In computing, producer–consumer problem is also known as the bounded buffer problem. In the producer–consumer problem there are two processes, first is the producer and the second is the consumer, who share a common, fixed-size buffer.  The producer’s job is to generate data, put it into the buffer and start again. At the same time, … Read more

DataInputStream and DataOutputStream for primitive data

In java, a basic input-output stream provides a method for reading & writing bytes or characters in a file. If we want to read-write primitive data types (such as int, float, etc.) then we can use filter classes to filter data in the original stream. DataInputStream & DataOutputStream are two filter classes used for creating … Read more

Date to Timestamp conversion

To convert java.util.Date to java.sql.TimeStamp as given below

String matching and comparing in Java

equals(Object anObject) compare String with object and returns boolean value, for comparing two strings if both are strictly equals(case sensitive) then it will return true else false value. equalsIgnoreCase(String anotherString) compare two strings with case ignorance and return boolean value. compareTo(String anotherString) compare two strings and return int value if both are equal(with case) … Read more