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

Is synchronized keyword necessary, in Java, if everything that is modified in a function is local to that function?
No, it is not required if you make sure whatever parameters are updated/modified will be done as atomic references/operations. Atomicity is an alternative to syncronizatiom.
Abishiek
0 0
6
Can you tell me some new features in JavaFX 2.0?
JavaFX is a software platform for creating and delivering desktop applications, as well as rich internet applications (RIAs) that can run across a wide variety of devices. JavaFX is intended to replace...
Renuka
0 0
5
What is the best site to learn Java for development?
https://beginnersbook.com/java-tutorial-for-beginners-with-examples/ This is the best website for Java beginners.
Chai
0 0
8
I am mechanical student. Can you please tell me opportunities in software field?
Yes, you can get an opportunity. I have seen many mechanical, chemical and biotechnology students are working in its sector. For that, you have to learn some IT courses.
Sainathgowd
How can I learn Java from home?
The best way to learn any technology is to: Step 1- Read in brief about the language from online source. Step 2- Understand basic syntax. Step 3- Take some mini project and start building from scratch...
Divya
0 0
5

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

Ask a Question

Related Lessons

Introduction to Course Content
Video about what we are going to learn throughout the Java Training Session .

JAVA Version History
Java Version History: There are many java versions that has been released. Current stable release of Java is Java SE 8. JDK Alpha and Beta (1995). JDK 1.0 (23rd Jan, 1996). JDK 1.1 (19th Feb, 1997). J2SE...
V

Java Overview
Java platform overview Java platform components The Java platform consists of the following components. The Java language Like any programming language, the Java language has its own structure, syntax...
A

Akshay Shende

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

Be prepared to get trained--init
Before starting the training,students must be mentally prepared for acceptance of new knowledge. Students must attend training with open minded forgetting the position they are working.This will help...
S

Smartnub Softsolutions

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