Rubbal Bhusri

Ranch Hand
+ Follow
since Dec 30, 2010
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Rubbal Bhusri

Winston Gutkowski wrote:Indeed, IMO "Dynamic Polymorphism" is a tautology, because polymorphism can't be anything but dynamic.

I know that it's probably used to distinguish it from "Static Polymorphism", which is what some people call method overloading; but to me that term is also wrong.


So, you mean Static polymorphism is method overloading and Dynamic polymorphism is method overriding.
Is it so ?
7 years ago

Matthew Brown wrote: So I'd suggest using a Map<String, Integer> to contain the mapping. Then it's just a simple lookup.

Can you please give me a start-up on Map<> (mapping) ?
Because I know nothing about mapping.
7 years ago
I have a method that returns a String. and On the basis of that returned String I have to choose a value from a set of different values. I tried to use the switch, but it works with only int-type of values.
I have a method that returns String branch

Now, there are different Fees structures for different branches
e.g. CSE-500
ME- 800

Now based on the branch Name returned, I have to make a logic that chooses corresponding Fees structure, I tried to pass String in Switch as e.g

Suggest me some alternative to select values based on the String returned.
7 years ago

Matthew Brown wrote:The compiler doesn't know that on line 7 base happens to be referencing an instance of ChildClass. All it knows is that you declared the variable as BaseClass. So the only methods it knows it can safely call are those declared in BaseClass.

If compiler doesn't know, that it is referring to a reference variable of a child class, then how come it exactly pick the child class's overridden method when it should have chosen base class method. But here it choses child class's overridden method, however, it doesn't work for other methods.
Your answer seems to be contradicting to your point.
7 years ago

[Fixed formatting and line-length]
I know the statement calling new method with reference variable of BaseClass is wrong, because we can invoke only overridden methods of ChildClass, and not the new methods. I want to know why is it so ?
7 years ago

Winston Gutkowski wrote:
Make sure you understand exactly what is being asked of you; and if you're not sure, ask your tutor to clarify.
I'll give you some hints:

2) The email ID must include “@” followed by a minimum of 1 and maximum of 2 “.”

So, how many "@"s are allowed?

3) The substring before “@”must contain a combination of Upper case, Lower case and “_”

What about blanks?

4) The first letter of the Email ID must be in Upper Case

Have a look at the Character class (java.lang.Character (←click)). I think you'll find what you need. It'll also help with #3 above.

Actually, I am undergoing an online generic training in Infosys company. I have been given a LabGuide which consists of several problems, and it was one of those.
I stated the problem as it is, and changed nothing.
In a general view the additional conditions you are talking about must also come to make complete sense of validating any email-address.

I have to come out with a single method which checks all these conditions in one go.
So please suggest me in that angle.
7 years ago

Winston Gutkowski wrote:
My suggestion would be to set up a private method for each of your 4 validation checks, eg:
private final boolean checkLength(String email) { ...

So, you are asking me to make separate method for each of these conditions. But what-if I want to make just a single method to validate all these conditions in one go.
Is it possible ?
7 years ago

Matthew Brown wrote:I'm not sure I get your drift, but are you really saying that you want the program to guess where you want spaces and insert them for you? How are you expecting that to happen?

no-no, not really.
But if it can do so, the program becomes so magical.
7 years ago

Winston Gutkowski wrote:
char[] str1 = "This is really not immutable!!".toCharArray();

I didn't know about this way of invoking function, like you did above ( .toCharArray()).
I read few books but never saw such type of invocation.
Thank you for doing it in a different way.
7 years ago
I got your point, since copyOfValue() is a static method of String class, therefore I have to invoke it like this :
I corrected this code as follows :

But one more thing, I have to place spaces while assigning value to Str1. Otherwise the output (which is returned as a string) came as follows :

I mean, isn't there any way to get output in proper format, including spaces.
7 years ago
I have a problem as follows :
Planet one, a leading data management group has been given the task
of storing the records of their one lakh employees. The record contains an email id whose
datatype is String. The logic for validation of the email id needs to be written and hence
implement the following class EmailCheck:
Fields :
String emailId
+main(String args[]):void static

The validation rules for the email id check are as follows (to be implemented in main()):
1) Overall Length of the email ID must be greater than 3 and less 20
2) The email ID must include “@” followed by a minimum of 1 and maximum of 2 “.”
3) The substring before “@”must contain a combination of Upper case, Lower case and “_”
4) The first letter of the Email ID must be in Upper Case
If all validations are valid,
Display “Email Id is VALID!”
Display “<Appropriate Error Message>”
 “Invalid Length of email Id”
 “Invalid Position of Special Characters”
 “Invalid Combination for username”
 “Invalid Case of First Letter”

I could able to fulfill only two conditions in validateEmailId() method out of four conditions, and they are :
1) Overall Length of the email ID must be greater than 3 and less 20
2) The email ID must include “@” followed by a minimum of 1 and maximum of 2 “.”
But the other two conditions are hard to implement for me as I didn't find any method which directly checks the usage of UpperCase, LowerCase letters as well as use of '_' before the sign '@'
and method for checking the usage of UpperCase letters for first letter of whole string.

The code written by me is as follows :

Please help me in writing code for other two conditions too.
7 years ago
Isn't this an inbuilt method of String class ?
Do we have to define such inbuilt methods too ?

I shall be thankful , if you could solve it for me, because I didn't get your point.
7 years ago
I have copied this code from some website into my eclipse IDE, the website has shown correct output using same code, but my eclipse IDE found errors in lines where it called the function copyValueOf(char[]) method saying that the method is undefined for the class I created. The code is :

import java.util.*;
public class Test {

* @param args
public static void main(String[] args) {
// TODO Auto-generated method stub
char[] Str1 = {'T','h','i','s', 'i','s', 'r','e','a','l','l','y', 'n','o','t', 'i','m','m','u','t','a','b','l','e', '!','!'};
String Str2;
Str2 = copyValueOf(Str1);
System.out.println("Returned String " + Str2);
Str2 = copyValueOf( Str1, 5, 10 );
System.out.println("Returned String " + Str2);


Please help me in removing the error.
7 years ago
What a silly mistake I did ! Thank you so much for being more than a compiler because even my compiler didn't give me exact explanation of this mismatch.
7 years ago
what is the error in following code ?
why the output shows : Array-index-out-of-bound, when it is not ?
The code is :

7 years ago