Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4608812
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:53:53+00:00 2026-05-22T00:53:53+00:00

I am a novice in Java World. How to avoid confusion over variable declaration

  • 0

I am a novice in Java World. How to avoid confusion over variable declaration in MVC pattern over same variable?

For Example,

In Servlet (Controller):

String firstName     = request.getParameter("firstname");
String lastName      = request.getParameter("lastname");

In Bean (Model):

private String firstname;
private String lastname;

public Person(String FirstName, String LastName) {
    setFirstName(FirstName);
    setLastName(LastName);
}

//Getter and Setter Methods
public String getFirstName() {
  return firstname;
}
public void setFirstName(String FirstName) {
  this.firstname = FirstName;
}
public String getLastName() {
  return lastname;
}
public void setLastName(String LastName) {
  this.lastname = LastName;
}

In DAO (Data Access Layer):

public void savePerson(String firstName, String lastName) {
    // Method statements
}

And in JSP (View):

${person.firstname} ${person.lastname}

My Questions/Confusion?

  1. What is the proper way of declaring same variable in different
    modules(controller,models,views,dao)? And how should I avoid confusion?

  2. Is there any conventions I have to follow while declaring variables in different
    modules?

  3. Should variables in Servlets and DAO be same? Should variables in Models/Bean
    be different from Servlet and DAO?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T00:53:54+00:00Added an answer on May 22, 2026 at 12:53 am

    In your servlet these would be method variables. That’s pretty fine.

    In your Model this works as a Model’s properties. That’s pretty fine, too.

    In view you are actually referring to Model’s properties, and not declaring any variable, whatsoever.

    In DAO, you are actually, persisting your Model.

    So, In Servlet/Controller this will be something more like this,

    Person p = new Person();
    p.setFirstName(request.getParameter("firstname"));
    p.setLastName(request.getParameter("lastname"));
    

    And in your DAO, it would be more like this,

    public void savePerson(Person person) {
        // Method statements
    }
    

    Hence, declaration only happens in Model. I hope it clears your confusion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm relatively novice when it comes to C++ as I was weened on Java
I am a novice in using the Esper event stream engine in Java. The
I am a novice programmer when it comes to Java, I have Java:How To
I am a novice software developer and have only developed a few Java based
I am a novice programmer in Java. I would like to know how important
could you please suggest me (novice in Android/JAVA) what`s the most efficient way to
I am a novice to android and java development. Currently, I got a small
I'm looking at some open source Java projects to get into Java and notice
am working on a java(tomcat) app. that sometimes writes to stdout. But I notice
Php novice. 1.Is there anything wrong with this PHP & MySQL code? include_once db_login.php

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.