Java Articles

Page 43 of 450

Get file extension name in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 735 Views

The file extension is the suffix that is attached to the computer file and it denotes the format of the file. A program that demonstrates getting the file extension name is given as follows −Exampleimport java.io.File; public class Demo {    private static String fileExtension(File file) {       String name = file.getName();       if(name.lastIndexOf(".") != -1 && name.lastIndexOf(".") != 0)          return name.substring(name.lastIndexOf(".") + 1);       else          return "";    }    public static void main(String[] args) {       File file = new File("demo1.txt");   ...

Read More

File Path with double slash in Java

Samual Sam
Samual Sam
Updated on 11-Mar-2026 1K+ Views

The double slash in the file path is required as to create the ’\’ character , another ‘\’ needs to be added to escape it. A program that demonstrates this is given as follows −Exampleimport java.io.File; public class Demo {    public static void main(String[] args) {       File file = new File("C:\jdk11.0.2\demo1.txt");       System.out.println(file);    } }The output of the above program is as follows −OutputC:\jdk11.0.2\demo1.txtNow let us understand the above program.The file path of the file is provided with double slash and then it is printed. A code snippet that demonstrates this is given ...

Read More

Java Program to strip a filename of its extension after the last dot

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 4K+ Views

The method removeExtension() is used to strip a filename of its extension after the last dot. This method requires a single parameter i.e. the file name and it returns the file name without its extension.A program that demonstrates this is given as follows −Exampleimport java.io.File; public class Demo {    public static String removeExtension(String fname) {       int pos = fname.lastIndexOf('.');       if(pos > -1)          return fname.substring(0, pos);       else          return fname;    }    public static void main(String[] args) {       System.out.println(removeExtension("c:\JavaProgram\demo1.txt"));   ...

Read More

Delete file or directory on termination in Java

Samual Sam
Samual Sam
Updated on 11-Mar-2026 329 Views

A file or directory can be deleted on termination of the program i.e. after the virtual machine terminates using the method java.io.File.deleteOnExit(). This method requires no parameters and it does not return a value.A program that demonstrates this is given as follows −Exampleimport java.io.File; public class Demo {    public static void main(String[] args) {       try {          File file = new File("demo1.txt");          file.createNewFile();          System.out.println("File: " + file);          file.deleteOnExit();       } catch(Exception e) {          e.printStackTrace();   ...

Read More

Get the Current Working Directory in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 8K+ Views

The method java.lang.System.getProperty() is used to obtain the system property. This system property is specified by the key which is the parameter for the method. To obtain the current working directory, the key used is user.dir.A program that demonstrates this is given as follows −Examplepublic class Demo {    public static void main(String[] argv) throws Exception {       String currentDirectory = System.getProperty("user.dir");       System.out.println("The current working directory is " + currentDirectory);    } }The output of the above program is as follows −OutputThe current working directory is c:\JavaProgramNow let us understand the above program.The current working ...

Read More

AbstractSequentialList in Java

Samual Sam
Samual Sam
Updated on 11-Mar-2026 191 Views

The Java Collection Framework contains the AbstractSequentialList class. This class is used to create and implement an unmodifiable list. Also this class implements the Collection interface and the AbstractCollection class.A program that demonstrates this is given as follows −Exampleimport java.util.*; public class Demo {    public static void main(String[] args) {       AbstractSequentialList list = new LinkedList();       list.add("John");       list.add("Martha");       list.add("Sally");       list.add("Susan");       list.add("Harry");       System.out.println("The elements are: " + list);    } }The output of the above program is as follows −OutputThe ...

Read More

Custom ArrayList in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 1K+ Views

A custom ArrayList can have multiple types of data and its attributes in general are based on the user requirements.A program that demonstrates a custom ArrayList is given as follows −Exampleimport java.util.ArrayList; public class CustomArrayList {    int n = 5;    class Employee {       int eno;       String name;       Employee(int eno, String name) {          this.eno = eno;          this.name = name;       }    }    public static void main(String args[]) {       int eno[] = {101, 102, 103, 104, ...

Read More

ArrayBlockingQueue Class in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 223 Views

A bounded blocking queue that is backed by an array is known as a ArrayBlockingQueue Class in Java. The size of the queue is fixed in the class and it uses FIFO for ordering elements. The ArrayBlockingQueue Class is a member of the Java Collections Framework.A program that demonstrates this is given as follows −Exampleimport java.util.concurrent.ArrayBlockingQueue; public class Demo {    public static void main(String[] args) {       int n = 10;       ArrayBlockingQueue abQueue = new ArrayBlockingQueue(n);       abQueue.add(7);       abQueue.add(2);       abQueue.add(6);       abQueue.add(3);     ...

Read More

LinkedBlockingQueue Class in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 203 Views

The LinkedBlockingQueue Class in Java has a blocking queue that is optionally bounded and based on linked nodes. This means that if the capacity is provided then the LinkedBlockingQueue is bound, otherwise it is not bound. Also, FIFO for ordering elements.A program that demonstrates this is given as follows −Exampleimport java.util.concurrent.LinkedBlockingQueue; public class Demo {    public static void main(String[] args) {       LinkedBlockingQueue lbQueue = new LinkedBlockingQueue();       lbQueue.add("Amy");       lbQueue.add("John");       lbQueue.add("May");       lbQueue.add("Harry");       lbQueue.add("Anne");       System.out.println("The elements in LinkedBlockingQueue are: " + ...

Read More

LinkedTransferQueue in Java

Samual Sam
Samual Sam
Updated on 11-Mar-2026 109 Views

The LinkedTransferQueue Class in Java has a transfer queue that has unbounded functionality and is based on linked nodes. It uses FIFO for ordering elements. This class implements the Collection interface as well as the AbstractQueue class. It is a part of the Java Collection Framework.A program that demonstrates this is given as follows −Exampleimport java.util.concurrent.LinkedTransferQueue; public class Demo {    public static void main(String[] args) throws InterruptedException {       LinkedTransferQueue ltQueue = new LinkedTransferQueue();       ltQueue.add("Amy");       ltQueue.add("John");       ltQueue.add("May");       ltQueue.add("Harry");       ltQueue.add("Anne");       ...

Read More
Showing 421–430 of 4,498 articles
« Prev 1 41 42 43 44 45 450 Next »
Advertisements