Java for back end coding

33 views
Skip to first unread message

Mohamed Turki

unread,
Dec 25, 2011, 10:45:15 AM12/25/11
to Google Web Toolkit
Hello everyone
I'm new to GWT but I have a modest experience with Java.
I never used Java for back end coding tho. I'm used to PHP and MySQL.
Can anybody here give me an idea on how to use Java for back end work,
like which libraries do I need and how things work.
Thanks a lot

Dennis Haupt

unread,
Dec 25, 2011, 1:08:51 PM12/25/11
to google-we...@googlegroups.com

there are about 3000 frameworks and applications servers to choose from.
you probably want to take a look at tomcat or jetty and hibernate. or
db4o, if you want to be a pirate.

--

-sowdri-

unread,
Dec 26, 2011, 1:35:31 AM12/26/11
to google-we...@googlegroups.com
GWT certainly is for people who know java.

>> I never used Java for back end coding tho.

If you are planning to learn Java through GWT, then I strongly recommend you to reconsider!

-sowdri-

divStar

unread,
Dec 26, 2011, 10:38:47 AM12/26/11
to Google Web Toolkit
Basically you COULD use php for backend - and instead of relying on
GWT-RPC, you could use a RequestFactory and push the objects around
using JSON or XML.
However I think it's a lot easier to develop backend services in Java,
because then you can manage you entire project within eclipse for
example and have your services implement given interfaces.

Request and implementation of those would go around like this:
- you think of methods you need for a given action
- you decide on services (e.g. I have things for recipes and items,
so I have two services: RecipeService and ItemService)
- you decide on the methods you need (e.g. getRecipes(int from, int
amount) and other methods, each in their own Service)
- you create your interfaces (you need e.g. IRecipeService and
IRecipeServiceAsync - there are lots of tutorials how to write/adjust
them)
- you should make your backend service implementations
(RecipseServiceImpl) extend RemoteServiceServlet and implement the
interface you just created (IRecipeService)

Then in your class where you want to be able to make this call, you go
on like this:
private final IBelongingsServiceAsync belongingsRPC =
(IBelongingsServiceAsync) GWT.create(IBelongingsService.class);

Now you can use belongingsRPC.getItemsOnCharacter(...) (that's just an
example) to get certain items. In my example getItemsOnCharacter is a
method declared within the interface and implemented in my backend.

Generally I wouldn't start learning Java by learning GWT, since GWT
does not support everything Java does and some things may work
differently when using Java.

Therefore - especially if you're familiar with php - you might want to
look at how to use RequestFactories and php for backend. It's imo a
bit harder (for instance when I tried it (must'Ve been around GWT 1.5
or so) it didn't work out for me, because I didn't know where to put
things) in my opinion.

If you still want to use Java for backend, I'd recommend to make it so
you can publish onto a tomcat-server, not the built-in jetty server. I
had a lot of trouble publishing the project outside of jetty. That's
why I decided to rework my project - and I am now developing on tomcat
(you can even pick that tomcat that comes with XAMPP if you're on
Windows).

As to the library question: it depends on whether you need
functionality that is not present in Java right-away. Basically the
only thing you need is the JDK (1.6 currently) - and when you publish
your application (including server-side), your server only needs to
have the corresponding JRE6. If you happen to use any additional
libraries (e.g. I use JDOM for XML-stuff), then you have to copy
the .jar-file into your "war/WEB-INF/lib"-folder and include it in
your build-path. There's also a library for handling mysql-stuff (it's
a mysql-connector and you can get it for free from Oracle).
Usually if you have a bigger application, then it makes sense to use
frameworks such as hibernate and/or spring (we use both at work,
because our application is really huge). These frameworks usually
automate things or make it easier to work with databases. Spring-
security for example also helps covering most vulnerabilities
automatically, so you don't have to keep track of it on your own.

However: I really recommend you start with the basics. It's a bad sign
if something seems to you rather automagical and you don't know what's
going on under the hood. This can make debugging (especially if
strange exceptions occur) a pain.

I hope it helps.

Igor.

Mohamed Turki

unread,
Dec 26, 2011, 1:15:37 PM12/26/11
to Google Web Toolkit
Thanks everyone for your responses. I just thought maybe I should give
you more information so the responses can be more concrete.
My goal is to create a sort of forge where students here (in Tunisia)
can start and collaborate in open source projects (just hoping
students will be more motivated to work outside of the class) and at
the same time I can familiarize myself with Java and GWT.

I would like to see an example of how to fetch data from a database
using Java or taking input from GWT forms and storing them in a
database? Should I learn Java Enterprise Edition before diving into
this?
I'm getting a bit lost here
Reply all
Reply to author
Forward
0 new messages