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

Can anyone know if there are tools/apps for representing the objects/classes/methods in the JVM in pictorial way?
rational rose and ibm software architect can be used for design and representation
Raghavendra Reddy
0 0
7
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
What are the most important topics in Java interviews for a fresher?
OOPS Multithreding String Handling Execption Handling Collection Freamwork JDBC Servlet Jsp Spring core Moudle Spring MVC
Advaith
0 0
6
Is Java a better programming language than C++?
If you campareboth then java has an edge n many oppurtunities compared to c++
Coaching Center

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

Ask a Question

Related Lessons

Java : Compile-time Versus Runtime optimization
While designing and development, one should think in terms of compile-time and run-time.It helps in understanding language basics in a better way.Let's understand this with a question below : What...
S

Java 8 Predicates
In the previous lession, we have learnt how to use filters and collectors. In filter we have passed the condition to evaluate whether the object is eligible to be filtered or not. Code given below for...

Spring - Dependency Injection (DI)
Spring - Dependency Injection (DI) DI is a framework which provides loose coupling in code. Here loose coupling means no hard coding of the object. Instead of hard coding, we will be injecting these object...

Features Of Java
There is given many features of java. They are also known as java buzzwords. The Java Features given below are simple and easy to understand. i. Simple ii. Object-Oriented iii. Portable iv. Platform...

Class and Objects in Java
Class is a template or a blueprint which is used to describe an object. On other hand Object is a reference of a class which follows all the stuff written inside the class. How about taking the whole tour in the following video

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