Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!

James Dekker

Ranch Hand
+ Follow
since Dec 09, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
5
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by James Dekker

Am working on a coding exercise which I am somewhat confused on how to implement a solution.

According to the JavaDoc, I have to implement this EmployeeManager interface. Presume that employee data arrives in a separate thread from other requests. Note that getSalary() execute in constant time O(n). Execution time must not vary with number of employees or departments.



Question(s):

1. What type of problem is this?

2. Should I create Employee and Department classes as POJOs and what would be inside? Will they have to implement runnable in order to be thread-safe?

3. What type of data structure(s) does this need?

Am really rusty with my data structures and CS stuff so would greatly appreciate any feedback.
1 year ago
Am using the latest version of Spring Boot to read in a sample JSON via Restful Web Service...

Here's my pom.xml:




Here's my web service code:

When I invoke it using the following command:


I get this error message:



The only thing I am trying to do is pass in some valid JSON (as a string via curl) and to see if the String payload enters the process method as {"name":"value"}

What am I possibly doing wrong?

Thank you for taking the time to read this...
3 years ago
Am new to JPA...

I have the following preexisting tables inside a MySQL 5 database:

App
User
User_App_Bridge

The relationship(s) are mapped to the User_App_Bridge table (as the name implies, a bridge) amongst App and User as a One to Many cardinality.

The E-R diagram:

User ------ User_App_Bridge------ App

1 User is associated with many apps inside the User_App_Bridge table.

1 App is associated with many users inside the User_App_Bridge table.

The DDL for the User_App_Bridge table:



Lets say that I have the following JPA Annotated Classes which are mapped to these tables:




Question(s):

(1) Is this (the block inside the @JoinTable) the correct way to do the one to many mapping for User and App entites with the UserAppBridge?

(2) Inside the @JoinTable should the column & referencedColumnName be assigned to the SQL value (e.g. name="User_Id" , referencedColumnName = "User_Id")
or should it be the Java reference name (e.g. name="userId" , referencedColumnName = "userId")?

(3) Inside the inverseJoinColumns code black, is the unique = true necessary (what is it for)?

(4) Do I need to do anything else inside the UserAppBridge class (for connecting to App and User)?

Thank you for taking the time to read this...
This is how the coding puzzle came... I am supposed to provide implementation in the Field's enums?
3 years ago
What Field is an enum... Am new to this and the interface predefined getField() method.
3 years ago
Lets say you have a particular enum called Field:


And you have a corresponding Java interface called Music


And you implement it like this:

Does this sound correct?


Is this a correct way to implement the sortAlbums method?
3 years ago
Lets say you have a particular enum called Field:


And another enum called:


And you have a corresponding Java interface called Music


Which the implementation looks liks this:


How would you use this API to implement the following two methods?



Any suggestions will help...
3 years ago
Am using Hibernate 3 / JPA on Java 6. Am trying to fetch a simple row from the database (which is populated).

Created the following JPA Annotated Domain Object:



My hibernate.cfg.xml file:



Code snippet from calling class:



When I run the calling class, this is the exception I get:



Line 15 where this ClassCastException occurs is here:



Here are my dependencies:



What I am I possibly doing wrong? I just want to call a simple select query against a person table.

What is the most simplest way to do a select query for one row of my Person table in Hibernate / JPA?

I am using session factory instead of entity manager.

Thank you for taking the time to read this.
Am using JDK 1.6, tomcat 7.0.32, and Red Hat Linux.

I need help setting up SSL on my local tomcat instance.

After looking at the instructions on the official tomcat 7 website:

http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html

I followed the directions like this:

(1) cd $CATALINA_HOME/conf

(2) Create a certificate and store it in a new key store.



(3) Uncomment the SSL connector configuration in Tomcat's conf/server.xml, specifying your key store file and password.



(4) Export the certificate from the key store.



When I tried to (which would have been Step # 5) import the certificate into the trust store.



I get the following prompt for my password (after which I entered in "mypassword"):
Enter keystore password:



(I disregarded this step by the way because I found it on Google but not on the official Tomcat7-SSL-Howto documentation - please let me know if its necessary).

My full server.xml file (located under $CATALINA_HOME/conf):


Tomcat's server output:



When I go to my bash shell and type this in:



I get the following error output:



Am I missing a step here?

I just want to enable SSL on Tomcat 7 and test it using curl.

Would appreciate it if someone could point me in the right direction.

Thanks for taking the time to read this.
5 years ago
Praful,

It still didn't work on Linux... Thank you for your help, nonetheless.

-James
5 years ago
Using Java 6, Tomcat 7, Jersey 1.15, Jackson 2.0.6 (from FasterXml maven repo), & Google GSON 2.2.2,
I am trying to pretty print the JSON String so it will look indented by the curl -X GET command line.

I created a simple web service which has the following architecture:

My POJOs (model classes):





Using a Utility Class, I decided to hard code the POJOs as follows:



My web service:



When I run this using:



I get this in my Eclipse's console (which is exactly what I want):



But from the command line curl command listed above, I get this
(there are 4 spaces after \n but JavaRanch's forum doesn't show it):


"{\n \"father\": \"Joe\",\n \"mother\": \"Jennifer\",\n \"children\": [\n {\n \"name\": \"Jimmy\",\n \"age\": \"12\",\n \"gender\": \"male\"\n }\n ]\n}"


How can I make the JSON formatting to be identical to what I am getting in Eclipse's console by using the curl command?

This is similar to my other two posts, located using Jackson and Using json.org/java. The only reason I am posting using all 3 parsers is because I want to help other people with similar problems who are using a specific JSON library of choice, in the future.

Thanks for taking the time to read this...
5 years ago
Using Java 6, Tomcat 7, Jersey 1.15, Jackson 2.0.6 (from FasterXml maven repo), & www.json.org parser, I am trying to
pretty print the JSON String so it will look indented by the curl -X GET command line.

I created a simple web service which has the following architecture:

My POJOs (model classes):





Using a Utility Class, I decided to hard code the POJOs as follows:



My web service:



When I run this using:



I get this in my Eclipse's console:

{"father":"Joe","mother":"Jennifer","children":[{"name":"Jimmy","age":"12","gender":"male"}]}

But from the curl command on the command line (this response is more important):

"{\n \"mother\": \"Jennifer\",\n \"children\": [{\n \"age\": \"12\",\n \"name\": \"Jimmy\",\n \"gender\": \"male\"\n }],\n \"father\": \"Joe\"\n}"

This is similar to the response I was getting just using plain old Jackson, see this post.

Would appreciate it if someone could point me in the right direction.
5 years ago
Praful,

Thanks for the response!

When I tried this:



Using the curl command in Linux (this is my actual web service client):



This is the response I got:

{"children":[{"age":"12","gender":"male","name":"Jimmy"}],"father":"Joe","mother":"Jennifer"}

Doesn't seem like anything happened...

Here are the dependencies listed in my pom.xml file:



Does anyone know what I am possibly doing wrong?
5 years ago
Thanks Steve,

Yes, I was able to get it working by doing this:



Thanks for your great input / feedback!

James
5 years ago
Using Java 6, Tomcat 7, Jersey 1.15, Jackson 1.9.9, created a simple web service which has the following architecture:

My POJOs (model classes):





Using a Utility Class, I decided to hard code the POJOs as follows:



MyWebService:



Produces:


What I need to do is have it produce it in a more legible manner:



Just am seeking a way to implement so it can display some type of formatting with indentation / tabs.

Would be very grateful if someone could assist me.

Thank you for taking the time to read this.
5 years ago