Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java Terms

Status
Not open for further replies.

scripter73

Programmer
Apr 18, 2001
421
US
Hi,

Relatively new to all of the naming conventions, etc to Java, although I've programmed in it previously.

So basically, is a "Java Servlet" just the same as a Java Class? And is a Java Bean roughly just an object?

If so, why are people giving "fancy names" to basic concepts. Just to sound smart? :)

Thanks for your help.

scripter73


Change Your Thinking, Change Your Life.
 
No, a Java Servlet is a special class that does internet interactions basically. A Java Bean is a special class that is a reusable component between different applications sort of like an ActiveX Object. An object is just an object and a class is the blueprint for that object, or basically the abstraction of an object. Hope that helps.

JavaDude32
 
I have to disagree here with JavaDude32 on some points ...

Both servlets and beans are both just plain old classes. An object is created when a Class is instantiated. Ie :

Class class = Class.forName("MyClass"); // here it is just s a class
MyClass mc = (MyClass)class.newInstance(); // the class is instantiated into an object.

Beans are given "fancy names" because they are written in a certain way. For example, this is a bean :
Code:
class MyBean {
   private String hello;
   public MyBean(){}
  
   public String getHello() {
      return this.hello;
   }

   public void setHello(String hello) {
      this.hello = hello;
   }
}

but this is not a bean :

Code:
class NotMyBean {
   private String hello;
   public NotMyBean(){}
  
   public String sayHello() {
      return this.hello;
   }

   public void makeHello(String hello) {
      this.hello = hello;
   }
}

The difference is theat beans must have "getters" and "setters" methods which correspond to their internal private variables (like above, getVariable() and setVariable()).

As JavaDude32 said, Servlets are used for coding classes that sit in a "servlet container" such as Tomcat, and which deal with HTTP connections. But they are still classses. What makes a "Servlet" is that it extends the HttpServlet class. Thats all really.

Hope this helps clear stuff up ...
 
Thanks to both of you. I'm still in the learning stages and this helps out.




Change Your Thinking, Change Your Life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top