• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

filters

 
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am still not sure how to correct these errors can some expert quickly help to resolve all these errors so that we could just focus next things  here...


Thanks much..
 
Saloon Keeper
Posts: 7165
165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you know what an "import" is in Java? If not, work through the relevant section of Oracle's Java tutorial first. After that: how would you use an import to let the Java compiler know that your code wants to use some class, for example 'Comparator"? If you have worked through the tutorial, you would know this, and be able to change your code accordingly.
 
John Ken
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it's amazing when i just added one line of code(import java.util.*) in my Employee java program then i just got 1 error but when i just added ';' in front of this line then i got 10 errors.







F:\Java Training\Java Programs>javac Employee.java
Employee.java:4: error: ';' expected
import java.util.*
                 ^
1 error

F:\Java Training\Java Programs>javac Employee.java
Employee.java:11: error: cannot find symbol
                 .filter(e->e.getAge()>22)
                             ^
 symbol:   method getAge()
 location: variable e of type Employee
Employee.java:12: error: invalid method reference
                 .map(Employee::getName)
                      ^
 cannot find symbol
   symbol:   method getName()
   location: class Employee
Employee.java:23: error: constructor Employee in class Employee cannot be applied to given types;
       Employee e1=new Employee("John",21);
                   ^
 required: no arguments
 found:    String,int
 reason: actual and formal argument lists differ in length
Employee.java:24: error: constructor Employee in class Employee cannot be applied to given types;
       Employee e2=new Employee("Martin",19);
                   ^
 required: no arguments
 found:    String,int
 reason: actual and formal argument lists differ in length
Employee.java:25: error: constructor Employee in class Employee cannot be applied to given types;
       Employee e3=new Employee("Mary",31);
                   ^
 required: no arguments
 found:    String,int
 reason: actual and formal argument lists differ in length
Employee.java:26: error: constructor Employee in class Employee cannot be applied to given types;
       Employee e4=new Employee("Stephan",18);
                   ^
 required: no arguments
 found:    String,int
 reason: actual and formal argument lists differ in length
Employee.java:27: error: constructor Employee in class Employee cannot be applied to given types;
       Employee e5=new Employee("Gary",26);
                   ^
 required: no arguments
 found:    String,int
 reason: actual and formal argument lists differ in length
Employee.java:34: error: invalid method reference
 Comparator<Employee> comp = Comparator.comparing(Employee::getName);
                                                  ^
 cannot find symbol
   symbol:   method getName()
   location: class Employee
Employee.java:35: error: cannot find symbol
var filteredAndSorted = employees.stream()
                       ^
 symbol:   variable employees
 location: class Employee
Employee.java:37: error: cannot find symbol
   .collect(toCollection(() -> new TreeSet<>(comp)))
            ^
 symbol:   method toCollection(()->new Tr[...]comp))
 location: class Employee
10 errors

F:\Java Training\Java Programs>javac Employee.java
Employee.java:4: error: ';' expected
import java.util.*
                 ^
1 error

F:\Java Training\Java Programs>

 
Tim Moores
Saloon Keeper
Posts: 7165
165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not surprising at all. If you remove the semi-colon the file is syntactically invalid, and the compiler simply gives up trying to make sense of it. Otherwise it's syntactically correct, but has lots of semantic problems.
 
John Ken
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
could some expert please quickly remove all these errors and make my code run successfully?

Thanks much...
 
Marshal
Posts: 74351
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could, yes, will, no.
 
Tim Moores
Saloon Keeper
Posts: 7165
165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesn't take an expert, just someone who is willing to read the advice given here already and apply it.
 
John Ken
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i studied comparator but unable to fix it here:-Comparator interface is used to order the objects of user-defined classes. A comparator object is capable of comparing two objects of two different classes. Following function compare obj1 with obj2

Syntax:

public int compare(Object obj1, Object obj2):
 
Tim Moores
Saloon Keeper
Posts: 7165
165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's no point fixing anything more advanced if you can't even get import statements working. Start with that, and post the code once you're done.
 
John Ken
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have been struggling a lot to make it work but it's not working what can i do now?
 
Tim Moores
Saloon Keeper
Posts: 7165
165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:Do you know what an "import" is in Java? If not, work through the relevant section of Oracle's Java tutorial first. After that: how would you use an import to let the Java compiler know that your code wants to use some class, for example 'Comparator"? If you have worked through the tutorial, you would know this, and be able to change your code accordingly.


And don't tell us that you can't find that section of the Oracle Java Tutorial.
 
John Ken
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes oracle java tutorial is a huge website  i really don't know where to check this particular information over there,can you please help ?
 
Tim Moores
Saloon Keeper
Posts: 7165
165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're unable to find a specific chapter on a web site (which does have a search facility), then I can't help you.
 
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's been a while since we've seen you code and I suspect it's changed a lot.  Can you show us your current code?

As for finding stuff in the Oracle Java tutorial, try googling how to use import statements in java.
 
John Ken
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you showed as a oracle java tutorial is just a google search page that i already checked and tried to solve my problem but could not solve it.
here is my code:-

 
John Ken
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
actually it's changed as i kept on referring many examples matching my problem so it's changed a lot what i posted earlier but still problem remains unresollved yet.
 
Knute Snortum
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's slow down a bit and just work with the code you posted.  The first error I see is that the compiler can't find the Employee type.  Look how you've declared the Employee class.  Can you see what's wrong?
 
John Ken
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think name of array list sorting should be 'Employee'?
 
John Ken
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
or may be  i should put Public in front of Employee class?
 
Saloon Keeper
Posts: 8738
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Case matters. Where braces are located matters. Without those, your code won't compile.
 
Carey Brown
Saloon Keeper
Posts: 8738
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's your code with indentation improved, maybe this will give you half a clue.
 
John Ken
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
experts still it has errors which i am unable to think how could i resolve them :-

i get below compilation errors with  this recent code now as followings:-

F:\Java Training\Java Programs>javac ArrayListSorting.java
ArrayListSorting.java:34: error: ';' expected
       Class Employee implements Comparator<Employee>
                     ^
ArrayListSorting.java:34: error: not a statement
       Class Employee implements Comparator<Employee>
                                           ^
ArrayListSorting.java:34: error: ';' expected
       Class Employee implements Comparator<Employee>
                                                     ^
ArrayListSorting.java:44: error: reached end of file while parsing
}
^
4 errors

F:\Java Training\Java Programs>

 
Master Rancher
Posts: 4052
56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's often a good idea to simply focus on the first error, and ignore the rest.  Later errors may or may not simply be caused by the first error; it's usually not worth spending time on later errors until the first error is fixed.

In this case, what's your first error?



Now, it says it expected a ';' - that's misleading in this case; it's just confused about what you're trying to do on this line.  But, take a close look at this line.  How does it compare to other class declarations which have worked correctly?  What's different?  Pay attention to small details early on in the line...

 
John Ken
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok,i am focussing on this line,but what is wrong with this line?
 
Knute Snortum
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remember that Java is case sensitive.
 
Campbell Ritchie
Marshal
Posts: 74351
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you remember what the 51 Java® keywords are?
 
John Ken
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, that i know but here i tried various combinations Implements,implements,Employee,employee,Comparator,comparator but all failed:-
F:\Java Training\Java Programs>javac Employee.java
Employee.java:35: error: illegal start of expression
public Class Employee implements comparator<Employee>
^
Employee.java:35: error: ';' expected
public Class Employee implements comparator<Employee>
                    ^
Employee.java:35: error: <identifier> expected
public Class Employee implements comparator<Employee>
                                                    ^
3 errors

F:\Java Training\Java Programs>javac Employee.java
Employee.java:35: error: illegal start of expression
public Class Employee Implements Comparator<Employee>
^
Employee.java:35: error: ';' expected
public Class Employee Implements Comparator<Employee>
                    ^
Employee.java:35: error: ';' expected
public Class Employee Implements Comparator<Employee>
                                          ^
Employee.java:36: error: illegal start of type
{
^
4 errors

F:\Java Training\Java Programs>javac Employee.java
Employee.java:35: error: illegal start of expression
public Class employee Implements Comparator<Employee>
^
Employee.java:35: error: ';' expected
public Class employee Implements Comparator<Employee>
                    ^
Employee.java:35: error: ';' expected
public Class employee Implements Comparator<Employee>
                                          ^
Employee.java:36: error: illegal start of type
{
^
4 errors

F:\Java Training\Java Programs>
 
Carey Brown
Saloon Keeper
Posts: 8738
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
 
John Ken
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
tried correcting even class-Class-class all variations almost tried still failin:-

F:\Java Training\Java Programs>javac Employee.java
Employee.java:35: error: illegal start of expression
public class Employee implements Comparator<Employee>
^
Employee.java:38: error: 'var' is not allowed here
var filteredAndSorted = employees.stream()
^
Employee.java:47: error: illegal start of type
       return employeeList;
       ^
Employee.java:47: error: <identifier> expected
       return employeeList;
                          ^
4 errors

F:\Java Training\Java Programs>javac Employee.java
Employee.java:38: error: 'var' is not allowed here
var filteredAndSorted = employees.stream()
^
Employee.java:47: error: illegal start of type
       return employeeList;
       ^
Employee.java:47: error: <identifier> expected
       return employeeList;
                          ^
Employee.java:50: error: reached end of file while parsing
}
^
4 errors

F:\Java Training\Java Programs>

 
Campbell Ritchie
Marshal
Posts: 74351
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you declaring a class on line 35? “Illegal start...” usually mean you have code  out of context where it shouldn't be.
 
Campbell Ritchie
Marshal
Posts: 74351
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Ken wrote:. . . i tried various combinations . .  .

That looks like guessing. You can guess 1000000× and some of the guesses will be correct, just from luck. Or you can think about what you are doing, and get it right first time.
Another thing: you have been posting code with apparently nice indentation, but it is hiding errors. Make sure to learn the rules for an indentation convention (you appear to be using Allman) and stick to those rules faithfully. Your class naming is also peculiar to say the least. I would never think that Employee would implement Comparator.
 
John Ken
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
then where shouuld it be declared?
 
Carey Brown
Saloon Keeper
Posts: 8738
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You've got two sets of error messages here, the second set indicates that you fixed the original problem. Now you have fewer problems and the next one to tackle is 'var'.

Could you please repost your code in its current state?
 
Campbell Ritchie
Marshal
Posts: 74351
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As you have written it, nowhere. The class you wrote looks incorrect to me.

Please go back to the original specification and work out where that class should be. Remember, as Tim H has told you, this is your work not ours.
 
John Ken
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Piet Souris wrote:But since this is a friendly place for everyone, I will answer Johns question, and then asking a question to John.

If you look at the code you have in your opening post, you see that you first create the List, and then do the filtering (and not yet sorting). Now, with my code snippet it is just the same: first create a List<Employee>, and when you have that List, you can invoke my code whenever you want: right after where you created the List, or later, if you need the filtering and sorting.

Now my question to you:
that code snippet of mine had the age of 22 built-in, just like that the sorting should take place on the basis of the name. That is not very flexible, to say the least. Now, can you implement this method:

And if you have that implemented, can you give an example of how to use this method?



I have been trying to fix your suggestion inside my code tried various cominations but so far have failed to merge it in my coe could you please help to merge it  in my code?
 
Campbell Ritchie
Marshal
Posts: 74351
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you go back to the beginning of this th‍read, you will find Piet did explain what was wrong. You were so near yet so far and in the meantime you have wandered randomly each step taking you farther from where you want to be.
 
John Ken
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but i am unable to merge piet's code in my code that is why i have been struggling and asking help for.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic