Found 33676 Articles for Programming

Does constructor return any value in Java?

mkotla
Updated on 23-Oct-2024 17:34:48

6K+ Views

No, the constructor does not return any value. While declaring a constructor you will not have anything like a return type. In general, the Constructor is implicitly called at the time of instantiation. And it is not a method, its sole purpose is to initialize the instance variables.Read more about constructors: Java Constructors Example public class Sample{ public Sample(){ System.out.println("This is a constructor"); } public static void main(String args[]){ ... Read More

How to find the mime type of a file in Python?

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

8K+ Views

In some scenarios, it is important to determine the MIME type of a file to verify its content type, especially when working with file uploads or handling media files. Python provides modules such as mimetypes and magic to determine the MIME type of a file. In this article, we’ll explore different methods to find a file's MIME type using Python. Using mimetypes.guess_type() The mimetypes module in Python provides the guess_type() function, which is used to guess the MIME type and to encode of a file based on its filename or URL. Example In this example, we are using the mimetypes.guess_type() ... Read More

Can you use both this() and super() in a constructor in Java?

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

2K+ Views

No, you cannot have both this() and super() in a single constructor.

What is constructor chaining in Java?

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

430 Views

Constructors are similar to methods but, They do not have any return type. The name of the constructor is same as the name of the class. Every class has a constructor. If we do not explicitly write a constructor for a class, the Java compiler builds a default constructor for that class. Each time a new object is created, at least one constructor will be invoked. A class can have more than one constructor. this() and super() are used to call constructors explicitly. Where, using this() you can call the current class’s constructor and using super() you can ... Read More

How to extract file extension using Python?

Sarika Singh
Updated on 07-May-2025 14:01:01

6K+ Views

In a few scenarios, we need to extract the extension of a file to perform specific operations based on its type, such as validating image formats or filtering document files. Python provides different ways to achieve this using the os and pathlib modules. In this article, we'll explore how to get a file’s extension with different approaches.  Using os.path.splitext() The OS file path manipulation is made simple with the help of the Python os.path module. It provides methods to perform operations to receive data from file paths, opening, saving, and updating. The os.path.splitext() method of the os module in Python ... Read More

What is default, defender or extension method of Java 8?

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

157 Views

Java 8 introduces a new concept of default method implementation in interfaces. This capability is added for backward compatibility so that old interfaces can be used to leverage the lambda expression capability of Java 8. For example, ‘List’ or ‘Collection’ interfaces do not have ‘foreach’ method declaration. Thus, adding such method will simply break the collection framework implementations. Java 8 introduces default method so that List/Collection interface can have a default implementation of foreach method, and the class implementing these interfaces need not implement the same. Syntax public interface vehicle { default void print() { ... Read More

How to change file extension in Python?

Niharikaa Aitam
Updated on 15-May-2025 16:03:31

16K+ Views

In few scenarios, we need to change the extension of a file programmatically such as renaming a .txt file to .md or converting .csv to .json. Python provides different ways to do this using the os and pathlib modules. In this article, we’ll explore how to change a file’s extension using both approaches. Using os.path.splitext() The os.path.splitext() method of the os module in Python is used to split the file name into the name and extension. We can use this method to strip off the old extension and add the new extension. Example In this example, we are using the os.path.splitext() ... Read More

What is the difference between Component class and Container class in Java?

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

4K+ Views

The class Component is the abstract base class for the non-menu user-interface controls of AWT. A component represents an object with graphical representation. The class Container is the superclass for the containers of AWT. The container object can contain other AWT components.

What are Java methods equivalent to C# virtual functions?

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

535 Views

All instance methods in Java are virtual except, static methods and private methods.

How to get specific nodes in xml file in Python?

SaiKrishna Tavva
Updated on 01-Sep-2025 14:55:03

10K+ Views

XML is abbrivated as Extensible Markup Language which is used format to represent a structured data. It's is useful when we are exchanging information between two systems. In Python, the xml.etree.ElementTree module helps us to read and work with XML data. In this article, we will explore how to extract specific parts of an XML file using this library. Introduction to XML and ElementTree When we are working with XML files in Python, the xml.etree.ElementTree module is used for parsing and navigating XML structures. It reads an XML document and builds a tree of elements from it by allowing us ... Read More

Advertisements