- 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 9320 Articles for Object Oriented Programming
![Malhar Lathkar](https://www.tutorialspoint.com/assets/profiles/7345/profile/60_93814-1511173378.jpg)
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
![Sreemaha](https://www.tutorialspoint.com/assets/profiles/13570/profile/60_64977-1512709068.jpg)
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
![varma](https://www.tutorialspoint.com/assets/profiles/13568/profile/60_26300-1512638592.jpg)
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
![usharani](https://www.tutorialspoint.com/assets/profiles/13564/profile/60_32161-1512638316.jpg)
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
![Prabhas](https://www.tutorialspoint.com/assets/profiles/13554/profile/60_90506-1512543588.jpg)
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).
![seetha](https://www.tutorialspoint.com/assets/profiles/13549/profile/60_42938-1512640859.jpg)
679 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
![vanithasree](https://www.tutorialspoint.com/assets/profiles/13547/profile/60_85216-1512542720.jpg)
560 Views
Multiline comments (/* */) are used to comment multiple lines in the source code. Example Live Demo public class CommentsExample { /* Following is the main method here, We create a variable named num. And, print its value * */ public static void main(String args[]) { //Declaring a variable named num int num = 1; ... Read More
![mkotla](https://www.tutorialspoint.com/assets/profiles/13540/profile/60_41073-1512640012.jpg)
455 Views
To comment a particular line just place ‘double back slash (//)’ before the line as shown below. // Hello this line is commented Example Following example demonstrates the usage of single line comments in Java. Live Demo public class CommentsExample { public static void main(String args[]) { //Declaring a variable named num int num = 1; //Printing the value of the variable num System.out.println("value if the variable num: "+num); } } Output value if the variable num: 1
![Sreemaha](https://www.tutorialspoint.com/assets/profiles/13570/profile/60_64977-1512709068.jpg)
522 Views
The java.lang package is the default package in Java, by default, it will be imported. Therefore, there is no need to import this package explicitly. i.e. without importing you can access the classes of this package. Example If you observe the following example here we haven’t imported the lang package explicitly but, still, we are able to calculate the square root of a number using the sqrt() method of the java.lang.Math class. Live Demo public class LangTest { public static void main(String args[]) { int num = 100; ... Read More