Found 34477 Articles for Programming

Why do Java array declarations use curly brackets?

Ankitha Reddy
Updated on 30-Jul-2019 22:30:20

492 Views

Curly brackets usually denote sets and ensembles while parenthesis usually in most Algol-based programming languages curly braces are used to declare arrays.

How to declare a class in Java?

mkotla
Updated on 30-Jul-2019 22:30:20

12K+ Views

Following is the syntax to declare a class. class className { //Body of the class } You can declare a class by writing the name of the next to the class keyword, followed by the flower braces. Within these, you need to define the body (contents) of the class i.e. fields and methods.To make the class accessible to all (classes) you need to make it public. public class MyClass { //contents of the class (fields and methods) }

How to convert a byte array to a hex string in Java?

Abhinaya
Updated on 30-Jul-2019 22:30:20

390 Views

The printHexBinary() method of the DatatypeConverter class accepts a byte array and returns a hex string.Exampleimport javax.xml.bind.DatatypeConverter; public class ByteToHexString { public static void main(String args[]) { String sam = "Hello how are you how do you do"; byte[] byteArray = sam.getBytes(); String hex = DatatypeConverter.printHexBinary(byteArray); System.out.println(hex); } }Output48656C6C6F20686F772061726520796F7520686F7720646F20796F7520646F

What are Java classes?

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

538 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

Advertisements