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 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

Freelance Programmer

init()..i.e.,initialization method used for,in order to place code which need to be execute whenever first request is generated...like database connection opening code ,file open code,datamember intialization code etc...
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

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

View 10 more Answers

Related Questions

I am a fresher and I want to become a Java developer, so what is necessary to crack the Java interview ? 

Hi Dipesh, understand that Java is a kind of ocean. It is vast. For interview preparation, you can brush up your Core Java Concepts and OOPs concepts and understand how JAVA works and learn the java features...
Dipesh
How to find a good Java coaching centre?
Its all depends on the trainer and his expertise. I would suggest you to get feedback from the students who already joined.
Abirami
1 0
6
What are the different types of Exceptions in Java?
Main two types 1. Compile time exception ex: FileNotFound Exception,ClassNotFound Exception. 2. Run time exception ex: ArrayIndexOutOfBounds Exception,IllegalTypeException,NullPointer exception,Arithmetic...
Aakanksha
Hi , this is Mithun Ghosh from Kolkata. I want a suggestion about the course content of teaching Java starting from core to Advanced level. Please anyone do help with a legible course content. Thanks in advance -- Thanks & Regards, Mithun Ghosh
Hi Mithun, This is AkiraITSolutions, We do provide real time training with real time employees, who ever having more than 10 years of IT Experience. For further details please feel free to reach us.
Mithun Ghosh
Hi, Can anyone help me on below queries? 1. What makes a class as "Thread safe class" ? 2. equals() method uses 3. Difference between String vs StringBuffer ?
There are three ways to construct thread-safe Java class which has some state: 1. Make it truly immutable 2.Make field volatile. 3.Use a synchronized block
Saurav

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

Ask a Question

Related Lessons

History Of Java
Java history is interesting to know. The history of java starts from Green Team. Java team members (also known as Green Team), initiated a revolutionary task to develop a language for digital devices such...
V

Android : Application Launch time improvements.
For any standard android application, below 3 components play important roles to show 1st interface to user, so that he/she can interact with the app. 1. Custom Application class : Intialize the components...

Differences Between HashMap vs HashSet In Java.
HashSet HashMap HashSet implements Set interface. HashMap implements Map interface. HashSet stores the data as objects. HashMap stores the data as key-value pairs. HashSet...

1.1. Reverse an array in Java.
public class Main { public static void main(String args) { int arr = {1, 2, 3, 4, 5}; for (int i = 0; i < arr.length / 2; i++) { int temp = arr; arr = arr; arr = temp; } System.out.println(Arrays.toString(arr)); }}

JAVA Online Training
What is Java? Java is a technology developed by James Gosling at Sun Microsystems, Sun Microsystems is now a part of Oracle Corporation. This is one of the most powerful & securable language used to...

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