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

Where can I get Python online training?
You can get many institutes in google which are providing online training.
Taranum
Should we learn DBMS and RDBMS without any Java training?
java or i can say any programming language is not required to learn DBMS or RDBMS
Karthik
0 0
6
What is difference between Multithreading and miltiprocessing?
It is simple to understand. You question itself contains the answer. Only the keynote is: A single processor/core of the cpu can execute single task at a time, not more than one task. And you should...
Milan
Is there any difference between Serializalble and Externalizable interface?
1. In case of Serializable, default serialization process is used. while in case of Externalizable custom Serialization process is used which is implemented by application. 2. JVM gives call back...
Vathsala
How many classes will it take to learn core Java?
25-35 . depends on the student's previous knowledge on any programming languages
Gene

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

Ask a Question

Related Lessons

Advance Java
1) Servlet • Basics of Servlet • Servlet Request • Servlet Collaboration • Servlet Config • Servlet Context • Attribute • Session Tracking • Event and Listener •...
A

Introduction to Programming Languages
What is a Programming Language? A programming language is a formal computer language or constructed language designed to communicate instructions to a machine, particularly a computer. Programming languages...

Software Development Training In Jaipur
Satyam Web Solution provides website designing &development and software designing &development training in Jaipur for various stream’s students. MCA 6 month Industrial Training/Internship B....

Example of DependsOnMethod in TestNG
public class dependsonM { @Test public void login() { System.out.println("login"); } @Test (dependsOnMethods = {"login"}) public void email() { //Intentionally I am failing this testcase Assert.assertTrue(false);...
S

Sarthak C.

0 0
0

Tips of learning Java Language/Other Programming Languages
1.You should know the basic concept: If we talk about programming languages so basic concept are same in all the high level languages. So you should know the basic concept firstly then you can easily understand...
I

ICreative Solution

0 0
0

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