- 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 34486 Articles for Programming
![Vikyath Ram](https://www.tutorialspoint.com/assets/profiles/13780/profile/60_74413-1512648006.jpg)
756 Views
A thread can be created by implementing the Runnable interface and overriding the run() method. Then a Thread object can be created and the start() method called.A thread can be stopped using a boolean value in Java. The thread runs while the boolean value stop is false and it stops running when the boolean value stop becomes true.A program that demonstrates this is given as follows:Exampleclass ThreadDemo extends Thread { public boolean stop = false; int i = 1; public void run() { while (!stop) { try { ... Read More
![Arushi](https://www.tutorialspoint.com/assets/profiles/13510/profile/60_55588-1512537391.jpg)
3K+ Views
The thread priority determines when the processor is provided to the thread as well as other resources. It can be changed using the method setPriority() of class Thread.There are three static variables for thread priority in Java i.e. MIN_PRIORITY, MAX_PRIORITY and NORM_PRIORITY. The values of these variables are 1, 10 and 5 respectively.A program that demonstrates this is given as follows:Example Live Demopublic class ThreadDemo extends Thread { public void run() { System.out.println("Running..."); } public static void main(String[] args) { ThreadDemo thread1 = new ThreadDemo(); ThreadDemo thread2 = new ... Read More
![Fendadis John](https://www.tutorialspoint.com/assets/profiles/13534/profile/60_64028-1512539837.jpg)
585 Views
A thread can be created by implementing the Runnable interface and overriding the run() method. Then a Thread object can be created and the start() method called.The thread priority determines when the processor is provided to the thread as well as other resources. It can be changed using the method setPriority() of class Thread.A program that demonstrates changing the thread priorities using the method setPriority() in Java is given as follows:Example Live Demopublic class ThreadDemo extends Thread { public void run() { System.out.println("Running..."); } public static void main(String[] args) { ThreadDemo thread1 ... Read More
![Rishi Raj](https://www.tutorialspoint.com/assets/profiles/13777/profile/60_73169-1512647303.jpg)
779 Views
The final static field variable is a constant variable. There is only one copy of this variable available. It is mandatory to initialize the final static field variable explicitly as the default value for it is not provided by the JVM. Also, this variable cannot be reinitialized.A program that initializes the final static field variable using a static initialization block is given as follows:Example Live Demopublic class Demo { final static int num; static { System.out.println("Running static initialization block."); num = 6; } public static void main(String[] args) { ... Read More
![Arushi](https://www.tutorialspoint.com/assets/profiles/13510/profile/60_55588-1512537391.jpg)
2K+ Views
The HashCode for an Integer can be obtained using the hashCode() method in Java. This method does not accept any parameters and it returns a hash code value of the Integer object.A program that demonstrates the hashCode() method in Java is given as follows:Example Live Demoimport java.lang.*; public class Demo { public static void main(String args[]) { Integer i = new Integer(60); System.out.println("The integer value is: " + i); System.out.println("The Hashcode for the above value is: " + i.hashCode()); } }OutputThe integer value is: 60 The Hashcode for the above ... Read More
![Fendadis John](https://www.tutorialspoint.com/assets/profiles/13534/profile/60_64028-1512539837.jpg)
167 Views
The hashCode() method is used to obtain the hash code for a string. This method does not accept any parameters as it is a default method and it returns a hash code value.A program that demonstrates the hashCode() method in Java is given as follows:Example Live Demoimport java.io.*; public class Demo { public static void main(String args[]) { String str = new String("The sky is blue"); System.out.println("The string is: " + str); System.out.println("The Hashcode for the string is: " + str.hashCode()); } }OutputThe string is: The sky is blue The ... Read More
![Vikyath Ram](https://www.tutorialspoint.com/assets/profiles/13780/profile/60_74413-1512648006.jpg)
997 Views
When a garbage collector determines that no more references are made to a particular object, then the finalize() method is called by the garbage collector on that object. The finalize() method requires no parameters and does not return a value.A program that demonstrates the finalize() method in Java is given as follows:Example Live Demoimport java.util.*; public class Demo extends GregorianCalendar { public static void main(String[] args) { try { Demo obj = new Demo(); System.out.println("The current time is: " + obj.getTime()); obj.finalize(); ... Read More
![Rishi Raj](https://www.tutorialspoint.com/assets/profiles/13777/profile/60_73169-1512647303.jpg)
5K+ Views
A string representation of an object can be obtained using the toString() method in Java. This method is overridden so that the object values can be returned.A program that demonstrates this is given as follows:Example Live Democlass Student { private int rno; private String name; public Student(int r, String n) { rno = r; name = n; } public String toString() { return rno + " " + name; } } public class Demo { public static void main(String[] args) { Student ... Read More
![Fendadis John](https://www.tutorialspoint.com/assets/profiles/13534/profile/60_64028-1512539837.jpg)
729 Views
Static import means that the fields and methods in a class can be used in the code without specifying their class if they are defined as public static.The Math class methods sqrt() and pow() in the package java.lang are static imported. A program that demonstrates this is given as follows:Example Live Demoimport static java.lang.Math.sqrt; import static java.lang.Math.pow; public class Demo { public static void main(String args[]) { double num = 4.0; System.out.println("The number is: " + num); System.out.println("The square root of the above number is: " + sqrt(num)); ... Read More
![Arushi](https://www.tutorialspoint.com/assets/profiles/13510/profile/60_55588-1512537391.jpg)
15K+ Views
Static import means that the fields and methods in a class can be used in the code without specifying their class if they are defined as public static.The Math class method sqrt() in the package java.lang is static imported.A program that demonstrates this is given as follows:Example Live Demoimport static java.lang.Math.sqrt; public class Demo { public static void main(String[] arg) { double num = 36.0; System.out.println("The number is: " + num); System.out.println("The square root of the above number is: " + sqrt(num)); } }OutputThe number is: 36.0 The square root ... Read More