UrbanPro

Learn Java Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Can u explain init() method is used in servlet for initialization then constructor also there for initializing variables.then what makes the difference between init() and default constructor in servlets?

Asked by Last Modified  

12 Answers

Learn Java

Follow 0
Answer

Please enter your answer

Using init() only advisable than default constructor because we cannot initialize servlet using constructor because servlets are not directly instantiated by javacode, instead container create instance and keep it in pool. Container create instance of servlet using Java reflection in presence of no...
read more
Using init() only advisable than default constructor because we cannot initialize servlet using constructor because servlets are not directly instantiated by javacode, instead container create instance and keep it in pool. Container create instance of servlet using Java reflection in presence of no argument constructor. Java Compiler not add default no argument constructor... more» read less
Comments

IIT BTech for Java, data structure and algorythm classes

Servlet implementation classes can have constructor but they should be using init() method to initialise Servlet because of two reasons, first you cannot declare constructors on interface in Java, which means you cannot enforce this requirement to any class which implements Servlet interface and second,...
read more
Servlet implementation classes can have constructor but they should be using init() method to initialise Servlet because of two reasons, first you cannot declare constructors on interface in Java, which means you cannot enforce this requirement to any class which implements Servlet interface and second, Servlet require ServletConfig object for initialisation which is created by container as it also has reference of ServletContext object, which is also created by container. read less
Comments

Java Trainer

servelt() cannot be called directly. Servlet will be instantiated implicitly by Servelt container, in this case we cannot provide initial values using constructor, hence we must go for init() method to initialize
Comments

Java Trainer

Serviet engine will call init() method to start life cycle process of Servlet. Init() will call default / no args constructor to initialize instance variables. Here init() helps Servlet to starts it's life cycle and constructor helps to create an object.
Comments

Both init() and constructors are used for initializing servlets but it's better to use init() because it receives "ServletConfig" parameter which can have data from "web.xml" and this has useful parameters need to initialize the servlet. However, even if you dont choose to use a parameterized constructor...
read more
Both init() and constructors are used for initializing servlets but it's better to use init() because it receives "ServletConfig" parameter which can have data from "web.xml" and this has useful parameters need to initialize the servlet. However, even if you dont choose to use a parameterized constructor , a default constructor will be called by default when the servlet ibject is created. So both are used. read less
Comments

Expert in java training and self development class of IT students

Using init() only advisable than default constructor because we cannot initialize servlet using constructor because servlets are not directly instantiated by javacode, instead container create instance and keep it in pool. Container create instance of servlet using Java reflection in presence of no...
read more
Using init() only advisable than default constructor because we cannot initialize servlet using constructor because servlets are not directly instantiated by javacode, instead container create instance and keep it in pool. Container create instance of servlet using Java reflection in presence of no argument constructor. Java Compiler not add default no argument constructor if the class has parameterized constructor. read less
Comments

Java Trainer with 6+ years of experience in big MNCs

init() method is more robust and broader in scope than the default constructor. init() is part of the servlet life cycle and required to be invoked once before taking any requests and its invoked by the container and it has access to ServletConfig as well. In contrast, default constructor can not take...
read more
init() method is more robust and broader in scope than the default constructor. init() is part of the servlet life cycle and required to be invoked once before taking any requests and its invoked by the container and it has access to ServletConfig as well. In contrast, default constructor can not take such parameters while initializing and its invoked everytime the instantiation happens. Hope it clears the difference. read less
Comments

Java tutor

Servlet implementation classes can have constructor but they should be using init() method to initialize Servlet because of two reasons, first you cannot declare constructors on interface in Java, which means you cannot enforce this requirement to any class which implements Servlet interface and second,...
read more
Servlet implementation classes can have constructor but they should be using init() method to initialize Servlet because of two reasons, first you cannot declare constructors on interface in Java, which means you cannot enforce this requirement to any class which implements Servlet interface and second, Servlet require ServletConfig object for initialization which is created by container as it also has reference of ServletContext object, which is also created by container. read less
Comments

Java tutor

Servlet implementation classes can have constructor but they should be using init() to innitilize servlet.
Comments

Enthusiast

init method can be overridden whereas we cannot override a constructor. If the we have to initialize then init method will be overridden
Comments

View 10 more Answers

Related Questions

will I get certificate
Better than certificate if you enroll with me you will get confidence and lot of practical knowledge...certifications dont matter after a period of time what really matters is your approach to a problem...
Sk.
Why is finally introduced in Java?
Finally is introduced in Java to do the code clean up or if you wants to perform some operation irrespective of whether the code throws an Exception or not.
Agastya
Is it really needed to do Java training before graduation, to get a job?
Yes, It's must to get better opportunities and to standard alone in IT field. Not only core Java but also learn Spring,Hinernat ,Struts. ANGULARJS add an advantage to get job easily.
Udaybhan
hat is java
Introduction to JAVA Programming concepts of Basic Java Language Features Data Types, Variables Control Statements OOPS Concepts Writing your own Java Classes Object...
Narendra
0 1
8

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

TestNG Annotations and its sequence
public class TestNGAnnotations { @BeforeMethod public void beforeM() { System.out.println("Before Method"); } @AfterMethod public void afterMethod() { System.out.println("After Method"); } @BeforeClass...
S

Sarthak C.

0 0
0

Basic Concepts of Web Designing
An introduction to domain names, web servers, and website hosting 1)What is the web? In a nutshell, the web is a whole bunch of interconnected computers talking to one another. The computers (on the...

ClassNotFoundException vs NoClassDefFoundError
ClassNotFoundException NoClassDefFoundError It is an exception and happens due to programmer’s mistake and can be recovered by updating the code. Thrown when an application tries...

Java Hash Map internal implementation
1.Hash Map internal implementation: In hash map it will create an array of table (to store the {Key,Value} pair) which is of type java.util.HashMap.EntryThe Entry object contains {hash, key, next, value}...
R

Use of Service Locator Pattern
If we want to reuse the java code that should be the best approach w.r.t re-usability, maintanence and saving time to concentrate on our own businbess logic/requirement. In the similar approach many patterns...
M

Recommended Articles

Before we start on the importance of learning JavaScript, let’s start with a short introduction on the topic. JavaScript is the most popular programming language in the world, precisely it is the language - for Computers, the Web, Servers, Smart Phone, Laptops, Mobiles, Tablets and more. And if you are a beginner or planning...

Read full article >

In the domain of Information Technology, there is always a lot to learn and implement. However, some technologies have a relatively higher demand than the rest of the others. So here are some popular IT courses for the present and upcoming future: Cloud Computing Cloud Computing is a computing technique which is used...

Read full article >

Designed in a flexible and user-friendly demeanor, Java is the most commonly used programming language for the creation of web applications and platform. It allows developers to “write once, run anywhere” (WORA). It is general-purpose, a high-level programming language developed by Sun Microsystem. Initially known as an...

Read full article >

Java is the most commonly used popular programming language for the creation of web applications and platform today. Integrated Cloud Applications and Platform Services Oracle says, “Java developers worldwide has over 9 million and runs approximately 3 billion mobile phones”.  Right from its first implication as java 1.0...

Read full article >

Looking for Java Training Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Java Training Classes?

The best tutors for Java Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Java Training with the Best Tutors

The best Tutors for Java Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more