• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Some very basic Java questions

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm coming from a PHP background, and I'd like to start developing web applications with Java for a number of reasons.
I am trying to grasp a few basic concepts, so any help would be much appreciated.
I think I understand scriplets (JSP?) - allows you to embed pure java code withing a .jsp page?
I think I understand servlets - allows you to write pure java code and output to a web client (HTML)? Am I correct in assuming you can access a servlet from JSP pages?
But what I don't understand are Java beans, or more precisely, the difference bewteen Java beans and a servlet. From what I've read, beans are great for seperating out Java code from JSP pages, I just haven't figured out what makes a bean a bean.
Also, a quite broad question. What is the best road to start down for web applications? Although it sounds silly, I am thinking JSP pages interacting with Java beans, the things I don't understand.
Servlets seem like things things can get messy quick, outputing HTML from Java. And although it looks like I can accomplish my first few projects with JSP alone, then I'm down the same road I'm on with PHP, just different tags.
Thanks in advance for anyone willing to help this newbie.
 
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically there is no difference between JSP and servlets.
all JSP are compiled into servlets behind the scenes so you dont notice it.
You must understand, that first there were servlets which allowed you to use server side programming with HTML output with java which was great.
The problem with servlets is that if you got many HTML output in it it can be messy to do as you discovered yourself.
For that reason, JSP was invented - with it you can integrate the java code with scriplets in an HTML page.
Now you can use JSP and servlets together in a web application where you use JSP mainly in HTML pages that you need to be dynamic and connect them to servlets where more heavy programming work is done (like database connection etc).
Java Beans are just regular java classes that have some minoer rules to follow up.
You can use this classes in a JSP page rather easily using tags, and thats another way to seperate the logic from the HTML page.
Its your choice whether to use servlets or beans for the logic although you'll find for yourself where are some of the advantages using one against the other.
[ June 16, 2002: Message edited by: Roy Ben Ami ]
 
Dave Comeau
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roy, thanks for the explanation.
Everything I've read about beans was very confusing, but I think I'm starting to understand.
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem in starting to learn JSP and servlets without having java background, is that it is very confusing at the beginning.
Java Beans are regular java classes that have to have a default no argument constructor, and set and get methods for all their properties. thats it !
the Java Bean is just a normal class in essence.
hope it helps.
 
Dave Comeau
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So a class I create in a bean can not have any args passed to it's constructor. Got it.
I also have to name any getter/setter methods as get ot set. Got it.
Are there any conventions regarding whether classes defined in a bean need to be public or private?
It also looks like you can just convert any class by declaring a BeanInfo class to define the bean? Since I'm just starting, I'll go with standard bean convention.
Thanks again Roy. I'm excited to dive in, I'm just trying to get a grip on all this terminolgy first, and most docs assume a level of knowledge I have yet to know.
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no problem, glad to help

a Bean is a java class itself. (just a fancy name for a java class that follows the conventions you mentioned).
and any class that follows those conventions can be called a bean. you dont even need the BeanInfo stuff if you dont want to. it only helps the use of the bean in visual environments.
dont get too confused with the terminology. just treat the bean as a regular class you write.
I think Sun made a mess of all these terminology...
 
Dave Comeau
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree on the verbose terminology, it's quite daunting to someone who is trying to sort it all out.
Things seem much clearer now. I think I can get started and let the real confusion begin
 
    Bookmark Topic Watch Topic
  • New Topic