![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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 9326 Articles for Object Oriented Programming
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
15K+ Views
Let’s say we have the following string, that has some letters and numbers.String str = "9as78";Now loop through the length of this string and use the Character.isLetter() method. Within that, use the charAt() method to check for each character/ number in the string.for (int i = 0; i < str.length(); i++) { if (Character.isLetter(str.charAt(i))) count++; }We have set a count variable above to get the length of the letters in the string.Here’s the complete example.Example Live Demopublic class Demo { public static void main(String []args) { String str = "9as78"; int count ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
5K+ Views
To check whether the entered value is a letter or not in Java, use the Character.isLetter() method.We have a value to be checked.char val = 'D';Now let us use the Character.isLetter() method.if (Character.isLetter(val)) { System.out.println("Character is in Lowercase!"); }else { System.out.println("Character is in Uppercase!"); }Let us see the complete example now to check for letter.Example Live Demopublic class Demo { public static void main(String []args) { System.out.println("Checking whether the given value is a Letter or not..."); char val = 'D'; System.out.println("Value: "+val); if (Character.isLetter(val)) { ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
1K+ Views
To validate if a String has only numbers, you can try the following codes. We have used the matches() method in Java here to check for number in a string.Example Live Demopublic class Demo { public static void main(String []args) { String str = "978"; System.out.println("Checking for string that has only numbers..."); System.out.println("String: "+str); if(str.matches("[0-9]+") && str.length() > 2) System.out.println("String has only numbers!"); else System.out.println("String consist of characters as well!"); } }OutputChecking for string that has only numbers... ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
873 Views
To check for Integer overflow, we need to check the Integer.MAX_VALUE with the subtracted integers result, Here, Integer.MAX_VALUE is the maximum value of an integer in Java.Let us see an example wherein integers are subtracted and if the result is more than Integer.MAX_VALUE, then an exception is thrown.The following is an example showing how to check for Integer overflow.Example Live Demopublic class Demo { public static void main(String[] args) { int val1 = 9898999; int val2 = 8784556; System.out.println("Value1: "+val1); System.out.println("Value2: "+val2); long sub = ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
39K+ Views
To check whether a character is in Uppercase or not in Java, use the Character.isUpperCase() method.We have a character to be checked.char val = 'K';Now let us use the Character.isUpperCase() method.if (Character.isUpperCase(val)) { System.out.println("Character is in Uppercase!"); }else { System.out.println("Character is in Lowercase!"); }Let us see the complete example now to check for Uppercase in Java.Example Live Demopublic class Demo { public static void main(String []args) { System.out.println("Checking for Uppercase character..."); char val = 'K'; System.out.println("Character: "+val); if (Character.isUpperCase(val)) { System.out.println("Character is ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
508 Views
To display printable characters, you need to work with the ASCII values from 32 to 127.With that, we are using the following, instead of System.out.println()System.out.write();The following displays all the printable characters.for (int i = 32; i < 127; i++) { System.out.write(i);Let us see the complete example.Example Live Demopublic class Demo { public static void main(String []args) { System.out.println("Printable characters..."); for (int i = 32; i < 127; i++) { System.out.write(i); if (i % 8 == 7) System.out.write(''); else ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
2K+ Views
To assign int value to a char variable in Java would consider the ASCII value and display the associated character/ digit.Here, we have a char.char val;Now assign int value to it.val = 77;Now, when you will print the value of “val”, it would display the character associate with the value (ASCII) 77.The following is the complete example.Example Live Demopublic class Demo { public static void main(String []args) { char val; val = 77; System.out.print("Value: "); System.out.println(val); } }OutputValue: M
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
1K+ Views
To reverse an integer in Java, try the following code −Example Live Demoimport java.lang.*; public class Demo { public static void main(String[] args) { int i = 239, rev = 0; System.out.println("Original: " + i); while(i != 0) { int digit = i % 10; rev = rev * 10 + digit; i /= 10; } System.out.println("Reversed: " + rev); } }OutputOriginal: 239 Reversed: 932In the above program, we have the following int value, which we will reverse.int i = 239;Now, loop through until the value is 0. Find the remainder and perform the following operations to get the reverse of the given integer 239.while(i != 0) { int digit = i % 10; rev = rev * 10 + digit; i /= 10; }
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
444 Views
To compare two Java short arrays, use the Arrays.equals() method.Let us first declare and initialize some int arrays.int[] arr1 = new int[] { 33, 66, 12, 56, 99 }; int[] arr2 = new int[] { 33, 66, 12, 56, 99 }; int[] arr3 = new int[] { 33, 66, 15, 56, 90 };Now let us compare any two of the above arrays.Arrays.equals(arr1, arr2));In the same way, work it for other arrays and compare themExample Live Demoimport java.util.*; public class Demo { public static void main(String[] args) { int[] arr1 = new int[] { 33, 66, 12, 56, ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
939 Views
To pass an integer by reference in Java, try the following code −Example Live Demopublic class Demo { public static void display(int[] arr) { arr[0] = arr[0] + 50;; } public static void main(String[] args) { int val = 50; int[] myArr = { val }; display(myArr); System.out.println(myArr[0]); } }Output100In the above program, a custom method is created, which pass an int array.int val = 50; int[] myArr = { val }; display(myArr);In the method, we have performed mathematical operation on the value of array.public static void display(int[] arr) { arr[0] = arr[0] + 50;; }The updated value is then displayed in the main.System.out.println(myArr[0]);