Need help on learning java frameworks quickly - java

I wrote a piece of java code using threads, JDBC, Java Mail API etc. without using any of the frameworks (read Spring). I am frankly not too comfortable learning them first (lots of terminologies to remember!) and use them. So, please suggest me some ways to refine my existing code incorporating few of these framework concepts applicable to the aforementioned things without having to learn a lot about them. Is there any quick way to learn some vital framework concepts and use it.. sounds certainly foolish, but still looking for somebody's experiences :)

If you aren't interested in frameworks, your code should at least use interfaces and layering that's appropriate. Your app will be well-layered if you have interfaces for services and repositories whether you use a framework or not.
You should have a front controller servlet that accepts all requests.
You should bind and validate all requests prior to processing in the service tier.
The services should be completely separate from your web tier. If you can't unbolt the web UI and have the rest of the stuff work, you're doing it wrong.

for your simple stuff i dont really see a value add of using framework. u could replace the thread handling with the Java 5 Executors though. And if you want IoC/dependency injection then look into Google Guice

I am not one of those people that can read a book and understand (although, I certainly wish I was that type). I have to learn by doing so I suggest installing an IDE that supports the framework you want to learn and do the tutorials or build something that you can use personally. Couple that with some books/internet for reference and guidance. Good luck!

Related

Can you write a web application with just the Java programming language?

My end-of-term assignment is to build a web-based student management application which connects to a MySQL database. However, the teacher does not allow us to use JS/ node because he says it is not OOP. Besides from JS, the members in our group can only use Java.
Therefore, I want to ask if it's it possible to do this assignment with just Java. If it is, what are the things I need to know and learn? Else, is it possible to learn PHP in 1 month for this kind of project?
Thank you very much for reading!
Yes it is possible to write a webserver in Java without any external (i.e. not Java SE) libraries. All you need to do is:
Learn about Socket and ServerSocket and the SSL stack, and ...
Spend a few days reading the HTTP specification in sufficient detail to understand what the protocol requires.
Spend a few more days implementing a server-side HTTP protocol stack and so on.
Which is ... a lot of effort, and probably a waste of you / your team's time.
If you are going to implement this in Java, you would be much better off either learning Spring / SpringMVC / SpringBoot, or learning Servlets and/or JSPs. They deal with the protocol side for you, and (more or less) leave you to focus on the aspects that are specific to your webapp.
These technologies (or equivalents) are what you are likely to use when you graduate.
If the other members of your team already know Java, that would be an obvious good reason to use it.
In short, there are 3 reasons to use Java + the above technologies:
Less effort
Less learning for your other team members1
You / they will be learning more immediately useful things.
PHP would be another alternative, though if your teachers are "down" on Javascript for being "not OO enough", they are probably unlikely to think well of PHP either.
On the topic of whether Javascript is OO or not, read this:
Is JavaScript object-oriented?
Read it and make up your own mind.
1 - How about volunteering to write all of the project's documentation so that you don't have to learn Java. No? You want to learn Java, don't you!
Sure you can write a web app in Java. Depending on what you're allowed to use there are tons of options. Just a short overview, further down means you need more 3rd party code but productivity goes up:
Build in on the JDK only. You'll need to build the WebServer on your own and compose HTML... (Only do this if requirements are strictly forbidding 3rd party libraries)
Use a servlet container like tomcat. You'll still have to build HTML on your own but request handling is mostly done for you. (Use this if a servlet container is all you're allowed to use)
Use a templating engine like JSP, Thymeleafe, Velocity. You will be able to build web pages quite easily. (This would already work conveniently, yet there are still better options)
Use an web application framework. This will take most boilerplate from you and allow you to use advanced concepts with little effort. There are multiple frameworks to choose from. I prefer Spring Boot and would recommend to start with s.th. like this (This will automatically provide much of what is asked from you, so check if you can use such a framework).

When to use a web framework?

we need to code an online web journal management system in Java. It's not an Amazon, but also more than a Hello World.
Should we use a framework? If yes, why? What are some good Java Web frameworks out there that are simple?
Yes.
A Web framework should be used for all applications which are more complex than "Hello, World!". There's no need to reinvent the wheel. Web frameworks contain many useful tested components which you will almost certainly need on your site. They also help organize your code, often into an MVC or similar paradigm, which will make your code more maintainable.
Some Java Web Frameworks (in no particular order):
JavaServer Faces
Grails
Struts
Tapestry
Spring MVC
Apache Wicket
Play Framework
Stripes
Start developing without any framework and you will definitely notice yourself if you need one or not. Once more than half of your code is infrastructure for your web components, this can be a clue you should have chosen a framework rather than develop one yourself.
As a better example, use System.out.println() for logging, enhance that with some specialised package that also provides functionality like writing to a file, then add formatting to log messages and when you realise you spent half a year to develop your own poor home-made version of log4j (or whatever), someone will complain and say you should have chosen a logging framework from the very beginning and spend one or two weeks to learn how to use it.
Don't get me wrong, sometimes a mere System.out.println() wrapper is enough and a framework only adds overhead. Unfortunately, that scenario is a rarity these days...
EDIT: I am (or used to be) an anti-framework type of developer at the core so I've learned all the above "the hard way".
For a web framework suggestion: Apache Wicket
You should use a framework when you want to create something real and spend most of your time solving the problem at hand and not dealing with the underlying technology so much (e.g peristence, templating, infrastructure etc).
A good all around framework which provides tons of integration with other frameworks is Spring Framework.
A simple web framework is the play framework. Watch the screen cast on the playframework.org homepage. I am sure you will be convinced.
As #cherouvim mentioned, it's worth using a framework if you anticipate the need for "commodity technologies" like persistence, templating, routing, etc. That is, if you think your website will require non-trivial use of a database or complicated layouts and views (which are almost always present in a web application).
Check out Grails, it's based on the Spring framework but far easier to learn, manage, and use, in my opinion. Plus it's comparable to Ruby on Rails, which is another popular web application framework worth considering.

Python web frameworks vs Java web frameworks (how is web development in Python done?)

I am thinking in starting a personal pet web project to experiment with different things and extend my knowledge.
I use Java a lot at work (for web applications :D) and was thinking in making my own in Python since I kinda like this language but never passed the simple scripts stages.
I want to step up a gear regarding Python (using 2.6.5) and don't know what to expect or what framework to choose from: Django, Pylons, web2py etc.
I also don't know how much these frameworks will offer me and how much will I have to write from scratch.
I could use a comparison with Java if somebody can provide me with. I'm thinking at filter functionalities such as sitemesh, custom tags like JSTL; In Python, can I write clean pages of HTML with tags in them or write a lot of print statements (something like servlets did in Java etc?
I don't know exactly how to phrase this question.
I actually need a presentation of how web development is performed in Python, at what level, and what the web frameworks bring to the table.
Can you share from your experience?
TIA!
hi try bottle python framework (bottle.paws.de / bottlepy.org) its really nice to use blistering fast and gets out of your way + the best thing about it is that its one single file to import, i recently migrated from PHP and i have to tell you am so ... loving it!
Python web frameworks run the full gamut of capabilities/facilities, all the way from shims around WSGI such as Bottle and Flask, all the way to full frameworks such as Django and TurboGears, and even "megaframeworks" such as Zope. Each does things slightly differently, but there will be some familiarity from one to the next.
It may sound strange, but there's no need to know "how web development is performed in Python" to start doing it.
In fact, working with language/framework/etc is a single most reliable way to get understanding of it. You won't gain a lot from one-page summaries.
Also, comparing it with Java isn't likely to help. There's no point in doing "Java-style development in Python". If you want to benefit, you'll need to clear your mind and do everything "Python-way".
As to what Python framework to choose, Django seems like like a good starting point. It's very popular, which means you won't be left without tutorials/documentation/help.
PS Short version: just do it.
Python web frameworks do it in a similar way as some Java-based frameworks. I can speak for Django here.
A good comparison could be Play! vs. Django. Both of them foster using an MVC architecture (or MTV = models, templates, views) and already provide you with a lot of things like CRUD operations in admin pages, ORM, authentication, URL configurations, a template language and much more.
Other Java-based frameworks might differ a lot, and I can't give you a general answer. Depending on the choice, there are only few differences. You can simply choose the language and framework you like the most. I'd recommend to go through some tutorials (Django tutorial, Play! framework tutorial for instance) and look which one works best for your needs.

Is Spring the right choice for me?

I want to start developing a little web-based game, and would appreciate some advice before I get into it. Hopefully this is the place to ask!
The game is basically a fantasy-football style game, where you create a team of players which compete against other users. Nothing fancy.
I haven't coded much since college, and am very rusty. I want to code in Java for a couple of reasons:
It is the language I am most familiar with.
What limited development work I have done since college has been in Java (I have some novice-level experience with Tomcat and Glassfish, i.e. I have got them running and deployed basic webapps I've coded from scratch to them).
I really like what I have seen of the GWT framework so I would like to develop my GUI with that.
The last time I did any programming was about 3 years ago when I wrote a web front-end for a crappy helpdesk system that only had a thick client and a web API. That was done in Java.
So basically, first up, I want to get a skeleton game up and running. Basically allow a user to log in, see their team, log out. So my questions start with:
Is there a particular development framework I should be reading up on? I've seen Spring recommended - is this a good choice? I've found this to get me started if it is the appropriate choice: http://static.springsource.org/docs/Spring-MVC-step-by-step/
What is the easiest way for me to handle login/authentication/authorisation without having to write a security system myself? Hopefully there is some kind of framework/library I can just drop in to the code? Or does Spring Security handle that?
I really like GWT - are there difficulties integrating that with Spring?
Many thanks for your time, I really appreciate it!
Spring is a good choice.
Check out the Spring security module. It's based on aspect-oriented programming ideas.
Looks like Spring does support GWT. It's relatively new (May 2010).
If you're rusty with Java, you might want to minimize the new technologies you introduce at one time.
Java's an object oriented language, so you can write the objects you need to model your game and get them running without any UI or database at all. That would allow you to focus on the game, the objects, and the use cases without getting wrapped around the axle with UI, security, persistence, etc.
Once you have that sorted out and fully tested you can turn your attention to the other features: persistence, UI, security, etc.
Maybe you can try basic authentication/authorization before you dive into Spring Security.
If you bite off too much at once you'll never get this done. Take small steps.
Spring is the par exellance example of what the cool kids don't like about Java. Many, many configuration files that make every aspect of the app customisable but is difficult to keep in your head where stuff belongs. If you are not a huge company this is almost certainly not what you need.
I would encourage you to look into the Play or Wicket framworks if you want to keep using Java. Both are conceptually simpler, don't throw in the kitchen sink and are heavily geared towards web sites. Spring MVC is just a part of the very large Spring ecosystem.
For the Inversion of Control (Dependency Injection) paradigm that Spring often is associated with, I find Guice way more awesome.

want to make web site using Java, should i implement struts?

I want to make discussion form kind of website using java, should i just make it using JSP- Servlet - Java code or should i use some framework like struts ...
I am new to Java, but i have sufficient exposure of programming
Depends what you're trying to achieve.
As far as frameworks go I would recommend checking out Spring over Struts (Although they can be used together, Spring has an equivalent Spring-MVC).
But Spring might be a bit involved for a Java newbie, even if you do have other language experience. Maybe experiment with JSPs/servlet first and check out Spring once you're comfortable with them (I recommend Spring in Action for reading material)
... Also, if we're talking a bit more outside the box (I see someone else mentioned Scala/Lift), another alternative would be Groovy on Grails. This is based on Spring, and owned by SpringSource, but is much more fun/quick to develop with. Plus if your previous experience happens to be with dynamic langs such as Python/Ruby, Groovy would be worth checking out.
You can try Play framework too. I have watched their demo and it's programming model looks promising to me.
If you're going to use Struts then make sure to use Struts 2. I would not recommend anyone write a new app in Struts 1 as it is very verbose and requires lots of configuration. However, Struts 2 is pretty awesome. I wrote a tutorial on it if that's the route you'd like to go.
You should have a basic understanding of servlet API, but you will most probably prefer to use some web framework built upon it. Struts is just one of them, popular and simple though a little old; there are many others
To name some: Struts, Spring-MVC, Stripes, Struts2, Wicket, JSF, Tapestry, GWT... an many others.
(Struts2 is not a new version of Struts, it's rather a new version of Webworks).
Unfortunately none of them is a clear winner.
You might consider Scala with Lift. I am building my next site in this and it is a very promising, light weight, less verbose, Java language.
You WILL need to understand servlets and what you can do with them regardless what, as all modern Java-based web platforms build on top of that.
The Sun tutorial for servlets is at http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets.html
If you're asking whether to use a framework at all or just use plain JSP-Servlet-Java I'd say that as long as you have a grasp of the language and Servlet API as other have said, the extra effort to learn a framework on top of that is well worth it in the long run. If you don't use a framework you eventually find that either a lot of your code becomes tedious, repetitive 'plumbing' or that you've essentially created your own framework anyway. Creating frameworks can be fun but if you have a job to do with a deadline, using an existing one saves a huge amount of time and effort.

Categories

Resources