Found 34494 Articles for Programming

What are native methods in Java and where are they used?

Samual Sam
Updated on 30-Jul-2019 22:30:20

1K+ Views

A native method in Java is a method whose implementation is written in other languages such as c and c++. The ‘native’ keyword is used before a method to indicate that it is implemented in other language.

How to extract a part of the file path (a directory) in Python?

Rajendra Dharmkar
Updated on 22-Aug-2023 11:34:40

2K+ Views

When using file operations and directory structures, working with file paths is a typical task in Python programming. You may occasionally need to strip off particular parts of a file path, such a directory name, in order to analyze or alter it independently. Python offers a number of methods to carry out this work quickly and effectively. This extensive article will examine various techniques for extracting a directory in Python from a file path. We will walk you through the procedure with step-by-step explanations and code samples. You may divide a file path into several parts, get the parent directory, ... Read More

When to use vararg methods in Java?

Sai Subramanyam
Updated on 30-Jul-2019 22:30:20

125 Views

Whenever, you want to pass different number of arguments each time you call a method you should use vararg methods. This example creates sumvarargs() method which takes variable no of int numbers as an argument and returns the sum of these arguments as an output. Example Live Demo public class Main { static int sumvarargs(int... intArrays) { int sum, i; sum = 0; for(i = 0; i< intArrays.length; i++) { ... Read More

How can I iterate over files in a given directory in Python?

Alekhya Nagulavancha
Updated on 19-Apr-2023 14:21:12

9K+ Views

Iterating over files in a given directory can be helpful for doing things like finding files that match a certain criterion, or counting the number of files in a directory. Python provides the following five ways to walk through all the existing files in a directory os.listdir() method os.walk() method os.scandir() method Using pathlib module glob.iglob() method Let us look at these methods in detail. Using os.listdir() Method The os.listdir() method is used to list all the files present in a directory. It accepts the path of the directory as an argument and all the entries, apart from ... Read More

What are vararg methods in Java?

Lakshmi Srinivas
Updated on 18-Feb-2020 10:02:14

163 Views

In Java methods, parameters accept arguments with three dots. These are known as variable arguments.sample(int args …){}If they are used you can pass a different number of arguments each time you call these methods.Examplepublic class Sample {    void demoMethod(String... args) {       for (String arg: args) {          System.out.println(arg);       }    }    public static void main(String args[] ) {       new Sample().demoMethod("ram", "rahim", "robert");       new Sample().demoMethod("krishna", "kasyap")    } }Outputram rahim robert krishna kasyap

What are variadic functions in Java?

Monica Mona
Updated on 16-Jun-2020 06:19:30

777 Views

Methods which uses variable arguments (varargs, arguments with three dots) are known as variadic functions.ExampleLive Demopublic class Sample {     void demoMethod(String... args) {       for (String arg: args) {          System.out.println(arg);       }     }    public static void main(String args[] ){       new Sample().demoMethod("ram", "rahim", "robert");       new Sample().demoMethod("krishna", "kasyap");    } }Outputram rahim robert krishna kasyap

How to list directory tree structure in python?

Rajendra Dharmkar
Updated on 11-Sep-2023 17:14:58

5K+ Views

While working with file systems and directories in Python, understanding the directories’ structure and their contents is essential for efficient file management and organization. Python makes available various methods and libraries that allow you to list the directory tree structure, including all subdirectories and files, in a comprehensive and exhaustive manner. Whether you're organizing files, analyzing directory structures, or performing data processing tasks, knowing how to list the directory tree structure in Python will significantly enhance your file handling capabilities. In this extensive article, we will explore different methods to list the directory tree structure in Python. We will also ... Read More

What are annotations in Java?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:20

519 Views

Annotations are a tag (metadata) which provides info about a program. Annotations in Java Start with the symbol ‘@’. They are used by the compiler to detect errors. Software tools to generate code. They are used to show attributes of an element: e.g. @Deprecated, @Override. Annotation are used to describe the purpose of an element of the framework, e.g. @Entity, @TestCase, @WebService Annotations describe the behaviour of an element: @Statefull, @Transaction. Example Live Demo class Sample{ public void display(){ System.out.println(" "); } } public ... Read More

How to check if a given directory contains any other directory in Python?

Rajendra Dharmkar
Updated on 11-Sep-2023 16:41:23

3K+ Views

When dealing with and handling file systems and directory structures in Python, it's important to find if a given directory contains any other directories. This data becomes invaluable in various situations, such as organizing files, managing hierarchical data, or implementing conditional logic based on the presence of subdirectories. Python has provision for several methods and techniques to efficiently check for the existence of directories within a given directory. In this informative article, we will explore different methods to check if a given directory contains any other directories in Python. We will also provide step−by−step explanations and code examples to help ... Read More

How do you get a directory listing sorted by their name in Python?

Rajendra Dharmkar
Updated on 11-Sep-2023 16:26:27

9K+ Views

When working with directories in Python, it's often necessary to obtain a list of files and subdirectories within a given directory. Moreover, sorting this directory listing by their names can be beneficial for better organization and readability. Python provides several methods and techniques to achieve this goal efficiently. Sorting the directory listing alphabetically can help you quickly locate specific files or directories and facilitate various file management tasks. In this comprehensive article, we will explore different methods to get a directory listing sorted by name in Python. We will provide step−by−step explanations and code examples to guide you through the ... Read More

Advertisements