Programming Articles - Page 3313 of 3366

What is the difference between a Java method and a native method?

Swarali Sree
Updated on 30-Jul-2019 22:30:20

618 Views

A native method is the one whose method implementation is done in other languages like c++ and Java. These programs are linked to Java using JNI or JNA interfaces. The difference between normal method and native method is That the native method declaration contains native keyword and, the implementation of the method will be other programming language. Example Tester.java public class Tester { public native int getValue(int i); public static void main(String[] args) { System.loadLibrary("Tester"); System.out.println(new Tester().getValue(2)); ... Read More

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

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

2K+ 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?

Niharikaa Aitam
Updated on 27-May-2025 18:10:57

4K+ Views

In Python, we can extract a specific part of a file path of the directory using built-in modules such os.path and pathlib. Extracting a part of the file path is commonly needed when working with file systems, data processing, or scripts that handle files dynamically. Using os.path Module The os.path module in Python provides functions to manipulate files and directory paths. We can use this module to extract directory names, file names, and traverse up directory levels. Example Following is an example, which shows how to use the os.path module to extract a directory path from a full file path ... Read More

When to use vararg methods in Java?

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

216 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 27-May-2025 18:39:23

11K+ Views

Iterating over files in a given directory helps to perform tasks such as finding files that match certain criteria 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 In this article, we are going to see all the above methods that are used to iterate over files in a given ... Read More

What are vararg methods in Java?

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

269 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

1K+ 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?

Niharikaa Aitam
Updated on 27-May-2025 17:48:20

9K+ Views

The given task is to list the directory tree structure, i.e., we need to print the hierarchy of folders and files starting from a specified root directory. This is similar to how the tree command works in Linux or Windows by showing nested folders and files in a structured and indented format. In this article, we will see all the possible methods in Python to list the directory tree structure. Using os.walk() Method The os.walk() method in Python is used to generate the file names and folder names in a directory tree by parsing through the tree in either a ... Read More

What are annotations in Java?

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

864 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?

Niharikaa Aitam
Updated on 15-May-2025 15:56:48

4K+ Views

In Python, when we are working with directory structures, it is necessary to check whether a given directory contains any other directories within it or not. This process of checking is useful when performing batch operations, cleaning up folders, or traversing file systems. Python provides several built-in ways to perform this check effectively. In this article, we will go through different methods using both os and pathlib modules to determine if a directory contains any subdirectories. Using os.listdir() and os.path.isdir() The os.listdir() method is the straightforward method to detect subdirectories to list directory contents, and when it is combined with ... Read More

Advertisements