Found 34494 Articles for Programming

How to replace Digits into String using Java?

Malhar Lathkar
Updated on 20-Jun-2020 13:19:39

1K+ Views

For this purpose, we create an object of HashMap class which is defined in java.util packageMap map = new HashMap();This hashmap object associates each digit with its corresponding word representationmap.put("0", "zero");Initialize an empty string object.String newstr="";Next, run a for loop over the length of given string and extract each character by substring() method of String class.Check if the character exists as a key in map object by containsKey() method. If it does, using it as key, obtain its value component in map and appenf\d to the new string. If not append the character itself to the new string. The complete code ... Read More

How do I write variable names in Java?

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

4K+ Views

While choosing an identifier to declare a variable in Java you need to keep the following points in mind. The name of the variable should begin with either alphabet or, an underscore (_) or, a dollar ($) sign. The identifiers used for variables must not be keywords. No spaces or special characters are allowed in the variable names of Java. Variable names may contain 0 to 9 numbers (if not at the beginning). Variable names are case sensitive i.e. MY_NUM is different from my_num. If you use two words in a identifier then the you should follow camel case ... Read More

How to remove a file using Python?

Rajendra Dharmkar
Updated on 24-Jul-2023 20:42:18

257 Views

There will be times when we need to remove files programmatically in Python. Removing files, in this context, is the act of deleting or erasing files from a computer's file system using Python programming language. You must know that when you remove a file, it is permanently deleted from the storage location; this frees up disk space and makes the file inaccessible. Python has a number of modules and functions, such as os.remove() or os.unlink(), that permit you to interact with the operating system and remove files using code. This functionality is particularly useful when we want to automate tasks, ... Read More

How do I write method names in Java?

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

3K+ Views

While writing a method name we should follow the camel case i.e. first letter of the first word should be small and the first letters of the remaining (later) words should be capital. Example public class Test { public void sampleMethod() { System.out.println("This is sample method"); } public void demoMethod() { System.out.println("This is demo method"); } public static void main(String args[]) { Test obj = new Test(); obj.sample(); obj.demo(); } } Output This is sample method This is demo method

How do I write class names in Java?

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

4K+ Views

While writing class names you need to keep the following points in mind. You shouldn’t use predefined or existing class names as the name of the current class. You shouldn’t use any Java keywords as class name (with the same case). The First letter of the class name should be capital and remaining letters should be small (mixed case). class Sample Likewise, first letter of each word in the name should be capital an remaining letters should be small. class Test Keeping interface names simple and descriptive is suggestable. Better not ... Read More

How to create a unique directory name using Python?

Rajendra Dharmkar
Updated on 18-Feb-2020 04:56:12

815 Views

You can use the tempfile module to create a unique temporary directory in the most secure manner possible. There are no race conditions in the directory’s creation. The directory is readable, writable and searchable only by the creating user ID. Note that the user of mkdtemp() is responsible for deleting the temporary directory when done with it. To create a new temporary directory, use it as follows −import tempfile _, temp_dir_path = tempfile.mkdtemp() # Do what you want with this directory # And remove the directory when doneNote that you need to manually delete this directory after you're done with ... Read More

Are identifiers hello and Hello same in Java?

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

201 Views

Identifiers in Java are case-sensitive, therefore, hello and Hello are considered as two different identifiers.

How to create a unique temporary file name using Python?

Rajendra Dharmkar
Updated on 18-Feb-2020 04:54:54

628 Views

You can use the tempfile module to create a unique temporary file in the most secure manner possible. There are no race conditions in the file’s creation. The file is readable and writable only by the creating user ID. Note that the user of mkstemp() is responsible for deleting the temporary file when done with it. To create a new temporary file, use it as follows −import tempfile _, temp_file_path = tempfile.mkstemp() print("File path: " + temp_file_path)Note that you need to manually delete this file after you're done with it.

What is the difference between keywords and reserved words in Java?

Prabhas
Updated on 18-Feb-2020 11:11:37

564 Views

KeywordsKeywords in Java convey a special meaning to the compiler therefore, these cannot be used as identifiers. Java provides a set of 50 keywords.abstractcontinuefornewswitchassertdefaultgotopackagesynchronizedbooleandoifprivatethisbreakdoubleimplementsprotectedthrowbyteelseimportpublicthrowscaseenuminstanceofreturntransientcatchextendsintshorttrycharfinallongstrictfpvolatileconstfloatnativesuperwhileReserved wordsAmong the list of key words list mentioned above the key words goto and const are currently not in use. They are reserved words (for the future use).

What are valid identifiers in Java?

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

680 Views

A valid identifier in java – Must begin with a letter (A to Z or a to z), currency character ($) or an underscore (_). Can have any combination of characters after the first character. Cannot be a keyword. Example Following example shows various possible identifiers used to declare a variable in Java. Live Demo public class VariableTest { public static void main(String args[]) { // Declaring a variable named num int num = 1; ... Read More

Advertisements