Sharon Christine has Published 433 Articles

What does the method sort(obj[] a) do in java?

Sharon Christine

Sharon Christine

Updated on 25-Feb-2020 09:28:44

72 Views

The sort(Object[]) method of the java.util.Arrays class sorts the specified array of Objects into ascending order according to the natural ordering of its elements.Exampleimport java.util.Arrays; public class ArrayDemo {    public static void main(String[] args) {       Object ob[] = {27, 11, 44};       for (Object ... Read More

How to use images with HTML5 canvas?

Sharon Christine

Sharon Christine

Updated on 25-Feb-2020 06:21:01

326 Views

The HTML5 tag is used to draw graphics, animations, etc. using scripting. It is a new tag introduced in HTML5. To use images with HTML5 canvas, use the drawImage() method. This method draws the given image onto the canvas.You can try to run the following code to learn how ... Read More

How to use the instanceof operator in Java?

Sharon Christine

Sharon Christine

Updated on 20-Feb-2020 10:07:53

161 Views

The instanceof operator is used only for object reference variables. The operator checks whether the object is of a particular type (class type or interface type).Examplepublic class Test {    public static void main(String args[]) {       String name = "James";       boolean result = name instanceof String;       System.out.println(result);    } }Outputtrue

How to use isAlive() method of Thread class in Java?

Sharon Christine

Sharon Christine

Updated on 20-Feb-2020 10:00:55

248 Views

The isAlive() method of the Thread class returns true if the thread is alive, which is anytime after the thread has been started but before it runs to completion.Exampleclass first implements Runnable {    public void run() {       try {          for(int i=0; i

How to calculate the size of folder using Java?

Sharon Christine

Sharon Christine

Updated on 20-Feb-2020 09:51:17

1K+ Views

You can get the size of a directory with the help of FileUtils.sizeofDirectory(File Name) method of FileUtils class.Exampleimport java.io.File; import org.apache.commons.io.FileUtils; public class Main {    public static void main(String[] args) {       long size = FileUtils.sizeOfDirectory(new File("C:/Windows"));       System.out.println("Size: " + size + " ... Read More

What is the difference between System.out.println() and System.out.print() in Java?

Sharon Christine

Sharon Christine

Updated on 20-Feb-2020 08:19:37

1K+ Views

The println() terminates the current line by writing the line separator string. The print() method just prints the given content.ExampleLive Demopublic class Sample {    public static void main(String args[]) {       System.out.println("Hello");       System.out.println("how are you");       System.out.print("Hello");       System.out.print("how are ... Read More

What is the difference between throw and throws keywords in Java?

Sharon Christine

Sharon Christine

Updated on 20-Feb-2020 06:39:20

295 Views

The throw keyword is used to raise an exception explicitly.Examplepublic class Test {    public static void main(String[] args) {       throw new NullPointerException();    } }Exception in thread "main" java.lang.NullPointerException at a6.dateAndTime.Test.main(Test.java:5)The throws keywords in Java used to postpone the handling of a checked exception.public class Test ... Read More

How to convert a Double array to a String array in java?

Sharon Christine

Sharon Christine

Updated on 19-Feb-2020 10:44:05

3K+ Views

You can convert a double array to a string using the toString() method. To convert a double array to a string array, convert each element of it to string and populate the String array with them.ExampleLive Demoimport java.util.Arrays; public class DoubleArrayToString {    public static void main(String args[]) { ... Read More

How to move an element of an array to a specific position (swap)?

Sharon Christine

Sharon Christine

Updated on 19-Feb-2020 10:17:30

2K+ Views

To move an element from one position to other (swap) you need to –Create a temp variable and assign the value of the original position to it.Now, assign the value in the new position to original position.Finally, assign the value in the temp to the new position.ExampleLive Demoimport java.util.Arrays; public ... Read More

How to declare an Array Variables in Java?

Sharon Christine

Sharon Christine

Updated on 19-Feb-2020 10:04:43

295 Views

You can declare an array just like a variable −int myArray[];You can create an array just like an object using the new keyword −myArray = new int[5];You can initialize the array by assigning values to all the elements one by one using the index −myArray [0] = 101; myArray [1] ... Read More

Advertisements