We help IT Professionals succeed at work.

How Do I Setup This Project?

BNLIND
BNLIND asked
on
I am trying to learn Java because I want to port a C# application to it so it will run on other platforms. I have Eclipse installed and I have used it to create a couple of basic classes from my C# app. What I really want to do is make the application modular by containing the application logic into its own project. Then, create new projects for the different types of front-ends (desktop gui, web-based, etc).

I guess my first question is: Am I thinking about this the right way? Should I make a "core" project, then separate projects for the different types of user interfaces?

Since my application connects to a database, I need to figure out how to work with databases from Java. I would like to have the core handle the database access stuff so that it is transparent to the user interfaces. I have already looked at EclipseLink, but have no idea how to use it or how to install it. None of the documentation or tutorials out there actually explain how to install it or how to use it. All they teach you is how to use annotations on classes, but that's only about 20% of it. You have to do so much other stuff to make this work that everyone just assumes everyone on the planet knows how to do.

So my second question is: How do I get my "core" to handle database access? I am using a PostgreSQL database currently, but I need to also make it work with other database engines/
Comment
Watch Question

I would recommend you to through some training on Java first.

As per your question,
1) your thinking is correct,
2) You can make separate projects for different interfaces, but as you will learn more about java, you will find that your project can be modularized even further

You need to learn about JDBC to communicate with database using Java

see these links to learn more
http://java.sun.com/docs/books/tutorial/jdbc/basics/index.html
http://java.sun.com/docs/books/tutorial/jdbc/index.html

Author

Commented:
It's good to know that I can modularize Java. this was a concern of mine. As for database access, I would really like to avoid using raw SQL. I did that dance with C# and ended up having to write a 2,000 line SQL code generator that could handle MSSQL, PostgreSQL, and MySQL. So JPA (or similar) is almost a requirement for my project since I need it to work cross-database.
for writing a database agnostic db access code you need to use some ORM package.

You can go for Hibernate (Hibernate Query language), or you can also try EQL (EJB Query language)\

But before moving towards these packages, get yourself well versed with Java/J2EE basics

Author

Commented:
Also, I have tried getting into some kind of a Java class, but there are no training centers within 100 miles of me that host Java classes. Everything is .NET, stuff I already know. And of course, I don't know any developers, much less Java developers, so I have no one to ask questions. Forums like these help, but can be frustrating when I can't find an answer.

Author

Commented:
gurvinder372: Can you recommend some resources in order to get well-versed in Java? The sun docs assume you are using Netbeans. I am using Eclipse, so that complicates things. I have also been unable to find many resources that walk you through the process. Everything I read goes straight from theory to guru code without explaining how to get to that point. I did find this tutorial a few months ago, which was actually pretty good, but very limited: http://eclipsetutorial.sourceforge.net/totalbeginner.html
Top Expert 2016

Commented:
>>I am trying to learn Java because I want to port a C# application to it so it will run on other platforms.

Have you already tried to build it as is for other platforms?

http://en.wikipedia.org/wiki/Mono_(software)

Author

Commented:
CEHJ:
To put it shortly, Mono will not handle p/invoke calls and it doesn't work too well on the Mac. If I ever had a problem with it on a different platform other than Windows, no one would be able to help me. Whereas if I have a problem with Java, practically every Java developer can help. As for p/invoke, Java already has the components I need for my app, so I don't need p/invoke.

Author

Commented:
All of the tutorials listed above deal with learning the language/syntax. Except for a couple of things, Java is EXACTLY like C#. It's working with libraries and frameworks that I need help with. Specifically, database stuff. I can port most of my code over from C# with no problem. Again, it's the complex stuff like database access is what I need help with.
Database connectivity you can achieve as follows ;

> Decide which db you want to use . viz MYSQL, MSSQL, ORACLE etc.

> You can search for JDBC driver (It is just a jar file) for that DB.

> Add the JDBC to your run time or you can directly paste the jar file into etc directory of JRE.

Simple implementation you can find at http://www.jdbc-tutorial.com/

Please do note that, you will need to change the class that has to be loaded depending on the kind of driver you are using, rest remains same
@BNLIND:
As I understand your problem; You want to port you application from C# to Java with taking care of platform and DB agnostic.

First let me tell you that, your path is right for the.

Solution Problem 1). creating project in Java using eclipse is very easy. you can just create different projects in eclipse. like
project A) for core, B) for GUI, C) for other calls etc and set dependencies for the same using eclipse build path. add dependent projects and libraries to the your project build path.

Solution problem 2). There are multiple option to solve this issue.
A). you can use Hibernate core,
B). You can use EJB3
C). You can use Hibernate with JPA

Note: you can use Jboss as application server.

Also you can go through this  link for reference:
http://www.javaworld.com/javaworld/jw-06-2008/jw-06-build-the-enterprise.html?page=1
http://openejb.apache.org/ejb3-sample-applications.html
http://www.graniteds.org/confluence/display/DOC/2.+Sample+Projects



Author

Commented:
The answers provided helped to solve the issue.