Found 33676 Articles for Programming

How to zip a folder recursively using Python?

Niharikaa Aitam
Updated on 27-May-2025 18:28:03

7K+ Views

Zipping a folder recursively means compressing a folder along with all its subfolders and files. In this article, we will explore all the possible ways to zip a folder recursively using Python. Using zipfile and os.walk() In Python, we have the methods zipfile() and os.walk() to zip all the folders recursively. This is a manual approach of zipping the available subfolders and files into one. Following is an example that shows how to zip a folder recursively using Python - import zipfile import os def zip_folder_manual(folder_path, zip_path): with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf: ... Read More

What is binding in Java?

Lakshmi Srinivas
Updated on 30-Jul-2019 22:30:20

6K+ Views

Association of method call with the method body is known as binding in Java. There are two kinds of binding. Static binding In static binding the method call is bonded with the method body at compile time. This is also known as early binding. This is done using static, private and, final methods. Example class Super{ public static void sample(){ System.out.println("This is the method of super class"); } } Public class Sub extends Super{ Public static void sample(){ ... Read More

How to install a Python package into a different directory using pip?

SaiKrishna Tavva
Updated on 01-Sep-2025 15:00:24

20K+ Views

In Python, pip is a standard tool which is used to install third-party packages in our system. By default, pip installs packages into the site-packages directory of the current Python environment but in some cases, such as restricted environments or creating portable apps, we may need to install packages into a different directory. Then we can use the pip's --target option. Syntax Following is the syntax of using the pip command while installing a python package in a different directory - pip install --target The above command tells pip to install the specified package and all its ... Read More

How many ways can get the instance of a Class class in Java?

Monica Mona
Updated on 18-Feb-2020 09:59:52

585 Views

You can create an object of the class named Class in two ways −Using new keyword as −Class obj = new Class();Using the forName() method of the class named Class.Class obj = Class.forName("DemoTest");

How to access the private methods of a class from outside of the class in Java?

karthikeya Boyini
Updated on 18-Feb-2020 10:00:48

7K+ Views

You can access the private methods of a class using java reflection package.Step1 − Instantiate the Method class of the java.lang.reflect package by passing the method name of the method which is declared private.Step2 − Set the method accessible by passing value true to the setAccessible() method.Step3 − Finally, invoke the method using the invoke() method.Exampleimport java.lang.reflect.Method; public class DemoTest {    private void sampleMethod() {       System.out.println("hello");    } } public class SampleTest {    public static void main(String args[]) throws Exception {       Class c = Class.forName("DemoTest");       Object obj = c.newInstance(); ... Read More

What is a method in Java that ends in a semicolon and has no method body?

Sharon Christine
Updated on 30-Jul-2019 22:30:20

804 Views

An abstract method is the one which has no definition and declared abstract. In short, an abstract method contains only method signature without body. To use this method, you need to inherit this method by extending the class and provide the method definition. Example public abstract class Employee{ private String name; private String address; private int number; public abstract double computePay(); }

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

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

598 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

208 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

Advertisements