sohail hussain

Ranch Hand
+ Follow
since Sep 06, 2018
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
4
Received in last 30 days
1
Total given
2
Given in last 30 days
2
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by sohail hussain

Campbell Ritchie wrote:

sohail hussain wrote:. . . you have to provide start index and end index to which you want to get substring

Please check the String documentation for details of overloaded methods before posting that sort of thing.

Example...
"hello".substring(2, 4)
It will print "llo" . . .

Afraid that isn't correct, as you will see from the appropriate documentation link.

I personally checked it compiled well but only difference is output is "ll" not "llo"
Because it take index less then one what you specified in substring(2,4) so on and counts index same as you specified that is on index 4 we have "l" so printed "ll"
1 week ago

Ana Yo wrote:What would "hello".substring(5) return?

you have to provide start index and end index to which you want to get substring
Example...
"hello".substring(2, 4)
It will print "llo"as the output that means 2 is the start of index where 4 is the end of index
And if you are specifying only one index that is start index then you need have" hello world" then substring (5) will print after the index 5 which is "world" as output
Hope this helpful
1 week ago

Paul Anilprem wrote:

sohail hussain wrote: I mean it's again depend on the type of access modifier using in equals() method                                            
Example... Default boolean equals() {}
Then you cannot override the equals()
This is from whizlabs mocks question which I got to know, and I personally checked it, compiled successfully,
So my question is why this diffrence has made for access modifiers, may be reason is package accessibility


Don't know what whizlab says but you can't override equals in a subclass with less than public accessibility because it is public in Object class.

yes you are right it should be public  accessibility

Campbell Ritchie wrote:Yes, it can override equals() from its superclass. It may introduce errors into the method by such overriding, but the only way to prevent such overriding is to mark the method final.

I mean it's again depend on the type of access modifier using in equals() method                                            
Example... Default boolean equals() {}
Then you cannot override the equals()
This is from whizlabs mocks question which I got to know, and I personally checked it, compiled successfully,
So my question is why this diffrence has made for access modifiers, may be reason is package accessibility

Campbell Ritchie wrote:SH: please explain your last post. I am finding it difficult to understand, but I think it is incorrect.

means if you have class c1 which has implemented equals() method from object class then another class c2 which extends c1 cannot override the equals method from c1 class to c2 class

emma roberts wrote:please why i can't override an equals method with a class how is a subclass of class object?

every class is subclass to object class so equals() method you can implement to subclass but if you have hierarchy of subclasses then it is not possible to override equals() method from class which is superclass to the class in which equals() already implemented

Petros Papatheodoru wrote:Hello, I would like some advice about how to use the main() method in my programs, and more specifically, what to put in there. Is it better to declare everything static and work like that or is it more preferable to create an instance of the main class and call another non static method and concider the new method as main() ? Also, consider this: I am given a university assignement where I have to come up with 2 algorithms that solve 2 different problems. I am asked to provide only one main method. Should I treat this main method as a merge of what would otherwise had been 2 main methods? For example for the first problem, check the arguments, then go ahead and call some methods of the one class and print the result and then continue to do something simillar for the second problem in the same main method. Or should I create 2 instances for the 2 other classes and call a non method that takes care of everything, for each of the 2 other classes?

basically if you have main() method then creates a class file for every class which contains main() method, now if you want to do one main() method then it should be test class, then for operation you want perform individual task create class for every task and use polymorphic behavior  by  creating instance of each class and call them from test class by using reference of instance to which it is pointing,, hope it helps
2 weeks ago

emma roberts wrote:i have this prgram of OCA book
[code=java]
public class koala{
public static int count=0;
public static void main(String[] args){
koala k=new koala();
System.out.println(k.count);
k=null;
System.out.println(k.count);

}

}

K=null means object is null but not the reference, so is still there you can refer to static variable with reference 'k' and if you remove static keyword then it becomes object variable so as long as object avaliable field is available, but you kept the object null, last print statement gives null pointer exception because object is null so there is no field so error

2 weeks ago

joseph hu wrote:i=i++  means i=i  and then i++ the same i++

it  is postfix operator so at first Will not update and same value is assigned to i

Veena Pointi wrote:[code=java]for(i=0;i<5;i=i++){

System.out.println(i);

}
Veena

means you are not updating the variable i, instead you are assigning updated value of variable i, to itself so it is assigning not updating that's the reason loop is infinite because condition is always true if value is not updated

myProcess() does the below:

calls fetchTableData  and gets the response.
uses the above response to call computeResults method compute the result and return this as response.
uses the above response to save into the database by calling saveOutputResults method.


Is it a wrong design?


OK fine, but my suggestion is you can use  method chaining concept please provide your complete code, I want to know how it works thanks  M. S
3 weeks ago

Monica Shiralkar wrote:

Why? That sounds like very dubious design.




The entire processing is broken down into 4 methods:
fetchTableData
computeResults
saveOutputResults


and myProcess() is the method which calls the 3 methods.


means methods inside method call I don't no such concepts that  its, because one method call contains other method call only one call, how does three methods will execute
3 weeks ago
I compiled it, I got nothing output because an empty array list is created which is fine, and a variable j is declared, and in for loop we are checking the variable i is less than list size(), which is false so come out of the loop and display nothing, is that OK to read the code like this and according to the code output is different, may be        wrong question  

Alisa Crowe wrote:I realize this has been explained, but I still have a question.  

If house.getChickens().size() = 0, then the for loop is never executed, resulting in no output- happily so even.
I thought the update statements aren't touched until after the body executes, which it never does.



This compiles and runs without any output.  What am I missing?  Thank you

Thank you for your quick reply.  But the book says that this will either have a runtime exception or produce at least one line of code.
That is what I don't understand.  My example shows that it will successfully run and produce no output, which is in contradiction with
the answer in the book.
Thank you again, Lisa

condition is there, so body executed well but it is not updating rather it is the value of i is updated and assigned to calling method get(),as formal parameter, I am not sure that you are not adding values to arraylist,before for loop, may be get(), does add values but it should be before condition of the for loop, so that it check for condition in for loop, and define the variable i outside of for loop that you can write your code before condition of for loop if you are use commend line argument its OK, I am not sure get() will return the updated value because it is i has  postfix increment operator and you are assigning to just variable j, not to list

Monica Shiralkar wrote:I have a code where a myProcess() method is responsible for entire functionality. Should I enclose this in a try catch block as below:




thanks

it depends on code, and it's courtcy in Java to use try catch cluose again it depends on, what type of  exceptions are, may be checked are unchecked exception, if you say it may throw an exception then use throws clause,  in calling method header, because checked exception are propagated with throws clause, if unchecked exceptions are there then it will compiled well but at runtime it causes error if don't specify
3 weeks ago