As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
This might be a really trivial question, but I've been writing Java programs at my school and I just found out that I can create websites with Java as well.
How can I do that? Any good books/tutorials for that?
Which is better for Web development, Java or PHP?
Also, when using PHP, MySQL comes into picture and while writing Java programs for desktop, we just use File I/O, so what is better for web dev, File I/O or MySQL?
You are asking a few different questions...
How can I create websites with Java?
The simplest way to start making websites with Java is to use JSP. JSP stands for Java Server Pages, and it allows you to embed HTML in Java code files for dynamic page creation. In order to compile and serve JSPs, you will need a Servlet Container, which is basically a web server that runs Java classes. The most popular basic Servlet Container is called Tomcat, and it's provided free by The Apache Software Foundation. Follow the tutorial that cletus provided here.
Once you have Tomcat up and running, and have a basic understanding of how to deploy JSPs, you'll probably want to start creating your own JSPs. I always like IBM developerWorks tutorials. They have a JSP tutorial here that looks alright (though a bit dated).
You'll find out that there is a lot more to Java web development than JSPs, but these tutorials will get you headed in the right direction.
PHP vs. Java
This is a pretty subjective question. PHP and Java are just tools, and in the hands of a bad programmer, any tool is useless. PHP and Java both have their strengths and weaknesses, and the discussion of them is probably outside of the scope of this post. I'd say that if you already know Java, stick with Java.
File I/O vs. MySQL
MySQL is better suited for web applications, as it is designed to handle many concurrent users. You should know though that Java can use MySQL just as easily as PHP can, through JDBC, Java's database connectivity framework.
Read the tutorial on Java Web applications.
Basically Web applications are a part of the Java EE standard. A lot of people only use the Web (servlets) part with additional frameworks thrown in, most notably Spring but also Struts, Seam and others.
All you need is an IDE like IntelliJ, Eclipse or Netbeans, the JDK, the Java EE download and a servlet container like Tomcat (or a full-blown application server like Glassfish or JBoss).
Here is a Tomcat tutorial.
I'll jump in with the notorious "Do you really want to do that" answer.
It seems like your focus is on playing with Java and seeing what it can do. However, if you want to actually develop a web app, you should be aware that, although Java is used in web applications (and in serious ones), there are other technology options which might be more adequate.
Personally, I like (and use) Java for powerful, portable backend services on a server. I've never tried building websites with it, because it never seemed the most obvious ting to do. After growing tired of PHP (which I have been using for years), I lately fell in love with Django, a Python-based web framework.
The Ruby on Rails people have a number of very funny videos on youtube comparing different web technologies to RoR. Of course, these are obviously exaggerated and maybe slightly biased, but I'd say there's more than one grain of truth in each of them. The one about Java is here. ;-)
While a lot of others should be mentioned, Apache Wicket should be preferred.
Wicket doesn't just reduce lots of boilerplate code, it actually removes it entirely and you can work with excellent separation of business code and markup without mixing the two and a wide variety of other things you can read about from the website.
Also be advised, that while Java is in general very beginner friendly, getting into JavaEE, Servlets, Facelets, Eclipse integration, JSP and getting everything in Tomcat up and running is not. Certainly not the easiest way to build a website and probably way overkill for most things.
On top of that you may need to host your website yourself, because most webspace providers don't provide Servlet Containers. If you just want to check it out for fun, I would try Ruby or Python, which are much more cooler things to fiddle around with. But anyway, to provide at least something relevant to the question, here's a nice Servlet tutorial: link
Look into creating Applets if you want to make a website with Java. You most likely wont need to use anything but regular Java, unless you want something more specialized.
I'd suggest OOWeb to act as an HTTP server and a templating engine like Velocity to generate HTML. I also second Esko's suggestion of Wicket. Both solutions are considerably simpler than the average setup.
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I love Java like hell. This is not my 'native' language in work and I do Java projects from time to time after work. I have used only few technologies with Java like communication via raw sockets and Swing. Once in the past I run the Apache-Tomcat with very simple JSP generated page. Really basic stuff.
Some time ago I was interviewed to participate in more commercial Java project. It was a web-service based on browser content/application... I heard words like 'JSON', 'GWT', 'AJAX', 'XML' and I was lost in answers. ... I suggested java Applets+Swing, but they wasn't interested. I realized I have extremely limited knowledge about web technologies. I looked very bad on this interview.
If I am not a JavaScript guy, can I really do web-apps with pure Java? I mean web pages with dynamic-fancy-elements which are I think provided mostly by the JavaScript. What technologies should I get to know? Can be JavaScript generated from Java code?
I'll make this a CW answer, because the question isn't a fit for Stack Overflow's "one right answer" format.
Yes, you can write browser applications without knowing JavaScript. One way to do that is to use the Google Web Toolkit. (Amusingly, this was one of the acronyms you heard but didn't know — GWT.)
Why we need Javascript?
to reduce load on the server, by doing things like input validations before submitting the data to server.
Can all this be done without Javascript?
Yes, you can have plain HTML and do all the validation from your Java code
Is it good idea?
No its not. By doing so, you are loading the server for simple tasks such as input validations which can be easily accomplished by Javascripts.
I don't know Javascript. With ONLY Java can I get rich web-app?
Yes, GWT is google's tool which allows you to achieve the same. GWT gives you Eclipse plugins to manager the GWT web-apps and it allows you to write plain Java code (absolutely no Javascript) and in the backgroud coverts them into Javascript, so that the rich UI is created with most of the UI event handling in the browser itself.
From someone who has Java as their go too language, develops web applications and doesn't particularly like JavaScript I'd say... just learn JavaScript. Sure it's not a very nice language (IMHO) but it's absolutely essentially now-a-days. JavaScript appears just about everywhere now from JavaFX to web services (e.g. JSON) to web applications. Java has a JavaScript engine in Rhino and is getting a new one in Java 8 called Nashorn so I'd expect to see more JavaScript not less.
In direct answer to your question, yes, you could write a web application without knowing any JavaScript but before long you'll find a situation where you have to hack on some JS or debug it and then you'll kick yourself for not having learnt it from the start.
To give a short answer, Yes you can but then the Javascript will be generated for you. There are many frameworks that will generate the Javascript for you. Maybe you should look at Vaadin if you don't like writting javascript at all.
On most projects there is no need for writting javascript on scratch. 99% of time we use jQuery or plugins based on those. Maybe you should have a look at the Twitter bootstrap.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I am planing to rewrite my desktop finance application (written in Delphi) as web application and am thinking which technology to use. Other possible requirement is to transfer as much code as possible to shared library which could be used in desktop version of the application too. There is no such parameter as total cost of owhership. I can rewrite it as long as I want.
I need a cross-platform technology which is able to handle UTF-8 natively and connect to PostgreSQL as well as Microsoft SQL Server.
I have programmed enough with Ruby on Rails and will say that it is quite good for commercial websites but does not fit for my own web application, as I do not like its "magic" and inability to write .rb files in UTF-8.
PHP seems to be similar to RoR although I haven't tried it.
ASP.NET / .NET MVC meets my requirements except it is for Windows only.
So, I've chosen Java. But they say in Internet that Java and JSP are different technologies and I can not take Java desktop application and with very little changes convert it to JSP. Are Java and JSP really so different? For example, in .NET I could write a database- and business-logic-library which could be used in desktop application as well as in ASP.NET application.
Java and JSPs are not different. JSP gets compiled into Java Servlet before execution.
JSP is meant for writing HTML/ASP like code dealing with presentation. In other words, it gives segregates presentation detail from Java coding, but in the end, server compiles your JSP files into Java Servlets.
What you want to write in JSP, can be written through Servlet.
If you plan to use JSP over Servlet, please make sure you are not writing entire code in JSP itself e.g. reading data from database. All the business logic should go in JAVA classes and used in JSP through your JAVA classes. Your Java classes can be reused if designed appropriately.
If I understand you right, this is what you are trying to achieve i.e. achieve re-usability of your application logic.
They are not that different besides you can reuse your services, logic etc. in the same way .NET does it.
The only problem is the view, there are many ways of doing it in java. If you've chosen JSP you will need to code all your presentation (you can invoke your services, logic, etc.), but if you want reuse as much code as possible in a Desktop java application an take it to the web perhaps your should take a look at java Applets which are relatively simple to turn into a java application.
For the situation that you describe it should be pretty easy to have a lot of shared code for both the desktop and the web application.Think of the application as consisting of 2 layers:
Layer 1: Business logic and Database access code, this layer just pure java it should not depend on any technology that can not run outside the container. For example, you can use JPA for database access, and Spring to organize your business logic into nice modular units. If you write a comprehensive test suite for this layer, then you would have confidence that your business logic works correctly and it would it make it easier to figure out if a bug is a web app bug or a desktop bug.
Layer 2: UI logic, you will need two instances of this layer, one written using a desktop UI technology like Swing,or JavaFX and another layer UI layer written in a Web application programming technology such as JSP / Servlets, JSF, SpringMVC, .... etc. This UI layer will depend on the Layer 1 and because of the comprehensive test suite for layer 1 you can be confident that the operations it calls upon on layer 1 are good.
As far as web development technology I would recommend that you consider higher level frameworks that JSP and Servlets, because that will save you a lot of time.
There is a possibility to be able to write a single UI layer using JavaScript, HTML 5 which is a web app but behaves like a desktop app for many features. You can then make a desktop version of your product that basically launches a browser windows without the chrome and runs the app within it. If you do choose to go down this road of using JavaScript and HTML 5 there are plenty of frameworks to choose from, I would recommend that you watch the videos on infoq.com from the ThroneOfJS conference http://www.infoq.com/throne_of_js/ to get an idea of what frameworks are available my biased recommendation would be for using AngularJS.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 12 years ago.
So here's the story: I currently work as a C# developer doing ASP.NET. While I like C# I don't like the overall quality of the .NET community; most of my past experiences have been that many .NET developers are totally ignorant of actual software engineering (e.g. design patterns, code separation, etc.). The Java area seems a lot better in this regard even if you do have to put up with the occasional "architecture astronaut".
My actual question is this: I can pick up the Java syntax easy enough since I already know C#. However, I've only worked with the full Microsoft stack for web development (WebForms, although I've looked a bit at MVC and I've done some Ruby on Rails demo stuff so I know MVC fairly well). If I want to learn enough marketable skills to be able to apply for junior-level Java development positions at companies, what stack should I look at? There are dozens of Java web frameworks out there; what would be the most common one used in companies? It seems that Hibernate is the default standard for persistence (I've done a little bit with NHibernate) so I'm okay with that. I've also seen several new Java web frameworks that seem interesting, but learning them won't give me a leg up in applying for a job at a company because I'm bettering they're untested in the corporate world and aimed at startups and similar like most new frameworks.
Which framework would be the most likely to be used at a typical company that I should start to learn in order to begin a transition to a better quality community?
I'd actually recommend that you start by learning straight JDBC for database access and servlets+JSP for the web front end, and using those to implement a (very) simple web app. JDBC is the API on which basically all other Java database libraries are built, and likewise for servlets. These will require the least configuration necessary to get your app running. Once you've done that, you'll have a better foundational understanding and can take a look at:
Hibernate with JPA for persistence
Spring for dependency injection
One of the many web frameworks - Spring MVC, Struts 2, JSF or Seam are all viable
Java EE components such as EJBs.
If you're looking to do this on a full-blown Java EE container, I'd recommend using Glassfish as your server. But Tomcat is simpler (just a servlet container), and might be better for starting out with the first project.
Get familiar with Apache and JSP stuffs would also be helpful in addition to the answer above.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am a .NET developer (and have been for a while now). I work for an organization that was just recently acquired by a larger company whose primary development language is Java. There are a few .NET developers, but the ratio of .NET to Java has decreased substantially now that the teams have merged.
That being said, I've decided it would be best for me to start Java development. However, most of the books I've seen so far for "learning Java" all take a very basic approach (what is a class, OOP principles, etc etc). I am comfortable with this part of development and don't need a primer (unless there are differences so profound that someone recommends the fundamentals from a Java perspective...).
Anyway, I'm looking for a book recommendation for Java development from a software developer's perspective that discusses today's techniques. For example, MVC architecture, application best practices (I am a web developer, this includes web services), is it worthwhile to work with JSPs or consider Ruby instead, etc etc.
A HUGE bonus would be "learning through doing". Something like Murachs, where I can step through a project from start to finish, and is light enough on fundamentals that I don't get bored. I'm hoping to walk away with enough basic knowledge to volunteer for some internal projects and grow from there.
I'm sorry if my question is needlessly broad, but I'm struggling to find a starting point aside from my Eclipse installation (I am doing this on Ubuntu, deliberately avoiding Windows).
Thanks for any direction or insight you can offer.
EDIT - After discussing with a co-worker, and reading Bert's great suggestion (all of them have been excellent, thank you all very much), it turns out the main focus is on EE, and Glassfish. They use NetBeans for development, since it is tightly bound to Glassfish.
This doesn't mean much to me, except that I think the parallel drawn is IIS/Web apps to Win32 apps. But perhaps it will help clarify some of the more open-ended questions in my OP.
Effective Java By Josh Bloch
It may not be "learning by doing" but it gets into the details of how to use the Java language effectively.
I would then complement it with Java Puzzlers by Josh Bloch and Neal Gafter
My best bet is to learn Spring based on your requirements:
MVC architecture, application best
practices (I am a web developer, this
includes web services), is it
worthwhile to work with JSPs or
consider Ruby instead, etc etc.
You can start by visiting SpringSource at http://www.springsource.org/
There are a few points I would like to make to you:
The basic Java language is rather small and C-ish. To my understanding C# and Java works almost identically here.
The Java runtime library is VERY, VERY BIG, and rather unlike C#. Very few people know all of the Java 6 runtime library well.
There are several IDE's in common use for Java. You will want to learn the one used by the rest of the team.
I would suggest having a brisk walk through the Oracle Java Tutorial, just to get the hang of the spirit and do some of the exercises, and then look at the common "Java for C# programmer" cheat sheets on the internet. Then do a lot of code, and then read Effective Java.
(For those who think they know Java 6 runtime well, please consider if you are familiar with RMI, the Rhino Javascript engine, and XPath in the XSLT implementation and all the rest)
Please look at the following thread:
https://stackoverflow.com/questions/75102/best-java-book-you-have-read-so-far
Ruby makes no sense unless you're writing JRuby on the JVM.
If you're writing web apps, you'll need to know JSPs written using JSTL (JSP standard tag library), servlets, HTML, CSS, and JavaScript. Download Tomcat from Apache - it's a servlet/JSP engine that will let you deploy web apps locally for learning. It has an HTTP listener built in, so you don't need IIS or Apache.
You'll need to know how to create and deploy a web archive (WAR) file. That's a ZIP file that contains the standard format for a web application.
I'd have a look at the Tomcat "first web app" docs to get a feel for it.
Once you have that, come back and talk about frameworks. (When you do, I'll recommend Spring.)
Here are some references I like. I'm sure there are better, but there are the ones I have read and can vouch for:
Java in a Nutshell is a classic summary of the core language. If you need more, there are books like Java for Programmers for programmers transitioning to Java (I have not read it).
Sun's Core Servlets and JavaServer Pages was a good book for Java servlets and JSPs. But consider that a lot of web tech is built on top of this (e.g. Spring), so this may be giving you foundation but not direct knowledge of the specific framework you will be using. Also a lot of web tech these days are client-side/JavaScript/AJAX-based, e.g. jQuery.
As for MVC, consider focusing on MVP instead. I been playing around with Google Web Toolkit to leverage my Java background to create client-side apps, but it is also a good way to get some idea of MVP - read Large scale application development and MVP Part I and Part II, and the GWT MVP Development with Activities and Places. However, GWT keeps evolving.
My last suggestion is that you narrow your focus - try to figure out what frameworks are popular at work and decide if you want to focus on a tier: front (e.g. HTML/CSS/jQuery), middle (e.g. Spring), or back-end (e.g. Hibernate). Once you figure this out, then post a more specific question(s) (e.g. what are the best resources for learning XYZ).
Just from my experiences with java (limited but I took a Web Dev course teaching JSP's) Any decent technology for it is usually 3rd party. However, from what I can tell when doing web dev I would use Netbeans, Netbeans has Tomcat built in especially in Ubuntu for easy debugging.
More on similar lines you can find answers from this post
https://stackoverflow.com/questions/3820437/life-after-head-first-java/3820449#3820449
The Java landscape is quite wide as you probably have already figured out.
There are hundreds of frameworks and tools that can be used for basically doing the same thing. To get an idea, you can take a look at this presentation written by Matt Raible, where he compares a number of Java web frameworks.
As someone else suggested, you should definitively take a look at the Spring Framework. It is widely used in the enterprise world. There are several good books about Spring.
If you want to get the basics of Spring MVC in a "tutorialized" style, you can take a look at this book. It doesn't cover the latest Spring version (3.0) and it is not a "perfect" book, but it should allow you to get the basics while running some examples.
Also, there are literally thousand of Spring-MVC tutorials on the web.
For instance, you can take a look at:
http://www.adobocode.com/spring/a-spring-web-mvc-tutorial
RESTful services are also quite popular these days. I have been working with the Resteasy framework from JBoss and I found it very easy to setup and work with. This book explains the REST architecture and uses Resteasy as framework for the examples.
I also recommended "Head First Design Patterns" from O'Reilly. It covers the most important patterns using Java and it will help you to see how the language can be used for patterns you may be already familiar with.
One more suggestion: you may considering "tuning in" on Java TV. It's a great resource with hundreds of Java tutorial videos. It covers a wide spectrum of technologies so you should be able to find something for you.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Is there any simple java web framework like sinatra (for ruby) or web.py (for python)?
If you want a strict Java framework Spark might be an alternative:
import static spark.Spark.*;
public class HelloWorld {
public static void main(String[] args) {
get("/hello", (req, res) -> "Hello World");
}
}
Play. Haven't tried it myself but heard only good things about it and seems to be quite beginner-friendly.
I think the simplest thing to do to generate web content via Java is to write a Servlet. Just like web.py allows you to define a GET method, you can implement a Servlet's doGet() method and write data directly back to the client.
Here is a link to the Servlets tutorial. You will also need to know how to package and deploy a web application; for that I usually point people to the Tomcat manual (see the section titled "First Web Application").
Writing and deploying a Java web application is not going to be as fast as in Ruby or Python, but Java isn't particularly known for its succinctness.
If you don't strictly require Java, check out Grails. It's a web application framework built on Groovy, which is a dynamic language similar to Python and Ruby that compiles to the JVM.
JAX-RS.
Java EE 6 Servers like GlassFish bundles it by default.
If you use Tomcat, you can use Jersey, Apache CXF, or Restlet implementations.
Using JAX-RS annotations the web development feels like Sinatra or Merb. BTW you don't have to use Java as the language, you can use Scala, Groovy, JRuby...
If you are only looking for a presentation framework in pure Java then, for me, Stripes1 is the closest of the Java MVC frameworks to the RoR philosophy: simple, elegant, and requiring minimal configuration.
1 Stripes pioneered the Convention over Configuration approach for Java web development. And while some other frameworks have adopted some of its principles (like Spring MVC or Struts2 with plugins), I still prefer Stripes because it does one thing, and does it well.
It is possible to use Sinatra as is with JRuby
look at this two as well: 1. activeweb and 2. dropwizard
You might want to have a look at those 2 groovy projects:
https://github.com/webdevwilson/graffiti
https://github.com/bleedingwolf/Ratpack
Really light akin to Sinatra. Might be a bit on the bleeding edge though:-) Interesting and promising never the less.
Check SerfJ : Simplest Ever Rest Framework for Java :
Using SerfJ is the easiest way of developing Java REST web
applications. It helps you to develop your application over an elegant
MVC arquitecture, giving more importance to convention than
configuration, so for example, you will not have to have configuration
files or annotations in order to specify which view serves a
controller's method. However, SerfJ is very flexible library, so if
you want to jump over those conventions, you can configure the
behaviour of your applications as you like.
The framework tries to meet JSR 311 specification, but it doesn't
follow every point of that, because the purpose is to have a very
intuitive library, and some some aspects of the specification are out
of the scope of SerfJ.
SerfJ is opensource and is released under the Apache License, Version
2.0.
If you have to develop business or database applications OpenXava is a good option. OpenXava allows you to develop a complete AJAX web application writing just domain classes, with no code generation and producing an application ready for production. Little code, great result.
The smallest "usable" web server for Java that support Servlets that I can find is Miniature JWS. And honestly there is no reason to run a Java web server that doesn't support Servlets. If you want to do REST, Restlet has a built in HTTP daemon that means you can run it as a stand alone web server.
HybridJava framework is really simple. Of course, it builds like an API above Servlet API, but deals with page and component instead of request and response. In other words it is truly MVC.
Step is a framework for Scala inspired by Sinatra.
I can recommend Struts2 to you, because i like the plugin architecture and with the convention plugin it is simple and fast to develop.