Starting web programming in Java - java

I've been programming in PHP and ASP.NET for a while now. When doing PHP, I've always used XAMPP to test my websites. I'm wondering (since I'm learning Java) if there are equivalent services around?
Furthermore, I know this is sort of an open question, but how would you make a basic page in Java, just a basic 'Hello World' web page.

You can actually still use XAMPP. You just need to install tomcat. Here is a great screen cast on how to do it: http://www.youtube.com/watch?v=TUV_jPdq7fc.
If your a mac user you can try MAMP (whcih I prefer) and follow http://blog.mirotin.net/22/tomcat-on-mamp-the-simple-way. To get Tomcat going.

You might want to learn about programming in JSP and Servelets. JSP s are kinda like php in that they emit html out.
Also the server would be tomcat.
It would be best if you download Eclipse for EE developers. You can also try Netbeans. a sample servelet

You may read about servlets which is the basis for web applications in Java. There are many web frameworks built on top of them.

I always recommend Grails to anyone getting started with java/the web. It's more important to grasp the patterns, lifecycle, and working with requests and responses than learning the actual language. Learning Grails has got me from hobbyist developer to IT employee working with ATG - one of the most obscenely challenging web frameworks there are.
Grails includes everything you need to get started: local server, scaffolding (that's your ticket to Hello World), database access, dependency injection, the list goes on. It's built on top of Spring, Hibernate, Sitemesh, etc, which are all well-known and excellent frameworks that are being used in production.
Grails is written with Groovy, a language written on top of the JVM not far from Java.
Happy coding!

i seems to be new to the platform nd new to java but would like to suggest what i have gained till now that for developing a java page we can have any of the two servers downloaded(Weblogic or tomcat). weblogic is fully implementation of classes whereas tomcat has partial implementation. Then for the next step that we require is a source file(java file),and html file and a xml file and these all needs to be placed in a root directory as like the source file,html file and a folder named WEB-INF to be placed parallel.
Inside WEB-INF folder needs to create classes folder where our java class file will be kept.
then needs to create a .war file and deploy it over weblogic to get our desired page display.
thanks......

Related

Java/JSP : Making a executable Java working as webapp

I have a standard java project working local made by another person i know.
It's about data retrieving.
I need to develop a web app supposed to do the same thing but accessible by anyone via browser.
I CAN'T edit the code for that purpose, at least some implementation details. A kind of black box.
Can you suggest me the best approach to make a webapp based on a local executable app through JSP & servlet ecc?
Maybe you can try something like webswing.
What is Webswing ? Webswing is a web server that allows to run any swing application inside your web browser using only pure HTML5.
The best days of swing framework are gone. Desktop applications lost
popularity and everything is forced to be online and mobile. But what
about existing application? Using applet technology proved to be
insecure, rewriting the application to web technology is too
expensive. This is where Webswing can help you. With Webswing, your
application is securely running on server and user's browser only
displays the application window. All this without changing single line
of source code.

Server side Java - where to start [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm really starting to get a hang of the client-side Java programming, and from what I understand Java is great for developing stable server sides for large amounts of traffic.
The problem is that I'm completely new to server development, so I don't know where to start or where to look for information, despite Java's good documentation.
More specific questions:
Do you know any good, non-specific tutorials for server-side Java? I've seen some tutorials for Google's Cloud Platform and Netscape, but I don't want to be dependent on their infrastructure.
Is the common practice to develop your code in Eclipse and then "ship" it to your server? As I said I've never done server-side development and I've only tried learning a little node.js.
Thank you in advance, I hope these questions aren't to wide-scoped.
I would suggest you to start with a simple setup like you already told us: Eclipse + let's say an easy to use tomcat.
If it comes to the server side you need to create a Servlet which allows to access other application data from your server in a format which you define or let's say you + the clients define. I would suggest you to start with something you will be familiar like Json. For this I have a little "starting point" for you.
Clone that simple example for a server-side application:
https://github.com/DominikAngerer/java-GsonJerseyProvider
It already provides you a simple structure for Json which is used by a Framework like Ember and also you can easy modify the structure which is defined there.
Is the common practice to develop your code in Eclipse and then "ship" it to your server?
Yeah it's totally common to do that. Write your Server Side code and export it as .war - tomcat or jetty for example can simply deploy them and you will be able to run them on these application server.
Do you know any good, non-specific tutorials for server-side Java? I've seen some tutorials for Google's Cloud Platform and Netscape, but I don't want to be dependent on their infrastructure.
I really love to work with Jersey - It's really a to understand the code you will write. Maybe try the example provided by IBM developersworks: http://www.ibm.com/developerworks/library/wa-aj-tomcat/
For the beginning it may be a little of a overhead but after you tried the example (it should be running right away) I think you will get the idea of how to create a simple backend system with java.
If you want a complete environment out of the box, you can try:
Netbeans EE IDE:
It contains a GlassFish server and the SDK preconfigured, glasfish is one of the most used open source application servers. Here you can find tutorials from the Netbeans page.
JBoss Developer Studio: is another very used IDE that includes a JBoss server. You can find tutorials from this one here.
I would sugest to start with GlassFish, as it is very easy to use and configure.
Take a look at JavaEE. I would start by learning how to create simple JSP pages with Eclipse + Tomcat (create a "Dynamic Web Project"). After that, check out Servlets and be sure to understand HTTP. After that, I would get an overview of JSTL and other Java EE components. DZone has a nice refcard giving you an overview of the Java EE 7 components.
After that, you should be good enough to move on to a framework like Spring or Struts. Alternatively you can perfect Java EE fully learning it's more advanced components like CDI(context dependency injection) or JAX-RS and JAX-WS(web services). This document should give you an overview of how to configure a servlet container in eclipse: http://www.eclipse.org/webtools/community/education/web/t320/Configuring_an_Application_Server_in_Eclipse.pdf
As for tutorials, check out Oracles JavaEE 7 tutorial at: http://docs.oracle.com/javaee/7/tutorial/
Alternatively, if you do not like the styles and patterns used in Java EE, there is a non-Java EE framework called the Play Framework (http://playframework.com) it gives you the option to develop your application using either Java or Scala, and uses MVC architecture.
If you want to learn server side programming with JAVA, I recommend to start working with Eclipse. Almost all developers whom I know are using one or another IDE, most of them are using Eclipse for J2EE.
There are plenty of tutorials available on how to setup eclipse on your local computer. I personally read many tutorials when I learned it, you can google it.
http://www.apekshit.com/t/11/Writing-JAVA-programs-in-Eclipse
http://www.apekshit.com/JSP-Tutorial-for-beginners-with-Examples/c/21
I found these 2 that might help you to achieve what you are looking for.

Setting up JSP Server?

OK so at work I've been working with Java to start migrating our legacy database and in-house systems to something more modern. Well today I was asked if there was a way to use HTML/CSS as a front end to the java programs I've made. So my coworker and I have set up Tomcat on our Ubuntu 12.04 server in hopes of using jsp. Now we don't know where to go. I've been using Netbeans for my java development and all the tutorials and articles I've found has been about installing the server on my PC and I think that can't be right. Are there any good, semi-current (as in not from 2003) tutorials or articles for setting this up? Both my coworker and I have experience with PHP and it's not this difficult to set up.
It doesn't matter where you install Tomcat, your computer or a separate server. Create your web application, drop the war into tomcat/webapps and you're ready to go (to http://yourservername.com:8080/nameofwar/). Of course if you've never actually created a web application, there's some additional complications.
If you're familiar with Netbeans, you probably want to create a Dynamic Web Project. Plenty of resources to be found with all this info I've given you.

Making a Java Application available via a Web Browser

I am working on a Java program that has bunch of classes consisting of dialog boxes, JFrames, etc.
Can someone guide me where I can learn how to transform it to an 'applet' kind of. ( I don't even know if applet is the right word)
Like for example, can it be accessible through the internet browser. If I somehow make a domain www.myjavaprogram2011.com it would be nice if it will take it straight to the java program I coded. I see this as anyone can come to this website and use that program.
Thanks!
You may want to look into Jars for distribution or probably more aptly Java Web Start as this allows Clients to be downloaded and run.
Java Applets isn't your best bet as there's lots of security permissions that you need to worry about as well as your jars needs to be signed (especially for client/server data access).
Try using Java Web Start, it will allow you to launch fully-featured application from the Web Browser. Oracle has tutorials on deployment of JWS, etc.
Sounds you're looking for some kind of RIA technology. Have a look at JavaFX, though it's not mature yet IMHO.
Ah, but then, if you already have a Swing application then this isn't an option probably.

What web server should I use if I want to run Java code behind it?

At the moment, I have lot's of Java which does all kind of nifty stuff and I'm happy with it. The code is command line driven which have been great so far, but I recently decided I want to make the functionality available through web-services. Since my is complex and I'm happy with the way it's written , I don't want go through the pain of porting it to other languages. So I set out on a google journey to find out what web servers exist (on a Linux machine, though it's interesting to hear the answer without that limitation).
From what I could find, it seems that there are two viable options: Apache Tomcat and Sun Java Server.
What are the reason to choose one on top of the other? what are the strength of each and what are the weaknesses? Or, perhaps, there is a third one which is much easier, flexible and less cumbersome.
Anyone?
Easy, flexible and not cumbersome, that would be Jetty, but also Simpleweb might be useful. You dont say much about your software so i'm not really sure, but for a command line program, I don't think you need all the JavaEE stuff.
The mainstream servers are these.
I think the Apache Tomcat vs Glassfish (Sun Java Server) discussion is irrelevant for your needs, any would do.
There are many containers for Java web applications, they all have their own strengths and weaknesses. If you're looking for a container to support a business application, you should probably take a look at how they differ and work out which suits your business and IT drivers.
The key thing is that they all support the servlet specification - your webapps can run in any of them - which means you can change your mind easily. Some of them will also support more of the Java Enterprise Edition specs, so may be too heavy for your needs.
If you're just getting started, I'd suggest Tomcat. It's basic, but it's reliable, quick to run and start up, and it's got a really easy web-based webapp deployment interface.
Your question is actually a bit too ambiguous and wide. You can in fact run Java code at any machine you like, regardless of the language you programmed the webbased interface in. You can for example create a PHP based website which interacts with a "backend" Java application (the "command line application" as you call it). The only requirement is to have a JRE at the server machine. Then basically everything as web interface suffices: CGI, PHP, ASP, Python, etcetera, you name it. As long as it has access to the underlying commandline runtime, which is in the PHP example to be done by exec().
But Java, actually Java EE, also provides a web application programming interface: the JSP/Servlet API, the web component of the large Java EE API. This make integration with the "commandline Java application" much more seamless. You can basically just put your application in the classpath and import/access/use it in a Servlet class the real Java way:
YourApplication app = new YourApplication();
Result result = app.doStuff();
// ...
To be able to run JSP/Servlet (JSP is at end actually also a Servlet), you need a concrete implementation of the Servlet API (the whole Java EE is just an abstract specification). Apache Tomcat is good to start with, the other popular alternative being Eclipse Jetty. Those are 'simple' servletcontainers which implements the Servlet API, with Jetty being a more embedded approach of it (you can configure and run it as a "plain vanilla" Java Application). But if you need to support/cover the other aspects of the Java EE API as well, then you need an application server, such as Sun Glassfish or JBoss AS (both which by the way uses Tomcat as the servletcontainer part).
To learn more about JSP/Servlet, I can recommend the Coreservlets.com tutorials.
Apache Tomcat should do good.
The standard concept for running code inside a web server is the "Servlet API" from Sun.
Essentially it provides a few interfaces which the web server uses to invoke your code, and defines how the web server should behave. This allows you to write very generic code that can run in a variety of web containers which implement the Servlet API. See the Wikipedia article for details - http://en.wikipedia.org/wiki/Java_Servlet.
They come in all sizes too, depending on your needs. Some small enough for embedding in your own application, some very big. The servlet API allows you not to care.
For a beginner, the quickest way to get up and running, is to download the full version of Netbeans which includes full support for doing this kind of work, and has a built in servlet container.

Categories