Posts

Object Class in Java | Article | Solution Maker - Blog

Solution Maker Understanding the Object Class in Java: Methods, Overriding, and Best Practices Introduction      The Object class in Java is the cornerstone of the Java class hierarchy. Every class in Java is directly or indirectly derived from the Object class, making it fundamental to understanding Java programming. In this blog post, we'll explore the key methods provided by the Object class, the implications of overriding these methods, and best practices for ensuring consistent behavior in your Java applications. Key Methods of the Object Class The Object class provides several essential methods that are inherited by all Java objects: toString() : Returns a string representation of the object. By default, it includes the class name and the ...

Regex Pattern for Validating Length in Java 2024 - Java Technical Interview

Regex Pattern Program for Validating Length           Here we are going to check whether the given String has only certain number length using the Regex Pattern matching logic in Java. The steps are Logical Theory : Check for Length: Ensure the number has exactly 10 digits. Regex Pattern for Validation :      1. Regex: ^.{10}$      2. Explanation:               ^ asserts the start of the string.               .{10} matches exact length10.               $ asserts the end of the string. Code : package com.dinatechy.challange; import java.util.regex.Matcher; import java.util.regex.Pattern; public class LenghtPattern { public static void main(String[] args ) { // Pattern for validate length String content = "DinaTechy" ; // length - 9 Pattern pattern = Pattern. compile ( "^.{9}$" ); Matcher matcher ...

Regex Pattern for Mobile Number in Java 2024 - Java Technical Interview

 Regex Pattern for Mobile Number     Here we are going to check whether the given String is contain mobile number or not using the Regex Pattern matching logic in Java. The steps are Logical Theory : Check for Length : Ensure the number has exactly 10 digits (or more if including a country code). Check for Digits : Ensure that all characters are numeric. Regex Pattern for Validation : Regex: ^\d{10}$ Explanation: ^ asserts the start of the string. \d{10} matches exactly 10 digits. $ asserts the end of the string. Code : package com.dinatechy.challange; import java.util.regex.Matcher; import java.util.regex.Pattern; public class MobileNoPattern { public static void main(String[] args ) { // Mobile number Pattern // length should be 10 // must be digits String mobileNo = "9876543210" ; Pattern pattern = Pattern. compile ( "^\\d{10}$" ); // d refers to only digit's // 10 length Matcher matcher = pattern .matcher( mobileN...

Finding Triangle with Three lengths in Java 2024 - Java Technical Interview

 Finding Triangle with Three length          We are going to find which Triangle's side this are using Java. 1. We are check three Triangle, which is  Equilateral, Isosceles and Scalene. 2. First we need to know the Mathmetical logic for all this,      Equilateral ==> all the three length's are equal.      Isosceles ==> either two side's are equal      Scalene ==> all three side's are different 3. Final part is we need to implement this in code. Code :  package com.dinatechy.challange; public class FindWhichTriangle { public static void main(String[] args ) { // Find the Which Triangle based on the given Three length's // Equilateral == all the three lenght's are equal, // Isosceles == either two side's are equal or // Scalene == all three side's are different int a = 23, b = 231, c = 232; if ( a == b && b == c && c == a ) Syste...

Pattern Matching in Java - Technical Interview 2024 - Problem Solving

 Pattern Matching Logic               First thing we need to know the content we are going to do the matching and the pattern. 1. Create a reference for Pattern class and then Call the Pattern class static method compile method and send the parameter as pattern you want to search for. 2. Create reference for Matcher and assign the method which is Pattern class method matcher, here send the parameter as content we need to check. 3. Finally call the find method in Matcher class to check the pattern is matched or not. If the method is return true the pattern is matched, if the method return false the pattern is not matched. Code :  package com.dinatechy.challange; import java.util.regex.Matcher; import java.util.regex.Pattern; public class PatternMatching { public static void main(String[] args ) { // Pattern Matching in Java // Example : content = "Hello people hi ", pattern = " hi " // Regex String content = ...

Check if String contains only Digit's - Java 2024 - Technical Interview

 Check String contains only Digit's           Get the input from the user using Scanner class. Then create a method to check the following condition. 1. Check if the string is null or empty, if it is directly return false. 2. Iterate the String using for loop inside the for loop, use the if for condition checking. 3. Condition is check the Digit's only, for this use the Character Wrapper class, in that we have isDigit() method to check the Digit's. 4. This method will return true or false based on it is Digit's or not. Code : package com.dinatechy.challange; import java.util.Scanner; public class CheckDigitsOnly { public static void main(String[] args ) { //To check if the String contains only Digit's Scanner scan = new Scanner(System. in ); String data = scan .next(); scan .close(); boolean isDigits = checkDigits ( data ); System. out .println( isDigits ? "Yes it is" : "No it's not" ); } privat...

Checking Character only in String - Java 2024 - MNC - Technical Interview

 Checking if the String contains Character only     Get the input from the user using Scanner class. Then create a method to check the following condition. 1. Check if the string is null or empty, if it is directly return false. 2. Iterate the String using for loop inside the for loop, use the if for condition checking. 3. Condition is check the Character only, for this use the Character Wrapper class, in that we have  isAlphabetic() method to check the character. 4. This method will return true or false based on it is character or not. Code: package com.dinatechy.challange; import java.util.Scanner; public class CheckCharacter { public static void main(String[] args ) { //Check the String only contains Character or Not Scanner scan = new Scanner(System. in ); System. out .print( "Enter the String : " ); String data = scan .next(); scan .close(); boolean isChar = checkOnlyCharacter ( data ); System. out .println( isChar ? "Yes...

Find GCD of Two number in Java - Euclidean algorithm - 2024

 Finding GCD of Two Number     First we need to modules the first number by second number, then store the output in second number.     Before doing the modules store the second number value for next iteration in temp variable. And do the process still the second number becomes zero. Code : package com.dinatechy.challange; import java.util.Scanner; public class GCDofNumber { public static void main(String[] args ) { Scanner scanner = new Scanner(System. in ); System. out .print( "Enter the first number: " ); int num1 = scanner .nextInt(); System. out .print( "Enter the second number: " ); int num2 = scanner .nextInt(); scanner .close(); // Calculate the GCD int gcd = findGCD ( num1 , num2 ); // Print the result System. out .println( "The GCD of " + num1 + " and " + num2 + " is: " + gcd ); } // Method to find the GCD usi...

Check the number is Prime using Java - Technical Interview - MNC - 2024

 Check the number is Prime                    First we need to check whether the number is 1 or 0, if it is straight away you can say it is Prime Number.                    Next we need to divide the number by 2, because if we couldn't divide a number by more than half of a number.                    Final Thing is start the for loop and inside for loop modules the given number by loop variable, if the remainder is zero it is not Prime, if not it is Prime Number. Code :  package com.dinatechy.challange; import java.util.Scanner; public class PrimeNumber { public static void main(String[] args ) { //Check if the given number is Prime or not Scanner scan = new Scanner(System. in ); int number = scan .nextInt(); scan .close(); boolean result = isPrime ( number ); System. out .pri...

Counting Vowels in a String - Time Complexity - Java 2024

 Counting Vowels in a String          We have two String's, one has the value we need to check and another has a vowels.  1. First we need a for loop for iteration of the given String. 2. Second for the condition end value is String's length, so to achieve Time Complexity we are storing the size of the String in one variable. 3. Next step as inside the for loop take the each character from the string and check if that character is in the vowels string. 4. If the condition is true increase the count values as one using post increment operator. If not doesn't do anything move to next iteration. Code : package com.dinatechy.challange; public class CountVowels { public static void main(String[] args ) { //Count number of Vowels - a e i o u String value = "DinaTechy" ; // vowels = 3 String vowels = "aeiou" ; int count = 0; int size = value .length(); for ( int i =0; i < size ; i ++) { if ( vowels .contains(String. ...

Instagram Follow Button Style - Frontend 2024 - Html & CSS.

 Instagram Follow Button Code :  <! DOCTYPE html > < html lang = "en" > < head >     < meta charset = "UTF-8" >     < meta name = "viewport" content = "width=device-width, initial-scale=1.0" >     < title > Document </ title >     < style >         .follow-btn {             background-color : rgb ( 33 , 125 , 218 );             border : none ;             border-radius : 4px ;             padding : 5px 12px ;             color : white ;             margin : 0 30% ;             font-weight : bold ;             letter-spacing : 1px ;         }     </ style > </ head > < body >  ...

Subscribe Button Styles - Frontend in 2024 - Html & CSS.

Image
Subscribe Button Styles Code :  <! DOCTYPE html > < html lang = "en" > < head >     < meta charset = "UTF-8" >     < meta name = "viewport" content = "width=device-width, initial-scale=1.0" >     < title > Document </ title >     < style >         .subscribe {             display : flex ;             align-items : center ;             gap : 0.5rem ;             background-color : rgb ( 229 , 231 , 234 );             padding : 0 6px ;             width : 120px ;             border-radius : 16px ;             margin : 0 30% ;         }     </ style > </ head > < body >     < ...

Finding Second largest number in Array - Java - TCS - Technical Interview

 Finding Second largest Number in Array :           1. First we need two variable called largest and second-largest. As next step, we need to use for-each loop to get the elements one by one.           2. Then as first condition is check whether value from the array is greater than largest.            3. If it is store the largest value into second-largest and value from the array into largest.            4. If not check another condition as value from the array is greater than second-largest and not equal to largest.            5. If this condition is true, store the value from the array into second-largest, is this if the second-largest value is value of last before(that is array.length-2 location).            6. It that condition also false do nothing, continue to next iteration. Co...

Serialization in Java

Image
  Serialization :         It is a process of converting Object into Stream (Sequence of data flow).         To implement Serialization, we first need to inherit the Serializable interface into the class where we want Serialization. Here, is the example : Next thing is to start the process of Data Transfer :  Thanks for reaching out Guys, if you any doubts or errors kindly let me know in the comments .

Java Program Question - MNC - Technical Interview

                Here we are going to see a very Interesting and Complicated Java Programming Questions, which is asking in literally all MNC's Technical Interview's Input : Array -- { 5,1,8,-5,-1,6,2,-2,45,-55,-9,-89,9 } Output :  Array -- { -89 -55 -9 9 -5 5 -2 2 -1 1 6 8 45 } Program :  package com.array; public class SortingArray { public static void main ( String [] args ) { int [] arr = { 5 , 1 , 8 ,- 5 ,- 1 , 6 , 2 ,- 2 , 45 ,- 55 ,- 9 ,- 89 , 9 }; for ( int a : arr ) { System . out . print ( a + " " ); } System . out . println (); for ( int i = 0 ; i < arr . length ; i ++) { for ( int j = i ; j < arr . length ; j ++) { if ( arr [ i ]> arr [ j ]) { int temp = arr [ i ]; arr [ i ] = arr [ j ]; arr [ j ] = temp ; } } } for ( int i = 0 ; i < arr . length ; i ++) {            ...