- 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
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
5K+ Views
The static methods belong to the class and they will be loaded into the memory along with the class. You can invoke them without creating an object. (using the class name as reference).Examplepublic class Sample{ static int num = 50; public static void demo(){ System.out.println("Contents of the static method"); } public static void main(String args[]){ Sample.demo(); } }OutputContents of the static methodThe "this" keyword is used as a reference to an instance. Since the static methods doesn’t have (belong to) any instance you cannot use the "this" reference within ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
16K+ Views
An exception is an issue (run time error) occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed.Exampleimport java.util.Scanner; public class ExceptionExample { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter first number: "); int a = sc.nextInt(); System.out.println("Enter second number: "); int b = sc.nextInt(); int c = a/b; System.out.println("The result is: "+c); ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
4K+ Views
Until Java 1.5 to read data from the user programmers used to depend on the character stream classes and byte stream classes.From Java 1.5 Scanner class was introduced. This class accepts a File, InputStream, Path and, String objects, reads all the primitive data types and Strings (from the given source) token by token using regular expressions.By default, whitespace is considered as the delimiter (to break the data into tokens).To read various datatypes from the source using the nextXXX() methods provided by this class namely, nextInt(), nextShort(), nextFloat(), nextLong(), nextBigDecimal(), nextBigInteger(), nextLong(), nextShort(), nextDouble(), nextByte(), nextFloat(), next().Passing Scanner object as a ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
2K+ Views
When you compile a program if you see this error it indicates that either you have not installed Java in your system properly or, you haven’t set the Path variable.The Path variable − The path environment variable is used to specify the set of directories which contains executional programs.When you try to execute a program from command line, the operating system searches for the specified program in the current directly, if available, executes it.In case the programs are not available in the current directory, operating system verifies in the set of directories specified in the ‘PATH’ environment variable.Setting Up the ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
699 Views
When you install Java in your system first of all you need to set the environment variables which are path and class path.PATH− The path environment variable is used to specify the set of directories which contains executional programs.When you try to execute a program from command line, the operating system searches for the specified program in the current directly, if available, executes it.In case the programs are not available in the current directory, operating system verifies in the set of directories specified in the ‘PATH’ environment variable.You need to set path for compiler (javac.exe) and JVM(java.exe), which exists in ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
262 Views
Strings are used to store a sequence of characters in Java, they are treated as objects. The String class of the java.lang package represents a String.You can create a String either by using the new keyword (like any other object) or, by assigning value to the literal (like any other primitive datatype).String stringObject = new String("Hello how are you"); String stringLiteral = "Welcome to Tutorialspoint";Concatenating StringsYou can concatenate Strings in Java in the following ways −Using the "+" operator: Java Provides a concatenation operator using this, you can directly add two String literalsExampleimport java.util.Scanner; public class StringExample { public ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
4K+ Views
Strings are used to store a sequence of characters in Java, they are treated as objects. The String class of the java.lang package represents a String.You can create a String either by using the new keyword (like any other object) or, by assigning value to the literal (like any other primitive datatype).Public class Sample{ Public static void main(String args[]){ String str1 = "Hello"; String str2 = "how are you"; } }Strings are immutable in Java i.e. once you create a String literal it cannot be modified.StorageSince all the String values we define ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
7K+ Views
Strings are used to store a sequence of characters in Java, they are treated as objects. The String class of the java.lang package represents a String.You can create a String either by using the new keyword (like any other object) or, by assigning value to the literal (like any other primitive datatype).Examplepublic class StringDemo { public static void main(String args[]) { String stringObject = new String("Hello how are you"); System.out.println(stringObject); String stringLiteral = "Welcome to Tutorialspoint"; System.out.println(stringLiteral); } }OutputHello how are you Welcome to TutorialspointStorage of ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
4K+ Views
Array is a container which can hold a fix number of entities, which are of the of the same type. Each entity of an array is known as element and, the position of each element is indicated by an integer (starting from 0) value known as index.Exampleimport java.util.Arrays; public class ArrayExample { public static void main(String args[]) { Number integerArray[] = new Integer[3]; integerArray[0] = 25; integerArray[1] = 32; integerArray[2] = 56; System.out.println(Arrays.toString(integerArray)); } }Output[25, 32, 56]Arrays are two types −Single dimensional arrays: Normal ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
865 Views
You can find whether a particular exists in a given array using any of the search algorithms. Here, we will see examples for linear search and binary search.Linear searchIterate through the array.Compare each element with the required element.import java.util.Scanner; public class ArraySearch { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the size of the array that is to be created: "); int size = sc.nextInt(); int[] myArray = new int[size]; System.out.println("Enter the elements of the array: "); for(int i=0; i