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
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by sohail hussain

that means talking about exception propagation, if yes then checked exception are propagated with throws clause and unchecked exceptions are propagated with throw,
3 weeks ago

Paul Clapham wrote:

joseph hu wrote:below is correct.



Except that the comment isn't correct. That code does not throw ClassCastException.

yes you are right because superclass reference pointing to subclass object so at runtime it points to subclass object there for it can  be casted, may be I am wrong but I thought in that way it works, please any way that it cast can happen explain sombody
3 weeks ago

Ouadi Belmokhtar wrote:Hi guys
I would like to ask for some suggestions from your experience on taking Java certifications.
I'am preparing OCA8, I fully read OCA8 Mala Gupta's book. I scored 61/77 on mock exam provided in the book.
Now, before taking the real exam, I'm hesitating between doing more preparations by taking more mock exams in (Selikoff's OCA8 Practice Tests book) OR taking directly Enthuware mock exams !
Knowing that I don't have a significant experience in Java development
What do you think ?

you are right you must go for enthuware mocks and you are almost done your preparation according to your mocks in Mala Gupta books that's very easy to understand, try 2 to 3 mocks in enthuware then if got at least 75% then your are ready to write I am also preparing for ocajp8 since 1year am writing my ocajp in June and one more point try for Khaled mughal book for ocajp8

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 month 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 month 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
1 month 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

1 month 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
1 month 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
1 month ago