CodeGym /Courses /Java Multithreading /Learning to google. How to find out whether an object has...

Learning to google. How to find out whether an object has a specific method? getName, getDisplayName, and getPublicName

Java Multithreading
Level 3 , Lesson 9
Available
Learning to google. How to find out whether an object has a specific method? getName, getDisplayName, and getPublicName - 1

"Hi, Amigo!"

"Let's continue our lessons on how to google."

"Here are some exercises:"

Question
1 How do you sort an array of numbers?
2 How do you sort a list of Strings in reverse alphabetical order?
3 How do you send an email from a Java program?
4 How can you tell if a passed object has a specific method?
5 What's the difference between TreeMap and HashMap?
6 Why do you need to write ArrayList<?> in that code?
7 How do you find the maximum value of an int?
8 How do you find the minimum value of a byte?
9 How do you convert a number to a hexadecimal string (123->»7B»)?
10 How do you convert a number to a binary string (123->»1111011″)?
Comments (8)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Paweł Mackiewicz Level 31, Poland, Poland
16 January 2025
Sort an array of numbers: Use Arrays.sort(array);. Sort a list of Strings in reverse alphabetical order: Use list.sort(Comparator.reverseOrder());. Send an email from a Java program: Use the javax.mail package with proper SMTP configuration. Check if an object has a specific method: Use Class<?> clazz = obj.getClass(); and then clazz.getMethod("methodName", paramTypes). TreeMap vs. HashMap: TreeMap is sorted and implements NavigableMap, while HashMap is unsorted and allows null keys. Why use ArrayList<?>: It indicates a generic wildcard type, allowing any type of elements in the ArrayList without specifying the exact type. Find the maximum value of an int: Use Integer.MAX_VALUE. Find the minimum value of a byte: Use Byte.MIN_VALUE. Convert number to hexadecimal string: Use Integer.toHexString(123). Convert number to binary string: Use Integer.toBinaryString(123).
manny9876 Level 35, Israel
16 November 2023
I'd appreciate it if someone can post all the the anwsers here
阿狼 Level 32, Zhengzhou, China
11 July 2022
d32
Ibrahim Level 41, Sheffield, United Kingdom
2 February 2022
Answer to number 6 here: https://stackoverflow.com/questions/9572060/what-does-sign-mean-in-arraylist
Andrei Level 41
6 April 2021
Does anyone know the answer to : 6. Why do you need to write ArrayList<?> in that code?
Szymon Level 41, Warsaw, Poland
12 April 2021
It basically means that if your variable is declared as ArrayList<?> you can initialize it with any non-primitive type inside the container e.g. ArrayList<String>, ArrayList<MyCustomClass> etc. But the thing I dont get is what is "that code" referring to in the question? Is that supposed to be understood as a general shown-during-the-interview kind of question?
Andrei Level 41
13 April 2021
Thanks! Yeah, good question. It might have been taken out from an interview where it was referring to some bit of code above the question.
Onur Bal Level 27, Istanbul, Turkey
14 October 2020
Great questions