- 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 338 Articles for Java Programming
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
14K+ Views
The java.lang.Enum class is the common base class of all Java language enumeration types.Class DeclarationFollowing is the declaration for java.lang.Enum class -public abstract class Enum extends Object implements Comparable, SerializableWe can compare enum variables using the following ways.Using Enum.compareTo() method. compareTo() method compares this enum with the specified object for order.Using Enum.equals() method. equals() method returns true if the specified object is equal to this enum constant.Using == operator. The == operator checks the type and makes a null-safe comparison of the same type of enum constants.ExampleLive Demopublic class Tester { // enum showing topics ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
366 Views
Prior to Java 2, Java provided ad hoc classes such as Dictionary, Vector, Stack, and Properties to store and manipulate groups of objects. Although these classes were quite useful, they lacked a central, unifying theme. Thus, the way that you used Vector was different from the way that you used Properties.The collections framework was designed to meet several goals, such as −The framework had to be high-performance. The implementations for the fundamental collections (dynamic arrays, linked lists, trees, and hash tables) were to be highly efficient.The framework had to allow different types of collections to work in a similar manner ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
781 Views
Java provides an assignment operator to copy the values but no operator to copy the object. Object class has a clone method which can be used to copy the values of an object without any side-effect. Assignment operator has a side-effect that when a reference is assigned to another reference then a new object is not created and both the reference point to the same object. This means if we change the value in one object then same will reflect in another object as well. clone() method handles this problem. See the below example.ExampleLive Demopublic class Tester { public ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
5K+ Views
Internet connectivity can be checked using java.net.URL and java.net.URLConnection class. Following are the required steps.Create a URL object and pass it the URL say GoogleCall URL.openConnection() method to get a URLConnection object.Call URLConnection.connect() method to check the internet connectivity. connect() method opens a communications link to the resource referenced by the passed URL if a connection has not already been established.Exampleimport java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; public class Tester { public static void main(String[] args) { try { URL url = new URL("http://www.google.com"); URLConnection connection ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
7K+ Views
Checked exceptionsA checked exception is an exception that occurs at the compile time, these are also called as compile time exceptions. These exceptions cannot simply be ignored at the time of compilation, the programmer should take care of (handle) these exceptions.For example, if you use FileReader class in your program to read data from a file, if the file specified in its constructor doesn't exist, then a FileNotFoundException occurs, and the compiler prompts the programmer to handle the exception.ExampleLive Demoimport java.io.File; import java.io.FileReader; public class FilenotFound_Demo { public static void main(String args[]) { ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
123 Views
The java.io.File class provides useful methods on file. This example shows how to check a file hidden or not by using the file.isHidden() method of File class.Exampleimport java.io.File; public class Main { public static void main(String[] args) { File file = new File("C:/java.txt"); System.out.println(file.isHidden()); } }ResultThe above code sample will produce the following result (if the file "java.txt" exists and is hidden in 'C' drive).true
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
5K+ Views
The java.io.File class provides useful methods on file. This example shows how to check a file existence by using the file.exists() method of File class.Exampleimport java.io.File; public class Main { public static void main(String[] args) { File file = new File("C:/java.txt"); System.out.println(file.exists()); } }ResultThe above code sample will produce the following result (if the file "java.txt" exists in 'C' drive).trueExampleThe following is another simple example of the file exist or not in java.import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintpWriter; import java.nio.file.FileAlreadyExistsException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
8K+ Views
Byte StreamsJava byte streams are used to perform input and output of 8-bit bytes. Though there are many classes related to byte streams but the most frequently used classes are, FileInputStream and FileOutputStream. Following is an example which makes use of these two classes to copy an input file into an output file −Exampleimport java.io.*; public class CopyFile { public static void main(String args[]) throws IOException { FileInputStream in = null; FileOutputStream out = null; try { in = new ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
1K+ Views
Chained exception helps to relate one exception to other. Often we need to throw a custom exception and want to keep the details of an original exception that in such scenarios we can use the chained exception mechanism. Consider the following example, where we are throwing a custom exception while keeping the message of the original exception.ExampleLive Demopublic class Tester { public static void main(String[] args) { try { test(); }catch(ApplicationException e) { System.out.println(e.getMessage()); } } ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
966 Views
Ideally No. But, using the tricky code, a subclass can override a private method as well. See the example below −ExampleLive Democlass A { private void display() { System.out.println("A.display"); } public void callDisplay() { System.out.println("A.callDisplay"); display(); } } class B extends A { private void display() { System.out.println("B.display"); } public void callDisplay() { System.out.println("B.callDisplay"); display(); } } public class Tester { public static void main(String[] args) { ... Read More