Found 34494 Articles for Programming

What are Java classes?

Giri Raju
Updated on 30-Jul-2019 22:30:20

537 Views

A class in Java is a user-defined datatype, a blueprint, a classification, that describes the behavior/state that the object of its type support. Example public class Dog { String breed; int age; String color; void barking() { } void hungry() { } void sleeping() { } } A class can contain any of the following variable types. Local variables − Variables defined inside methods, constructors or blocks are called local ... Read More

How to convert BLOB to Byte Array in java?

Ramu Prasad
Updated on 30-Jul-2019 22:30:20

6K+ Views

You can contents of a blob into a byte array using the getBytes() method.Exampleimport java.awt.Image; import java.awt.image.BufferedImage; import java.sql.Blob; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.Arrays; public class BlobToByteArray { public static void main(String[] args) throws Exception { Image image = new BufferedImage(300, 400, BufferedImage.TYPE_INT_RGB); String JDBC_DRIVER = "com.mysql.jdbc.Driver"; String DB_URL = "jdbc:mysql://localhost/mydb"; String USER = "root"; String PASS = "password"; ... Read More

How to Map multi-dimensional arrays to a single array in java?

V Jyothi
Updated on 19-Feb-2020 12:15:46

2K+ Views

A two-dimensional array is nothing but an array of one dimensional arrays. Therefore to map a two dimensional array into one dimensional arrays.Create arrays equal to the length of the 2d array and, using for loop store the contents of the 2d array row by row in the arrays created above.Examplepublic class Mapping_2DTo1D {    public static void main(String args[]) {       int [][] array2D = {{7, 9, 8, 5}, {4, 5, 1, 8}, {9, 3, 2, 7}, {8, 1, 0, 9}};       int [] myArray1 = new int[array2D[0].length];       int [] myArray2 = ... Read More

How to scan through a directory recursively in Python?

Alekhya Nagulavancha
Updated on 24-Feb-2023 12:08:19

10K+ Views

A directory is simply defined as a collection of subdirectories and single files; or either one of them. A directory hierarchy is constructed by organizing all the files and subdirectories within a main directory, also known as “root” directory. These subdirectories are separated using a “/” operator in a directory hierarchy. Since the directory is organized in the form of a hierarchy/tree, scanning it can be likened to traversing a tree. And to do that, there are various ways. Using os.walk() method Using glob.glob() method Using os.listdir() method The directories are handled by the operating system; therefore, whenever ... Read More

How to get the home directory in Python?

Rajendra Dharmkar
Updated on 11-Sep-2023 17:00:43

3K+ Views

As a Python coder, you may often come across scenarios where you need to access the user's home directory to perform specific operations like reading or writing user−specific files, configuration files, or data. However, the location of the home directory can change across different operating systems, making it a challenge to access it in a platform−independent manner. In this extensive article, we will explore various methods to obtain the home directory in Python effectively and efficiently. We will proceed to provide step−by−step explanations and code examples to understand the process. Whether you're developing a cross−platform application or simply need to ... Read More

How to find if a directory exists in Python?

Alekhya Nagulavancha
Updated on 24-Feb-2023 12:13:45

6K+ Views

Directory creation is a common task for computer users. You might need to create a directory to store some files, or to place some new files inside an existing directory. In this article, you will learn how to find if a directory already exists in Python or not. A directory is a file system structure used by operating systems and software applications to organize files. It can also refer to a list of files and folders, like the current folder in Windows Explorer. Sometimes there arises a need to check whether a certain directory exists in a system or not; ... Read More

How to share common data among multiple Python files?

Rajendra Dharmkar
Updated on 03-Aug-2023 13:21:27

1K+ Views

In the domain of Python programming, organization and modularity are pivotal in crafting efficient and maintainable code. As your Python projects grow in complexity, the necessity to disseminate common data across multiple files becomes paramount. Gratefully, Python furnishes several techniques to accomplish this seamlessly. Within this article, we shall embark on a journey of a few distinct methods to share common data among multiple Python files. Each approach boasts its unique strengths and adaptability, endowing you with the ability to construct scalable and robust Python projects. You will be guided through each method with comprehensive explanations in a human-friendly style. ... Read More

How to find difference between 2 files in Python?

Rajendra Dharmkar
Updated on 03-Aug-2023 11:42:42

8K+ Views

When you venture into the realm of file processing, the need to discern disparities and differences between two files arises frequently. Python equips us with an array of potent tools to accomplish this task with ease and precision. In this article, we shall navigate a few distinct methodologies to reveal the differences between two files in Python. Each approach is equipped with unique functionalities and adaptability, granting you the ability to seamlessly compare files of varying sizes and formats. As a Python coding enthusiast, you are walked through each method, providing stepwise explanations in a style that is human-friendly. By ... Read More

How (where) are the elements of an array stored in memory?

Priya Pallavi
Updated on 30-Jul-2019 22:30:20

1K+ Views

In Java, arrays are objects, therefore just like other objects arrays are stored in heap area. An array store primitive data types or reference (to derived data) types Just like objects the variable of the array holds the reference to the array.

Can i refer an element of one array from another array in java?

Nikitha N
Updated on 16-Jun-2020 10:04:41

392 Views

Yes, you can −int [] myArray1 = {23, 45, 78, 90, 10}; int [] myArray2 = {23, 45, myArray1[2], 90, 10};But, once you do so the second array stores the reference of the value, not the reference of the whole array. For this reason, any updating in the array will not affect the referred value −ExampleLive Demoimport java.util.Arrays; public class RefferencingAnotherArray {    public static void main(String args[]) {       int [] myArray1 = {23, 45, 78, 90, 10};       int [] myArray2 = {23, 45, myArray1[2], 90, 10};       System.out.println("Contents of the ... Read More

Advertisements