- 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 267 Articles for Java8
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
689 Views
This is an in-place comparison-based sorting algorithm. Here, a sub-list is maintained which is always sorted. For example, the lower part of an array is maintained to be sorted. An element which is to be inserted in this sorted sub-list has to find its appropriate place and then it has to be inserted there. Hence the name, insertion sort.The array is searched sequentially and unsorted items are moved and inserted into the sorted sub-list (in the same array).Algorithm1.If it is the first element, it is already sorted. return 1; 2.Pick next element 3.Compare with all elements in the sorted sub-list ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
3K+ Views
Selection sort is a simple sorting algorithm. This sorting algorithm is an in-place comparison-based algorithm in which the list is divided into two parts, the sorted part at the left end and the unsorted part at the right end. Initially, the sorted part is empty and the unsorted part is the entire list.The smallest element is selected from the unsorted array and swapped with the leftmost element, and that element becomes a part of the sorted array. This process continues moving unsorted array boundary from one element to the right.Algorithm1.Set MIN to location 0 2.Search the minimum element in the ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
4K+ Views
Factorial of a positive integer n is the product of all values from n to 1. For example, the factorial of 3 is (3 * 2 * 1 = 6). Algorithm1. Take integer variable A 2. Assign a value to the variable 3. From value, A up to 1 multiply each digit and store 4. The final stored value is factorial of AExampleimport java.util.Scanner; public class Factorial { public static void main(String args[]){ int i, factorial=1, number; System.out.println("Enter the number to which you need to find the factorial:"); Scanner sc = new Scanner(System.in); number = sc.nextInt(); for(i = 1; i
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
2K+ Views
Fibonacci Series generates subsequent number by adding two previous numbers. Fibonacci series starts from two numbers − F0 & F1. The initial values of F0 & F1 can be taken 0, 1 or 1, 1 respectively.Fn = Fn-1 + Fn-2Algorithm1. Take integer variable A, B, C 2. Set A = 1, B = 1 3. DISPLAY A, B 4. C = A + B 5. DISPLAY C 6. Set A = B, B = C 7. REPEAT from 4 - 6, for n timesExampleLive Demopublic class FibonacciSeries2{ public static void main(String args[]) { int a, b, c, i, n; n = 10; a = b = 1; System.out.print(a+" "+b); for(i = 1; i
![V Jyothi](https://www.tutorialspoint.com/assets/profiles/13530/profile/60_77592-1512648869.jpg)
413 Views
The StringTokenizer class of the java.util package allows an application to break a string into tokens.This class is a legacy class that is retained for compatibility reasons although its use is discouraged in new code.Its methods do not distinguish among identifiers, numbers, and quoted strings.This class methods do not even recognize and skip comments.ExampleLive Demoimport java.util.*; public class Sample { public static void main(String[] args) { // creating string tokenizer StringTokenizer st = new StringTokenizer("Come to learn"); // checking next token System.out.println("Next token is : " + st.nextToken()); } }OutputNext token is : Come
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/32020/profile/60_153038-1524898298.jpg)
164 Views
public class RegexOccur { public static void main(String args[]) { String str = "java is fun so learn java"; String findStr = "java"; int lastIndex = 0; int count = 0; while(lastIndex != -1) { lastIndex = str.indexOf(findStr,lastIndex); if(lastIndex != -1) { count ++; lastIndex += findStr.length(); } } System.out.println(count); } }Output2
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/32020/profile/60_153038-1524898298.jpg)
980 Views
regex ^((?!kk).)*$ returns true if a line does not contain kk, otherwise returns falseExamplepublic class RegTest { public static void main(String[] args) { // TODO Auto-generated method stub String s="tutorials"; boolean i=s.matches("^((?!kk).)*$"); System.out.println(i); } }
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/32020/profile/60_153038-1524898298.jpg)
221 Views
the syntax? i:x makes the string search case-insensitive. for egpublic class RegCaseSense { public static void main(String[] args) { String stringSearch = "HI we are at java class."; // this won't work because the pattern is in upper-case System.out.println("Try this 1: " + stringSearch.matches(".*CLASS.*")); // the magic (?i:X) syntax makes this search case-insensitive, so it returns true System.out.println("Try this 2: " + stringSearch.matches("(?i:.*CLASS.*)")); } }
![Sravani S](https://www.tutorialspoint.com/assets/profiles/13538/profile/60_67753-1512711355.jpg)
6K+ Views
Yes! Java supports constructor overloading. In constructor loading, we create multiple constructors with the same name but with different parameters types or with different no of parameters.ExampleLive Demopublic class Tester { private String message; public Tester(){ message = "Hello World!"; } public Tester(String message){ this.message = message; } public String getMessage(){ return message ; } public void setMessage(String message){ this.message = message; } public static void main(String[] args) { Tester tester = new Tester(); System.out.println(tester.getMessage()); Tester tester1 = new Tester("Welcome"); System.out.println(tester1.getMessage()); } } OutputHello World! Welcome
![Janani Jaganathan](https://www.tutorialspoint.com/assets/profiles/506990/profile/60_3923617-1661405985.jpg)
12K+ Views
Anonymous object in Java means creating an object without any reference variable. Generally, when creating an object in Java, you need to assign a name to the object. But the anonymous object in Java allows you to create an object without any name assigned to that object. So, if you want to create only one object in a class, then the anonymous object would be a good approach. Reading this article, you will learn what an anonymous object is and how to create and use anonymous objects in Java. Let's get started! Anonymous Object in Java Anonymous means Nameless. An ... Read More