- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 4338 Articles for Java 8
![Vikyath Ram](https://www.tutorialspoint.com/assets/profiles/13780/profile/60_74413-1512648006.jpg)
84 Views
Following example compares two strings by using str compareTo (string), str compareToIgnoreCase(String) and str compareTo(object string) of string class and returns the ascii difference of first odd characters of compared strings.Example Live Demopublic class StringCompareEmp{ public static void main(String args[]) { String str = "Hello World"; String anotherString = "hello world"; Object objStr = str; System.out.println( str.compareTo(anotherString) ); System.out.println( str.compareToIgnoreCase(anotherString) ); System.out.println( str.compareTo(objStr.toString())); } }OutputThe above code sample will produce the following result.-32 0 0String compare by equals()This method compares ... Read More
![Fendadis John](https://www.tutorialspoint.com/assets/profiles/13534/profile/60_64028-1512539837.jpg)
4K+ Views
Generate OTP is now a requirement on most of the website now-a-days. In case of additional authentication, system generates a OTP password adhering to OTP policy of the company. Following example generates a unique OTP adhering to following conditions −It should contain at least one number.Length should be 4 characters.Exampleimport java.util.Random; public class Tester { public static void main(String[] args) { System.out.println(generateOTP(4)); } private static char[] generateOTP(int length) { String numbers = "1234567890"; Random random = new Random(); char[] otp = new ... Read More
![Vikyath Ram](https://www.tutorialspoint.com/assets/profiles/13780/profile/60_74413-1512648006.jpg)
7K+ Views
A method catches an exception using a combination of the try and catch keywords. A try/catch block is placed around the code that might generate an exception. Code within a try/catch block is referred to as protected code, and the syntax for using try/catch looks like the following −Syntaxtry { // Protected code } catch (ExceptionName e1) { // Catch block }The code which is prone to exceptions is placed in the try block. When an exception occurs, that exception occurred is handled by catch block associated with it. Every try block should be immediately followed either by ... Read More
![Fendadis John](https://www.tutorialspoint.com/assets/profiles/13534/profile/60_64028-1512539837.jpg)
393 Views
Following programs shows the float arithmetic can cause dubious result if integer values are used using float variables.Examplepublic class Tester { public static void main(String[] args) { float a = 500000000; float b = -500000000; float c = 1; float sumabc1 = a+(b+c); float sumabc2 =(a+b)+c; System.out.println("Floating Point Arithmetic"); System.out.println("a + ( b + c ) : " + sumabc1); System.out.println("(a + b) + c : " + sumabc2); ... Read More
![Vikyath Ram](https://www.tutorialspoint.com/assets/profiles/13780/profile/60_74413-1512648006.jpg)
6K+ Views
Following are the notable differences between super() and this() methods in Java. super()this()Definitionsuper() - refers immediate parent class instance.this() - refers current class instance.InvokeCan be used to invoke immediate parent class method.Can be used to invoke current class method.Constructorsuper() acts as immediate parent class constructor and should be first line in child class constructor.this() acts as current class constructor and can be used in parametrized constructors.OverrideWhen invoking a superclass version of an overridden method the super keyword is used.When invoking a current version of an overridden method the this keyword is used.Example Live Democlass Animal { String name; Animal(String name) ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
384 Views
With Java 8, Arrays class has a stream() methods to generate a Stream using the passed array as its source.DescriptionThe java.util.Arrays.stream() method returns a sequential Stream with the specified array as its source. −Arrays.stream(array)DeclarationFollowing is the declaration for java.util.Arrays.stream() methodpublic static Stream stream(T[] array)Type ParameterT − This is the type of the array elements.Parameterarray − This is the source array to be used.Return ValueThis method returns a stream for the array.ExampleThe following example shows the usage of java.util.Arrays.stream() method.Live Demoimport java.util.Arrays; public class Tester { public static void main(String args[]) { int data[] = { 1, ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
723 Views
Here is the syntax for declaring an array variable −SyntaxdataType[] arrayRefVar; // preferred way. or dataType arrayRefVar[]; // works but not preferred way.Note − The style dataType[] arrayRefVar is preferred. The style dataType arrayRefVar[] comes from the C/C++ language and was adopted in Java to accommodate C/C++ programmers.ExampleThe following code snippets are examples of this syntax −double[] myList; // preferred way. or double myList[]; // works but not preferred way.Creating ArraysYou can create an array by using the new operator with the following syntax −SyntaxarrayRefVar = new dataType[arraySize];The above statement does two things −It creates an array ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
27K+ Views
Array in Java can be copied to another array using the following ways.Using variable assignment. This method has side effects as changes to the element of an array reflects on both the places. To prevent this side effect following are the better ways to copy the array elements.Create a new array of the same length and copy each element.Use the clone method of the array. Clone methods create a new array of the same size.Use System.arraycopy() method. The arraycopy() can be used to copy a subset of an array.ExampleCreate a java class named Tester.Tester.javaLive Demopublic class Tester { public ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
1K+ Views
'+' operator in java can be used to add numbers and concatenate strings. Following rules should be considered.Only numbers as operands then result will be a number.Only strings as operands then result will be a concatenated string.If both numbers and strings as operands, then numbers coming before string will be treated as numbers.If both numbers and strings as operands, then numbers coming after string will be treated as a string.Above rule can be overridden using brackets().ExampleCreate a java class named Tester.Tester.javaLive Demopublic class Tester { public static void main(String args[]) { //Scenario 1: ... Read More
![Lakshmi Srinivas](https://www.tutorialspoint.com/assets/profiles/13528/profile/60_91717-1512651120.jpg)
468 Views
ASCII stands for American Standard Code for Information Interchange. There are 128 standard ASCII codes, each of which can be represented by a 7-digit binary number: 0000000 through 1111111.If you try to store a character into an integer value it stores the ASCII value of the respective character.Exampleimport java.util.Scanner; public class ASCIIValue { public static void main(String args[]){ System.out.println("Enter a character ::"); Scanner sc = new Scanner(System.in); char ch = sc.next().charAt(0); int asciiValue = ch; System.out.println("ASCII value of the given character is ::"+asciiValue); ... Read More