Java Articles

Page 6 of 450

Why do we need generics in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 5K+ Views

Reference typesAs we know a class is a blue print in which we define the required behaviors and properties and, an interface is similar to class but it is a Specification (containing abstract methods).These are also considered as datatypes in Java, unlike other primitive datatypes a literal of these kind of types points/refers to the location of the object. They are also known as reference types.GenericsGenerics is a concept in Java where you can enable a class, interface and, method, accept all (reference) types as parameters. In other words it is the concept which enables the users to choose the ...

Read More

Difference Between Daemon Threads and User Threads In Java

Nitin Sharma
Nitin Sharma
Updated on 11-Mar-2026 2K+ Views

As we know java is a language that supports multi threading and on the basis of nature threads in java are classified into two types Daemon thread and User thread.The following are the important differences between Daemon Threads and User Threads.Sr. No.KeyDaemon ThreadsUser Threads1NatureDaemon thread is low in priority i.e JVM does not care much about these types of threads.User threads are recognized as high priority thread i.e. JVM will wait for any active user thread to get completed.2CPU availabilityIt is not guaranteed that Daemon thread always gets CPU usage whenever it requires due to its low priority.User thread always ...

Read More

Matching Nonprintable Characters using Java regex

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 1K+ Views

There are 7 common non printable characters used in general and each character has its own hexadecimal representation.NamecharactersHexa-decimal representationbell\a0x07Escape\e0x1BForm feed\f0x0CLine feed0x0ACarriage return\r0X0DHorizontal tab\t0X09Vertical tab\v0X0BExample 1import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample1 {    public static void main(String[] args) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter input text: ");       String input = sc.nextLine();       String regex = "\x09";       //Creating a pattern object       Pattern pattern = Pattern.compile(regex);       //Matching the compiled pattern in the String       Matcher matcher = ...

Read More

Incremental Java infinite loop

Abhinanda Shri
Abhinanda Shri
Updated on 11-Mar-2026 253 Views

ExampleFollowing is the required program −public class Tester {    public static void main(String args[]) {       int i = 0;       do {          i++;          System.out.println(i);       }while (true);    } }The output will keep printing numbers in sequential order.

Read More

Incremental Java infinite loop

Abhinanda Shri
Abhinanda Shri
Updated on 11-Mar-2026 253 Views

ExampleFollowing is the required program −public class Tester {    public static void main(String args[]) {       int i = 0;       do {          i++;          System.out.println(i);       }while (true);    } }The output will keep printing numbers in sequential order.

Read More

How is down-casting possible in Java?

Syed Javed
Syed Javed
Updated on 11-Mar-2026 236 Views

Yes, a variable can be downcast to its lower range substitute by casting. It may lead to data loss although. See the example below −Examplepublic class Tester {      public static void main(String[] args) {       int a = 300;         byte b = (byte)a;         System.out.println(b);    }   }OutputIt will print output as −44

Read More

How is down-casting possible in Java?

Syed Javed
Syed Javed
Updated on 11-Mar-2026 236 Views

Yes, a variable can be downcast to its lower range substitute by casting. It may lead to data loss although. See the example below −Examplepublic class Tester {      public static void main(String[] args) {       int a = 300;         byte b = (byte)a;         System.out.println(b);    }   }OutputIt will print output as −44

Read More

How to import java.lang.String class in Java?

Fendadis John
Fendadis John
Updated on 11-Mar-2026 18K+ Views

To import any package in the current class you need to use the import keyword asimport packagename;Exampleimport java.lang.String; public class Sample {    public static void main(String args[]) {       String s = new String("Hello");       System.out.println(s);    } }OutputHello

Read More

String Concatenation by concat() method.

Alankritha Ammu
Alankritha Ammu
Updated on 11-Mar-2026 280 Views

You can concatenate two strings using the concat() method of the String class. This class concatenates the specified string to the end of this string.Examplepublic class Test {    public static void main(String args[]){       String str1 = "Krishna";       String str2 = "Kasyap";       System.out.println(str1.concat(str2));    } }OutputkrishnaKasyap

Read More

Local variables in Java

Syed Javed
Syed Javed
Updated on 11-Mar-2026 2K+ Views

Local variables are declared in methods, constructors, or blocks.Local variables are created when the method, constructor or block is entered and the variable will be destroyed once it exits the method, constructor, or block.Access modifiers cannot be used for local variables.Local variables are visible only within the declared method, constructor, or block.Local variables are implemented at stack level internally.There is no default value for local variables, so local variables should be declared and an initial value should be assigned before the first use.ExampleHere, age is a local variable. This is defined inside pupAge()method and its scope is limited to only ...

Read More
Showing 51–60 of 4,498 articles
« Prev 1 4 5 6 7 8 450 Next »
Advertisements