sekhar kiran

Ranch Hand
+ Follow
since Apr 25, 2013
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by sekhar kiran

Norm Radder wrote:The code must us an expression like the following to get an int value that can be used to order the Employee objects:
oneEmployee.compareTo(anotherEmployee)


in that case it should be like 80000 comparto(75000) like that rite?
but in programing i see 75000-80000?this makes me confused/how this.sal works here this makes me annoying and confused
7 years ago

Norm Radder wrote:Look at the source code for the sort method to see how it works.



how could i see, imean your taking about sorting in compartomethods?
7 years ago

Henry Wong wrote:

sekhar kiran wrote:
finally how this sorting occurs?



As already mentioned a few times, the details of the sorting algorithm are not officially documented. You will need to examine the source code.

Henry


k got you, so it will happens internally,so leave that one.how this.sal and emp.sal values taken from given object,
7 years ago
before sorting of objects salary 80000 75000 120000 60000

so here how this.sal refers to 2nd instance of object salary dis is my first doubt
this.salary-emp.salary
75000-80000 = - value this.sal<emp.sal
so above condition shows negative value,after that is it going to sort or swap what wil happen?

after that again how the values taken ie this.sal and emp.sal for next step

120000-75000= + value this.sal>emp.sal

120000-80000 = + value this.sal>emp.sal

60000-80000 = - value this.sal<emp.sal

60000-75000= - value this.sal<emp.sal

finally how this sorting occurs?
7 years ago
i mean when i debugg i could see
this.salary operator employee.salary
75000 - 80000
120000 - 75000
120000 - 80000
60000 - 80000
60000 - 75000

so how it takes the value for this.salary as well as employee.sal which was taken .
we inserted order of salary 80000, 750000, 120000 and 60000.
7 years ago

Norm Radder wrote:Is your problem solved now? If not, please explain.


yeah i have a doubt ie how this.salary refering 2nd instance and how employe.sal refers 1st. and how it was comparing and sorting values
7 years ago

Ganish Patil wrote:I have run your and mine program in debug mode. I found strange way of comparing these values with each other. In your program values that are compared is salary so here we have your insertion order of salary 80000, 750000, 120000 and 60000. While debuging in variable window after Arrays.sort(e); I saw values being compared in following fashion in public int compareTo(Employee employee)

this.salaryoperatoremployee.salary
75000-80000
120000-75000
120000-80000
60000-80000
60000-75000

Even in my program I added values in List. Insertion order 10, 6 and 60.While debuging in variable window after Collections.sort(myClassList); I saw value being compared in following fashion in public int compareTo(ComparableWithinClassDemo o).
this.classIdoperatoro.classId
6-10
60-6
60-10

I checked source code by clicking on Collections.sort() method it does cloning of this array of objects and does merge sort. It is quite obscure to understand. I don't think we need to know that much in detail. If anyone know will be great If explains


even i debugged i could see here my doubt is how this.salary refering 2nd instance and how employe.sal refers 1st. and how it was comparing and sorting values
7 years ago

Norm Radder wrote:The Arrays class's sort() method uses the compareTo() method with two elements in the list of Employees to determine the sort order. The code probably uses an expression like this to determine the order:
oneEmployeeElement.compareTo(anotherEmployeeElement)


I mean I got your point but why should take like this 75000- 80000 ,I mean this.salary refers 2nd instance?

2) ineed exact function what Is happening in that comparetomethod which shows in example

waiting for reply.
7 years ago

Norm Radder wrote:

so this.salary refers 75000 how?


The compareTo method is located in an instance of the Employee class. this.salary refers to the variable in the same instance of the class. The Employee reference passed to the compareTo() method is the other object that is being compared to this object.


so this.salary refers to be 80000 this one only na.i mean how it can initialize 2nd instance.

Henry Wong wrote:

sekhar kiran wrote:
negative value indicateds salary is less than employee salary am i right?
so here my doubt is



What initialization of Employee object? This is just an method declaration.

Henry


i mean we are passing those variables into that method rite
7 years ago

Norm Radder wrote:

what here happening.


Look at the API doc for the Comparable class's compareTo method. It returns an int value that can be used to order the objects in the list that is being sorted.
It determines if this object is less than, equal to, or greater than the specified object.
The code uses it to order the objects based on the value of the salary variable. If this salary is 500 and the employee's salary is 600, the method would return -100.
What does the API doc say about negative values?


negative value indicateds salary is less than employee salary am i right?
so here my doubt is
public int compareTo(Employee employee)/ here we are initializing the employee objects rite?
{
return this.salary - employee.salary; so here what is indicates actually which mean here substraction is happening ?so this.salary refers 75000 how?
}
7 years ago
Im stuck at comparable intefaces..i know it was used to sorting objectss..but i need some clarity.in below program im confused for that overide compareto method.actually what here happening.
@Override
public int compareTo(Employee employee)
{
return this.salary - employee.salary;
}

7 years ago

Jesper de Jong wrote:

sekhar kiran wrote:i got error


What is the error?

Error messages contain a lot of useful information about what is wrong. Don't just think "Oh, an error. Now I don't know what to do." At least read and try to understand what the error message means. If you don't know, and you post a question in the forums, then include the error message, because it helps other people to understand what's wrong. If you don't tell us what the error is, you're making it hard for us to help you.


when i compile i got this ie C:\Documents and Settings\admin\Desktop>javac Client.java
.\MyOwnExceptionClass.java:12: error: illegal character: \160
return "Price should not be in negative, you are entered" +price;
9 years ago
whats the output of above program,how to get it,i got error
9 years ago

Campbell Ritchie wrote:

sekhar kiran wrote: . . .
so throw will use instead of try catch ,am i right?when we will use throws ofcourse it is system defined excption,which scenario will use

No. No.

You use throw to signal that something has gone wrong and your method should not continue. You use throws to signal that your method might suffer a particular exception. Google for Java Tutorials Exceptions and read that.


then we can use try and catch instead to throw?then what the purpose of throw ,is it more advantage?
below program i got an error ie


i got error ie
C:\Documents and Settings\admin\Desktop>javac Client.java
.\MyOwnExceptionClass.java:12: error: illegal character: \160
 return "Price should not be in negative, you are entered" +price;
^

10 years ago

Campbell Ritchie wrote:No. An interface gives much more flexibility. Both have their uses.


we can declare methods in interface but we cant define ,but in abstract we can declare as well as we can define
then when we will use interface while developing in project because abstract can do all features which are available in interface
10 years ago