- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 34470 Articles for Programming
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
6K+ Views
In the process of managing files and directories in Python, there are often situations where you need to obtain a directory listing sorted by creation date. The task of sorting files and directories by their creation timestamps can be beneficial for various purposes, such as analyzing the most recently added files or organizing data based on chronological order. Python has several methods and techniques to achieve this goal effectively and efficiently. By making use of the "os" module, the "pathlib" module, or third−party libraries, you can effortlessly obtain a sorted directory listing based on creation date. In this exhaustive article, ... Read More
![Sharon Christine](https://www.tutorialspoint.com/assets/profiles/13517/profile/60_82215-1512649681.jpg)
245 Views
You can declare an array just like a variable −int myArray[];You can create an array just like an object using the new keyword −myArray = new int[5];You can initialize the array by assigning values to all the elements one by one using the index −myArray [0] = 101; myArray [1] = 102;You can access the array element using the index values −System.out.println("The first element of the array is: " + myArray [0]); System.out.println("The first element of the array is: " + myArray [1]); Alternatively, you can create and initialize an array using the flower braces ({ }): Int [] myArray = {10, 20, 30, 40, 50}
![Sarika Singh](https://www.tutorialspoint.com/assets/profiles/502778/profile/60_2211036-1660719373.jpg)
38K+ Views
A portable method of interacting with the operating system is offered through the OS Python Module. The module, which is a part of the default Python library, contains tools for locating and modifying the working directory. The following contents are described in this article. How to obtain the current working directory: os.getcwd() Changing the current working directory: os.chdir() The __file__ function returns the path to the current script file (.py). Getting the current working directory- os.getcwd() The function os.getcwd() returns as a string str the absolute path to Python's current working directory. "Get current working directory" (getcwd) refers ... Read More
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
453 Views
When working with files and directories in Python, it's a crucial point to distinguish between regular files and directories. Knowing the type of each file is most essential for implementing different file handling operations, such as reading, writing, or navigating through directory structures. Python makes available several methods and techniques to determine if a given path points to a directory or a regular file. By utilizing the "os" module, the "pathlib" module, or other specialized functions, you can easily differentiate between these two types and perform the necessary operations accordingly. In this exhaustive article, we will explore different methods to ... Read More
![varma](https://www.tutorialspoint.com/assets/profiles/13568/profile/60_26300-1512638592.jpg)
2K+ Views
Default constructors in Java:A constructor initializes an object when it is created. It has the same name as its class and is syntactically similar to a method. However, constructors have no explicit return type. There are two types of constructors namely −parameterized constructors − Constructors with arguments.no-arg constructors − Constructors without arguments.Example Live Demopublic class Sample{ int num; Sample(){ num = 100; } Sample(int num){ this.num = num; } public static void main(String args[]){ System.out.println(new Sample().num); System.out.println(new Sample(1000).num); } }Output100 1000Default ConstructorIt ... Read More
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
2K+ Views
When it comes to file operations in Python, adhering to best practices is crucial to ensure the security and integrity of your data. Mishandling files can lead to data corruption, resource leaks, and even security vulnerabilities. This article aims to delve into the best practices for safely opening and closing files in Python, accompanied by five illustrative code examples with stepwise explanations to enhance your understanding. Utilizing the 'with' Statement Python offers a convenient approach to opening and closing files using the 'with' statement. The 'with' statement guarantees automatic closure of the file once the code block inside ... Read More
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
16K+ Views
When it comes to file management within a directory in Python, there can be scenarios where you find yourself needing to entirely empty the folder, erasing all the files and sometimes subdirectories it contains. In this regard, Python makes provision for several efficient and secure methods to accomplish this task. In this article, we'll explore a few diverse methods to achieve the above-mentioned objective of deleting all files in a directory. We take the help of code examples accompanied by step-by-step explanations to ensure a smooth execution of the aforementioned task. Utilizing os.listdir() and os.remove() Let's start with ... Read More
![Sai Subramanyam](https://www.tutorialspoint.com/assets/profiles/13512/profile/60_68191-1512710774.jpg)
13K+ Views
If super class and sub class have same methods including name, return type and parameters, and if you try to call it using the object of the sub class Then the method in the sub class is invoked. Constructor looks like method but it is not. It does not have a return type and its name is same as the class name. But, a constructor cannot be overridden. If you try to write a super class’s constructor in the sub class compiler treats it as a method and expects a return type and generates a compile time error. Example ... Read More
![seetha](https://www.tutorialspoint.com/assets/profiles/13549/profile/60_42938-1512640859.jpg)
410 Views
The Java.lang.Class class instance represent classes and interfaces in a running Java application. It has no public constructor. Example Following is the example demonstrates the usage of the class Class. The java.lang.Class.getCanonicalName() method returns the canonical name of the underlying class as defined by the Java Language Specification. It returns null if the class does not have a canonical name. Live Demo import java.lang.*; public class ClassDemo { public static void main(String[] args) { ClassDemo c = new ClassDemo(); Class cls = ... Read More
![Lakshmi Srinivas](https://www.tutorialspoint.com/assets/profiles/13528/profile/60_91717-1512651120.jpg)
2K+ Views
Except public, protected and, private constructor does not allow any other modifier. When you use a final keyword with a method or constructor it cannot be overridden. But, a constructor in Java cannot be overridden therefore, there is no need of using the final keyword with the constructor. Since you cannot override a constructor you cannot provide body to it if it is made abstract. Therefore, you cannot use abstract keyword with the constructor. If you want to invoke a member of a class before instantiating the class you need to use static before it. But, contractors are called ... Read More