Are Java and JSP really so different? [closed] - java

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.

Related

How to use pure Java in web applications without JavaScript knowledge? [closed]

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.

Is ZK open source edition "write once, run anywhere"? [closed]

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've been looking into using zk for my upcoming Java web project, but am a little skeptical because as awesome as it seems, it has an expensive licensed edition as well as a free open source edition.
I could only use ZK Open Source edition but need the "write once, run anywhere" functionality (otherwise I will probably go with GWT/Phonegap).
On their feature comparison page, they don't mention write once/run anywhere, so I'm wondering if any battle-weary ZK veterans can weigh-in on whether this feature runs on the free version or not, and how well.
I need to support all web browsers, mobile web, all Android devices (including Nook/Kindle), all iOS devices, Microsoft devices (Surface, etc.) and Blackberry.
Also, if the free/open source edition does support this feature, how does it work? Nothing in the tutorials seems to indicate how it generates native executables for the various platforms in addition to a WAR...
No.
ZK only builds Java web archive files (war), it does not build native applications for Android, iOS, Nook, Kindle, or even stand alone applications for the desktop.
ZK web applications only run in a Java application server like Tomcat, JBoss, Jetty, Glassfish, etc.
In this sense, ZK is very similar to GWT and very disimilar to PhoneGap.
With PhoneGap you build phone applications using HTML, CSS, and JavaScript. Your application is then displayed inside a native wrapper compiled for each phone platform. This is not intended for the web, per se.
With GWT you build web applications in Java code. Some of this Java code actually gets compiled into JavaScript so it can run on the client side when appropriate, offering performance advantages if used well. Writing JavaScript code as Java has the advantage of going through the Java compiler for type safety and the like.
With ZK you build web applications in Java code. Unlike GWT, this never becomes JavaScript - all your Java code runs on the server. ZK handles setting up the AJAX calls.
Programming in ZK feels as though you have a copy of the DOM as Java objects. ZK deals with initializing your Controller for a particular View and you can ask it to wire up any Component from the view. You then have those Components as objects and any changes you make are immediately (more or less) reflected on the client.
Now, ZK aside..
If you want to write code once to run on all web browsers as well as on all phones, the only option is to write a web application. At the curent state of technology, you will not be able to get native executables for all phones and a get a web application from the same code base. If you develop a web application (using ZK, GWT, IceFaces, Lift, Grails, whatever) you can expect the maximum penetration into the market as almost all devices have a web browser.
Finally, some personal opinions on ZK..
The development cycle is fantastic, I love programming with ZK.
The team and community is great also, lots of momentum.
The framework is actively evolving, new core features and improvements all the time.
I'm not sure how it would stack up against the others under heavy load.
The DOM they generate is very heavy
There is a lot of chatter between the client and server
Edit:
PS: I found this old reference to something called ZK Mobile which I think is now a dead project. My impression is that it was probably aiming to be something similar to PhoneGap in that it would just wrap your ZK website in a native Android application. Everything would still work over the internet but the user would have an icon on their phone. You wouldn't have access to any native functionality like alarms or the like.
Anyway, just thought I'd put it here for the sake of completeness.

Whats the best technology stack for supporting mobile apps and a website from the same back-end? [closed]

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 11 years ago.
I will have native iPhone and Android apps, and later a mobile web site (for other mobile platforms) all talking to a back-end that manages users, settings, video, social graphs, etc. I will also have a dynamic web site with a lot of video, pictures, and social graph administration. The web site will basically be a more featureful version of the apps on the phones. The back-end consists of video storage, transcoding, a video recommendation engine, options to share the video with your network.
My thought is that I should build a common applications services layer that exposes a RESTful api that returns JSON, and have both the apps and the web site talk to this api.
My question is should I keep the web site and the services layer both in one technology or use Java for the services layer, and Rails or Python for the web site to take advantage of their purported faster dev time. The site will have a lot of JavaScript and AJAX to support dynamic behavior. If I use Rails or Python, should they also talk REST/JSON to the services layer? In terms of deployment and scaling management, it would seem like sticking with one technology like Java for all back-end pieces might be better; but on the other hand Rails and Python promise faster development and maintenance times for the web layer. If I use Rails for the web tier, would it make sense to deploy it in JRuby within the same JVM as the services layer to have fewer moving parts to manage on the web/app server?
The site may grow to millions of users and videos. The development team are experienced at Java, with some Python, but are smart and can quickly learn other technologies.
Feel free to suggest the technology stack of your choice.
Here are some advice based on my experience:
create a separate API layer for your JSON api. Use Spring MVC or JAX-RS there
for the web front-end you can use grails - it combines the strengths of dynamic languages like ruby and python with the power of the JVM and the java stack.
you can choose to use only your API from your site, or expose only some of the features through the API and use the rest internally.
for internal communication try not to add overhead - you can start with simple service classes (spring beans, for example). Exposing them as web services is harmful, imo. Yes, it appears that your modules are decoupled, but it hampers flexibility. Since services are stateless they can be invoked from any place, so you can easily make them live and be invoked in the same JVM as the grails app.

Which Java technology should I use, if I want to build a website with thousands of users?

Sorry for asking this question, but I searched all Java-related questions, but I got more confused. I am still not clear what should I start with.
My main thing is building websites in Java, because someone told me that there are some machine learning or AI libraries available in Java which I can use in Java. So I decided to use that as it can reduce my work.
Now I don't know Java at all. Some people say the following are used to build websites, like:
Servlets alone can build a website
JSP alone can also build a website
Struts
Spring Framework with Hibernate
Seam
Java EE also for websites
I am confused. Where should I start from? Where does core Java fits in here?
I was thinking of perhaps learning Python as I know I have to learn Python only, not its variations.
So please guide me to one thing which can solve my basic purpose of using ready-made libraries of AI.
If I can do that with JSP then I will start with that.
But if I need to learn all of them, then it’s better if can start learning Python.
I have five months to finish the website.
I really don't know why there are many branches of Java for doing one thing.
To correct some misconceptions of yours:
servlets and JSP are Java EE
Seam and Struts can be used together with Hibernate as well
Spring MVC is a web framework. Spring as a dependency injection framework can be used together with any other framework.
there are many more options, like JSF, Tapestry, Click, Play, etc.
It depends on what will the site will be doing, but you can choose any.
Experience has shown that building complex HTML forms (especially validation) and Ajax functionality is hard to get right. You will most likely appreciate having a library to assist you with that. The same thing with database access.
Everything builds on servlets. Learn those in order to understand the libraries you will use.
I would suggest learning JavaServer Faces (JSF) with facelets. The easiest, while being powerful, is JSF 2 in Java EE 6. The easiest way to get started is to use NetBeans with GlassFish 3.
For static web pages, HTML alone is enough and if you want to make it more user-friendly and interactive, use JavaScript.
There are lot of frameworks you can use directly in JavaScript, like jQuery. Now if you want to make some more functionalities, like database interaction, then you will need either PHP, Java (JSP and Servlets) or .NET (there exist some more, but I’m aware of three only). Each of them have their library to interact with database.
Since you are interested in Java, go through Servlets, HTML, JavaScript, and JSP. Once this is done, you can look into JSF and EJB beans. So if you have knowledge of Java this will not take too much time, because the syntax is the same; the only difference is the concept.
So you will have a frontend (HTML, JS, and JSP) which will interact with the backend (Servlets and the database) which will be deployed in a Web container. To deploy, you can use an one of the available application servers, like Apache Tomcat, GlassFish, or WebSphere. To develop your application, you can use Eclipse as the IDE, which is one of the best IDEs I have used.
So decide your architecture and design, break it into components and start writing small applications first. Once you are experienced in small application, start writing an application where there are more things you have to care of, like load on database, availability, security, etc. For that, you can refer a very famous question on Stack Overflow, What technical details should a programmer of a web application consider before making the site public?.
The closest to core Java is servlets. No extra syntax, very minimal library, but no included functionality.
For building websites, the main thing is HTML and HTTP.
All technologies (including Enterprise Java or Server side Java) do the same—to understand an HTTP request and respond back with HTML. All that you mentioned do the same thing with a different level of sophistication.
Start with Wikipedia.org to know what technologies do what. If you are completely new to Java, go through the Sun tutorials, do sample programs, and get comfortable with Java packages, JVM and classes. (This might take a week or two).
To build websites using Java, you'll have to learn Java Servlets—everything else (JSP, Struts, JSF, and Spring(!)) are built on it. Get Head First books on Java and Servlets; they will be useful.
You can always build the page in Ruby or something that will give you a website very fast. For the AI stuff that analyzes the bought items for the recommendations, use something unrelated to the page that only takes the database to work with.
I would not mix the whole web page stuff with the AI computing. You can do the AI things that will take a long time and maybe should done on a different machine to have your webpage also responsive with C++ or Java in normal applications.
Choosing your front end technique because of later usage is a very dangerous thing. Using the whole Java EE concept and learning it from scratch will take you much longer than have a quick start with your page if you do it in Ruby or PHP.
You can then build the first version of the page and generate a user base. Start working on the AI stuff once you got some data with other technologies.
If your page has performance problems because your technology does not scale, you can always begin switching parts of the stuff out with a faster technology or maybe simply a bigger machine. Get your page running before you build it bulletproof for the thousand users you are expecting.
If you’re trying to build a website from scratch, with no prior knowledge, your best bet is to go with frameworks that provide a complete stack for web development.
If you aren't dead set on Java, you could probably start learning Ruby on Rails, which would be easier to start with (if so, go buy a Ruby on Rails tutorial which goes through all the necessary things for modern web development, from MVC to version control).
For Java, try:
Play Framework is very similar to Ruby on Rails. It will get you started very quickly, and hopefully (if you follow conventions) handle all of your peripheral needs.
Spring Roo is a very-fast-to-work-with framework, but it might get hard to maintain and extend later on.
These two are full web frameworks, that is, they handle database, MVC (presentation layer), configuration setting, etc... (I'll explain shortly). And could even ease your deployment process.
If you're going to go through any other route (using several frameworks together), you are probably not going to finish what you are doing in five months.
To understand why, and to clear some things you wrote in your question, you need to understand that modern web development (and enterprise development as a whole) is comprised of several different technologies:
Presentation: the term web frameworks has been more or less taken to mean frameworks that deal with this side of web development, i.e., how to create a web page (an HTML page). Most of the frameworks offer an MVC like approach (which you can read about elsewhere), and this is what most of the frameworks/technologies you gave sit in—JSP and Struts (which uses JSP) are examples of web frameworks. Servlets is a lower-level API that standardizes how to answer HTTP requests (which JSP and Struts sit on top of).
Persistence: being able to show a webpage doesn't mean squat these days if you can't save data to a database, and that is what the persistence frameworks do (they ease the way you can save data to the database). Hibernate is a persistence framework.
For Java there are also dependency injection (DI), which is what Spring DI is. It's tough to explain DI to people not familiar with the troubles of Java, so I won't try to explain it, but it's a very important part of modern Java development.
apart from these core technologies, there are also many items that you'll need to learn to actually deploy the application (unless your using services like Heroku or Google App Engine, which should simplify things), and troubleshoot it later (understanding how concurrency and HTTP works).
To address the other technologies you brought up:
I've never really touched Seam, so I'm not sure, but it looks like a collection of other frameworks (mainly EJB 3, which itself is a collection of APIs, and JSF).
Spring denotes a popular open source group (the SpringSource group) that provides various technologies, but most likely when you hear about it they refer to two things Spring's dependency injection (DI) and Spring's MVC (which is a web framework).
Java EE is merely a collection of high level APIs which other technologies implement (Hibernate implements JPA which is part of Java EE for instance).

How do you make websites with Java? [closed]

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.

Categories