Stefan Evans

+ Follow
since Jul 06, 2005
Merit badge: grant badges
For More
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 Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Stefan Evans

Don't know if you are still encountering this problem, but have you looked at using LogBack?
They seem to have a solution for this: covers this exact use case.

5 years ago
A little late to the party, but just to put another opinion here, and point out a flaw.

You have written your method in a synchronous manner, but are making an asynchronous call to the API.

Is there any reason you have to make this call asynchronously (call.enqueue) vs synchronously(call.execute)?  Something like this (untested, but following the API at

If you want to make an asynchronous call then you are going to have to change the getProductById method not to return the value directly...
Congratulations indeed.

But is it sad that I only recognise one maybe two other names on that list?
6 years ago
I would take another look at the instructions in the comment.

What you have is five different methods, all very similar to one another

public static SchoolTextBook [] sortTextBooksByAuthor(SchoolTextBook [] textBookArray)
public static SchoolTextBook [] sortTextBooksByTitle(SchoolTextBook [] textBookArray)
public static SchoolTextBook [] sortTextBooksByIsbn(SchoolTextBook [] textBookArray)
public static SchoolTextBook [] sortTextBooksByPageCount(SchoolTextBook [] textBookArray)
public static SchoolTextBook [] sortTextBooksByPrice(SchoolTextBook [] textBookArray)

The only difference between these methods is the if statement you use to compare the two items.

Can you write one method that looks like this:
public static SchoolTextBook [] sortTextBooks(SchoolTextBook [] textBookArray, String sortProperty)
The difference is that you don't have the same code repeated 5 times with subtle variations.
It is more efficient in the amount of code you write if nothing else :-)

You could probably write a helper method:
boolean bookIsGreaterThanAnother(SchoolTextBook book1, SchoolTextBook book2, String property)
book1 and book2 are the books to compare
property is the property of the bean to use to compare
returns true if book1 is "greater than" book2, otherwise false.

You could then replace the if statement with that method.

One thing I have noted is your method signature could be

You are actually editing the textBookArray in place, and don't need to return it explicitly.
This makes it clearer to anybody looking at it.  Otherwise they might assume that it returns a "sorted" array while leaving the original unsorted.

In terms of efficiency, you could look at your algorithm for sorting.  You have used the "Bubble Sort" algorithm here.
It is not a very efficient algorithm for sorting.  You might research other possible search algorithms (google and wikipedia will be of great help here and will explain it better than I ever could)
6 years ago
I merged your stuff with the following thread. I hope that is okay by you.
6 years ago
@Ioanna - you seem to have grasped the concept :-)

This is the sort of question that I really hate in these exams.
Contriving a confusing example which no programmer worth their salt would ever conceive of in 'real' code, and expecting you to interpret it 'correctly'
This is why we have naming conventions/standards.

For clarity you wanted to re-write it so that T represented the Generic type and B represented the class (and thus avoid the confusing name collision), I believe the result should be:

EDIT: You have to cast the new B() to type T to get it to compile.
6 years ago
"Source not found" probably mean you haven't got the file in the right place.

Instead of trying to guess where it should go, get the program to tell you.
If you have a File object, then you can use the getAbsolutePath() method to tell you exactly where java will go looking for this file.
If it is Eclipse, the file will probably be relative to your Eclipse project.

But I am just guessing here - as Paul said it would be helpful if you showed us what code you have, what file you are looking for, and explicitly what exception is thrown
6 years ago
The Url is made up of three parts
#1 - The Tomcat Server - http://localhost:8080
#2 - Your web application context - defaults to the folder you created under webapps - ch1
#3 - The resource within your web application you want to call - the url-pattern you have used in the web.xml:  Serv1

You were trying:  http://localhost:8080/ch1/Serv
Try adding the '1' on the end of that to match exactly what you have in your web.xml file
6 years ago
Do you know the valid date format(s) that you will be receiving in the XML?
At some point you need to convert from a String into a Date.

You can do this in the JAXB layer, or with the BeanUtils specifying date formats for the converter.
The important segment:

Example test code below:

6 years ago
Not really very clear code.
From the TODO comments, I guess that the individual entries in the two-dimensional array are blood donors - representing how much people have donated.
The first index represents the state (in the US ? )
The second index the number of the donor in each state?

Purely from reading :

public int findTopDonor() {
/*** TODO: Read each value in donations, noting the index of the maximum
             (maybe keep a counter to know how many donors have come before it)

 public int findTopState() {
   /*** TODO: Sum all values in a row of donations, noting the row of the maximum
              Return the maximum row ***/

Anyways, the first thing is to re-read the questions and make sure you are returning what they want.

Find Top Donor - you are not keeping track of the maximum amount seen so far anywhere.  I would suggest

Find top state.  They want the index in the array which has the highest sum.
Not the actual sum...
I would suggest printing out the value of rowSum after each "row" is completed, and then checking to see if it matches what you calculate.

One final  suggestion - for testing purposes change the line at the top:
Random r = new Random();
Make it
Random r = new Random(1);
Just remember to change it back before you submit the assignment :-)

That change means you will get the same "random" numbers every time which makes it easier to debug your program
6 years ago
Also keep in mind what your URL to each state / game will look like.
Crawlers work better with unique URLs rather than having the same URL with different parameters.

6 years ago
I don't see anything overtly wrong here.

"when adding an item to an ArrayList i keep adding only the memory location into the List not the actual item with id"

Why do you think this?
What proof do you have?
hint:  check out the default implementation of toString() for an object...
6 years ago
I have a few suggestions.  I've tried to separate them out.  
Implement one or all of them within your constraints.

First thing.

You have written this whole thing using <% scriptlet tags %>.
Scriptlet tags are bad ok?

Lets introduce you to the JSP Expression tag.  <%= expression %>
The expression tag effectively does an out.print of the expression you place between the tags.

Rather than write:

It would be preferable to have

There.  We've gotten rid of a whole lot of unnecessary boilerplate code.


The other thing I don't like is your continued use of carports[i].
At the least, declare a local variable for it and assign it at the start of your loop:


However we can even do better than that using JSTL and EL

It isn't exactly the same because we need an instance of the userServlet rather than what looks like a static import, but that is the way I would want it to look.

Ideally then we could use an EL expression rather than a scriptlet expression
That would look something like:

By using these tools, you can get rid of practically every scriptlet on your page.

Rather than putting the customerId into an input type="hidden" populated from the session, remove that field from the form, and in your servlet retrieve it from the session directly.
int customerID = Integer.parseInt(session.getAttribute("customerID"));

I don't know what customerID is.  If it is an Integer already in the session, then you don't need to parse it.

hope this helps,

7 years ago
What should you learn first? As always the answer is "it depends"

If you are more interested in the java programming side of things, then I would suggest catching up with the changes in the java language since you last touched it.  
New Features & APIs etc.
I would also recommend you get acquainted with Spring and Spring boot.  which have some quick start modules and examples.

JDBC is still there.
But must of the time I want to talk to a database I use an ORM tool like Hibernate to abstract away the JDBC code.
And Spring provides a nifty feature such that you annotate your bean, write an interface that extends a and you're done.
You don't actually end up writing any jdbc code at all.

If you are interested in the web side of things, then brush up your javascript (not the same as java)
And then check out a framework such as Angular or React.

In terms of this project, you could actually do both, which might also help you on the way to understanding how web applications have evolved.

#1 - Write back end java classes to load/save your data from your database.  (spring boot data module)
#2 - Build a JSP/Servlet Web application with a form that lets you interact with the back end java code.  (Spring MVC)
#3 - Write a REST web service that exposes the back end java code (spring-boot)
#4 - Build a "Single page app" in javascript that does exactly the same as your JSP web application, just without JSP.  (angular/react)

The bits provided in brackets are suggestions only to help 'automate' the work.

But personally I would  be more impressed by a demo that utilized the frameworks out in the real world rather than having custom written java code behind them.

7 years ago