Use the lastIndexOf() method to search for last index of a group of characters. Let’s say the following is our string.String myStr = "pqrstuvwxyzpqrst";Searching for the substring “pqrs” in the string to get the last index of its occurring in the string. We begin the search from index 3.int begnIndex = 3; strLastIndex = myStr.indexOf("pqrs", begnIndex);The following is an example, wherein we are searching for the last index of the substring “pqrs”Example Live Demopublic class Demo { public static void main(String[] args) { String myStr = "pqrstuvwxyzpqrst"; int strLastIndex = 0; System.out.println("String: "+myStr); strLastIndex = myStr.lastIndexOf("pqrs"); System.out.println("The last index of ... Read More
Narrowing conversion is needed when you convert from a larger size type to a smaller size. This is for incompatible data types, wherein automatic conversions cannot be done.Let us see an example wherein we are converting long to integer using Narrowing Conversion.Example Live Demopublic class Demo { public static void main(String[] args) { long longVal = 878; int intVal = (int) longVal; System.out.println("Long: "+longVal); System.out.println("Integer: "+intVal); } }OutputLong: 878 Integer: 878Let us see another example, wherein we are converting double to long using Narrowing Conversion.Example Live Demopublic class Demo { public static void main(String[] args) { double doubleVal = 299.89; long longVal = (long)doubleVal; ... Read More
In this section we will see how ADC (Analog to Digital Converter) works with Intel 8085 Microprocessor. The Analog to Digital Conversion is a quantizing process. Here the analog signal is represented by equivalent binary states. The A/D converters can be classified into two groups based on their conversion techniques.In the first technique it compares given analog signal with the initially generated equivalent signal. In this technique, it includes successive approximation, counter and flash type converters. In another technique it determines the changing of analog signals into time or frequency. This process includes integrator-converters and voltage-to-frequency converters. The first process ... Read More
Serialization is the process of changing the state of an object into the byte stream so that the byte stream can return back into a copy of the objectIn Java, an object is said to be serializable if its class or parent classes implement either the Serializable interface or the Externalizable interface.Deserialization is converting the serialized object back into a copy of the object.There are three cases of Object Serialization with inheritance.The child class is automatically serializable if the parent class is serializableA child class can still be serialized even if the parent class is not serializableIf we want the ... Read More
If the static keyword is applied to any method, it becomes a static method.If a method is declared as static, it is a member of a class rather than belonging to the object of the class. It can be called without creating an object of the class. A static method also has the power to access static data members of the class.There are a few restrictions imposed on a static methodThe static method cannot use non-static data member or invoke non-static method directly.The this and super cannot be used in static context.The static method can access only static type data ... Read More
Good manners mean the social and polite behavior that a person possesses. Good manners play a vital role in building human relations. It is the back bone of a stable social pattern. Good manners imply towards the certain values and behavior of human relationship which keeps the society alive.Good Manners refers to being humble, polite, respectful, courteous and well-cultured social behavior. A well-mannered man/woman is respected and esteemed wherever he goes and in whatever condition of life, he may be. Among students, in particular, the preservation of good manners is a boon and it costs nothing.Why do we need Good MannersWe ... Read More
Streams in Java have a few terminal operations. They are as follows −collect − The collect method returns the outcome of the intermediate operationsList id = Arrays.asList(“Classes", "Methods", "Members"); List output = id.stream().filter(s -> s.startsWith("M")).collect(Collectors.toList());reduce − The reduce method is reduces the elements of a stream into a single element having a certain value after computation. The BinaryOperator is an argument of the reduce method.List list1 = Arrays.asList(11, 33, 44, 21); int even = list1.stream().filter(x -> x % == 0).reduce(0, (ans, i) -> ans+i);forEach − This method iterates through every element in the streamList list1= Arrays.asList(1, 3, 5, 7); List ... Read More
The insert() method of the StringBuffer class inserts the String starting from an index specified in the parameter along with the stringThe syntax of the insert method is −original_string.insert( index , var)where var is the variable to be inserted and index is the position where the variable var is to be inserted.Let us see an example program −Example Live Demopublic class Example { public static void main(String[] args) { StringBuffer str = new StringBuffer("Hello World"); String a = "Wonderful "; str.insert(6, a); System.out.println(str); } }OutputHello Wonderful World
The Intel 8253 is programmable Interval Timers (PTIs) designed for microprocessors toper form timing and counting functions using three 16-bit registers. Each counter has 2 input pins, i.e. Clock & Gate, and 1 pin for“OUT” output. To operate a counter, a 16-bit count is loaded in its register. On command, it begins to decrement the count until it reaches 0, then it generates a pulse that can be used to interrupt the CPU.Features of 8253It has three independent 16-bit down counters.It can handle inputs from DC to 10MHz.These three counters can be programmed for either binary or BCD count.It is ... Read More
The capacity() method returns the current capacity. It is a part of the StringBuffer. It is the quantity of storage present for recently inserted characters, after which an allocation occurs.Declaration - The capacity() method is declared in the java.lang.StringBuffer class as follows −public int capacity()The capacity of a StringBuffer object can be set by inserting the value to be set while instantiating the StringBuffer class.Let us see an example program showing how the capacity value can be set.Example Live Demoimport java.lang.*; public class Example { public static void main(String[] args) { StringBuffer b = new StringBuffer(100); ... Read More