Using constructor

i want to know how to use constructors to send variables
from one class(in file)to another class(in another file)
please i want code example for that

class A
  private int myInt = 2;
  public A()
    B classB = new B( myInt );
class B
  public B(int theNumber)
    System.out.println("Number is: "+theNumber);
}

Similar Messages

  • How to use constructor to create a null object?

    I am trying to extend java.sql.Timestamp class. However, I am not sure what to do with a null Timestamp object. The constructor of Timestamp always creates a valid Timestamp object. Anyone have any idea how to create a null object using constructor? Thanks.
    Julia

    when you create an object i.e., instantiate an object there are three steps that are followed behind the scene.
    1) Assign memory
    2) Allocate a reference
    3) constructor is called.
    Now there is no such thing as a null object as has been pointed out however in case you mean you just want to assign a null reference to a variable then you are not instantiating an object and not calling a constructor but you could simply do
    String sqlQuery = null;But keep in mind that the object has not been instantiated and neither initialized here. Constructors basically do the initialization.

  • Wats necessity to use constructors, in java

    i am new to java so wanted to now
    bout the necesity to use constructors in java.
    n also y java doesnt support distructors?? yes offcourse it has concept of garbage collector
    but whether user will come to know that the object which is not in use has been deleted?? if yes then how??

    99% of the time, Java's garbage collection should do everything you need it to do.
    The other 1% are usually things that use resources outside of the JVM, that need to be released (like a FileInputStream). In these cases, the object overrides the finalize() method, and when that method is called upon garbage collection, the FIS will call its own close() method, releasing any external resources.
    Note that even when objects implement finalize(), it's not to avoid a memory leak inside the JVM, but instead to avoid locking resources outside the JVM. So it's still not a problem with garbage collection in those cases.
    Edited by: endasil on Oct 23, 2007 9:43 AM

  • Abstract class method polymorphically using constructors?

    how can i have a method defined in an abstract superclass call a constructor of the actual class running the method?
    abstract class A {
    public List getMultple() {
    List l = new ArrayList();
    for (short i=0;i<4;i++) {
    l.add(this());//<obviously this breaks
    return l
    or something like that. A won't run this method, but its children will...and they can call their constructors, but what do i put here to do that?
    i've tried a call back. an abstract method getOne() in the superclass forces each child to define that method and in each of those i return the results of a constructor. that works fine.
    the problem is i want to abstract this method out of each of these children classes cause its the exact same in each one, just using a different constructor to get multiple of each in a list. so if i use this callback method, then i am not saving the number of methods in each class, so why bother at all?
    any ideas?

    I still say you are coming at it from the wrong angle. A super class is not the way to go. What you are doing sounds like something very similar to something I did not too long ago.
    My requirement was that I had tab delimited text files filed with data that I had to parse. Each line would be used to instantiate one object, so a particular file could be used to instantiate, for example, a thousand objects of the same class. There were different types of files corresponding to different classes to instantiate instances of.
    Here is the design I ended up using.
    An object of class DataTextFileReader is instantiated to parse the text file and generate objects. It includes code for going line by line, handling bad lines and generating objects and reports. The constructor:
    public DataTextFileReader(File inputFile, LineParser<T> theLineParser)LineParser is an interface with one method:
    public T read(String line);When you call a load() method of the DataTextFileReader, it does its thing with the aid of the LineParser's read method, to which each line is passed, and stores the generated objects in an ArrayList. This can be returned by using another method. There are other methods for getting the reports, etc.
    Obviously, the LineParser chosen needs to have code appropriate for parsing the lines in question, so you have to choose and instantiate the right one.
    I find this design to work well. I arrived at it after spending hours giving myself headaches trying to come up with a design where there was a superclass roughly equivalent to the DataTextFileReader mentioned above, and classes extending this that fulfilled the duty of the LineParsers mentioned above... rather like what you are trying to do now.
    I did not care for the solution at first because it did not give me the "Ah, I am clever!" sensation I was expecting when I finally cracked the problem using inheritance, but I quickly came to think that it was much better OOD anyway.
    The LineParsers mentioned above are essentially embodiments of the Factory pattern, and I would recommend you do something similar in your case. Obviously your "constructors" all have to be different, so you should make a separate class for each of those. Then you can put the code that performs the query and loops to create loads of objects in another class called something like DatabaseDepopulator, using appropriate generics as in my example. Really it is the same problem, now that I look at it.
    This will also result in better separation of concepts, if you ask me. Why should the class constructor know how to parse a database result query, much less perform the query? It has nothing to do with databases (I presume). That is the job of an interpreter object.
    As a final note, remember... 95% of the time you feel like the language won't let you do what you want, it is because you shouldn't anyway.
    Drake

  • Why create a String object no need to use constructor?

    If we create a Java String object, we will do:
    String s = "Hello";
    And we won't do:
    String s = new String("Hello");
    In API doc, String() constructor description says "Initializes a newly created String object so that it represents an empty character sequence. Note that use of this constructor is unnecessary since Strings are immutable."
    I am not sure how immutable is related to this??
    Also, I wonder if the compiler will convert
    String s = "Hello" to
    String s = new String("Hello");
    Thanks!

    String s = new String("Hello");
    This is a valid statement too..... But the compiler will not convert String s = "Hello" to String s = new String("Hello") as you suggested. The reason is that java has a sort of a String Bag. Everytime you do a String s = "Hello" it will check the bag and see if such a string already exists. If it does, it merely creates a pointer to it, because strings are immutable, it doesn't need to worry about others modifying that string. If the string doesn't exist then it creates the necessary memory for the string object and adds the reference to the bag.
    However, once you do a String s = new String("Hello") what you are saying to the compiler is, "Hey, don't check the bag just create the String." This is all fine and dandy, except that it increases the memory size of your program unnecessarily.
    V

  • Using constructors in JApplet for passing variables?

    Hello,
    Some how I could not figured out, how to pass some parameters to the JApplet by using the constructors. Some how none of the constructors are invoked when I run the JApplet. I have to run it without html. How can I solve this problem?

    public class K extends JApplet {
            //declared variables here
         public K() {
         public K(Data data) {
              System.out.println("******");
         public K(int kNo) {
                    System.out.println("******");
              setKNo(kNo);
         public K(String kP) {
                    System.out.println("******");
              setKP(kP);
         public K(String kP, int kNo) {
                    System.out.println("******");
              setKNo(kNo);
              setKP(kP);
            //init method works fine
         public void init() {
              this.setSize(500, 500);
              this.setBackground(Color.BLACK);
              this.setPreferredSize(new Dimension(500,500));
              printer = new Printer(this);
              panel = new Panel(this);
              panel.repaint();
              this.add(panel);
              this.setVisible(true);
           //Other Methods ....
    }* I tried to invoke all of the constructors, I added System.out.println("******"); to see if the constructors work fine but none of the overriden constructors were invoked. *

  • IllegalArgumentException when using Constructor expression in Named Query.

    I have the following JPQL-query:
    SELECT NEW se.callista.test.dto.EmployeeReportData(e.firstName, e.lastName, a.city, e.employmentPeriod.startDate) FROM Employee e JOIN e.address a ORDER BY e.lastName, e.firstNamewhere EmployeeReportData is a dto (not an entity). The query works fine when running it as a normal query. When I put it as a named query however, I get the following error message when trying to execute it: java.lang.IllegalArgumentException: Object: se.callista.test.dto.EmployeeReportData@10f9644 is not a known entity type.
    I can't find anything in the JPA-spec that says a named query cannot contain a constructor expression - am I missing something?
    Found the error. It works fine now :)
    Message was edited by:
    Sofia_Jonsson

    I had the same problem.
    It seems that the Entity class is not loaded by the JVM at the moment of calling createNamedQuerey(string).
    I've solved this problem by loading the entity class manually in the caller by calling "Class.forName(string)" and passing the entity's class name as a parameter.

  • How to use Constructor.newInstance(Object [] o)

    this is my code:
    Constructor[] theConstructors = c.getConstructors();
    for(int ii=0;ii<theConstructors.length;ii++)
    Object oArg[] = new Object[2];
    Integer integerX = new Integer(x);
    Integer integerY = new Integer(y);
    oArg[0] = integerX;
    oArg[1] = integerY;
    Class [] cAry =theConstructors[ii].getParameterTypes();
    try{
    o = theConstructors[ii].newInstance(oArg);
    }catch (InstantiationException aa){}
    catch (IllegalAccessException bb){}
    catch (IllegalArgumentException cc){}
    catch (InvocationTargetException dd){}
    and the class called UseCase(Object[] o)
    but the object can't create..is null ......why?

    but the object can't create..is null ......why?Because the constructor wants one parameter of the type Object[], but you give it two parameters of the types Integer.
    Change the following three lines accordingly:
    Object[][] oArg = new Object[1][2];
    oArg[0][0] = integerX;
    oArg[0][1] = integerY;- Marcus

  • JPQL, error when using constructor in query

    I have such query:
    sb.append("select new ibs.parliament.model.stateless.cd.helperobject.PersonWithAccessCount(p, sum(personCounters.count))");
    sb.append(" from Person p left join p.counter personCounters where personCounters.date>= :startPeriodDate and  personCounters.date<= :endPeriodDate");
    sb.append(" group by p.id");PersonWithAccessCount has fields for Person and count for sum result.
    @Entity
    public class Person{
        @OrderBy("date")
        @ManyToMany(fetch=FetchType.EAGER, cascade={CascadeType.ALL}, mappedBy="person")
        private List<PersonAccessCounter> counter;
    //other fields, getters and setters
    @Entity
    public class PersonAccessCounter {
         @Id
          @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.ALL})
         private Person person;
         @Id
         private Date date;
         private long count;
    //other fields, getters and setters
    public class PersonWithAccessCount implements Comparable<PersonWithAccessCount>{
         private Person person;
         private long count;
    //getters and setters
    }I get such error:
    org.apache.openjpa.kernel.jpql.ParseException: There is "," in symbol 82, but expected: ["."].
    82 is here: (p*,* sum(personCounters.count))
    What does it mean? Why this error happens, please, tell me.

    My query is:
            sb.append("select new ibs.parliament.model.stateless.cd.helperobject.PersonWithAccessCount(personCounters.person, sum(personCounters.count))");
         sb.append(" from PersonAccessCounter personCounters where personCounters.date>= :startPeriodDate and  personCounters.date<= :endPeriodDate");
         sb.append(" group by personCounters.person");I get this error:
    >
    Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: DB2 SQL Error: SQLCODE=-134, SQLSTATE=42907, SQLERRMC=BIOGRAPHY, DRIVER=3.50.152 {prepstmnt 1306676706
    SELECT t1.id, t1.accessCounter, t1.biography, t1.birthdayDate,
            t1.firstLetter, t1.firstName, t1.lastName, t1.lastUpdateDate,
            t1.medialogyUid, t1.patronymic, t1.portrait_id, t1.sourceUri,
            SUM(t0.count)
        FROM Parliament.PersonAccessCounter t0 INNER JOIN Parliament.Person t1
            ON t0.person_id = t1.id
        WHERE (t0.date >= ? AND t0.date <= ?) GROUP BY t1.id, t1.accessCounter,
            t1.biography, t1.birthdayDate, t1.firstLetter, t1.firstName,
            t1.lastName, t1.lastUpdateDate, t1.medialogyUid, t1.patronymic,
            t1.portrait_id, t1.sourceUri FETCH FIRST 10 ROWS ONLY
    [params=(Timestamp) 1988-10-15 17:19:16.734, (Timestamp) 2008-10-15 17:19:16.734]} [code=-134, state=42907]
    >
    This is problem field "biography".
            @Lob
         @Basic(fetch=FetchType.LAZY)
         @Column(nullable=false, length=100000)
         private String biography;I've annotated it as "LAZY field". Now, I'll try to make a query...(
    I've found this:
    SQL Reference for usage of VARCHARs greater than 255 bytes:
    A VARCHAR string with a maximum length that is greater
    than 255 bytes or any CLOB string is a Long String.
    Following indicates the contexts in which long strings cannot be referenced.
    A GROUP BY clause
    An ORDER BY clause
    A CREATE INDEX statement
    A SELECT DISTINCT statement
    A subselect of a UNION without the ALL keyword

  • Problem with string constructor when using byte array as parameter

    I am creating a string using constructor and passing byte array as parameter.This byte array i am getting from MessageDigest's digest() method,i.e. a hash value.
    The problem is when i iterate through byte array i can able to print all the values in byte array.But when i construct a string from that byte array and printing that string ,that is printing some unknown characters.
    I don't know whether i need to pass charsequence to the constructor and the type of charsequence.Can anybody help me?
    Thanks in advance

    Is there some problem today? I'm getting this sort of thing all over.
    I already told you and so did Kayaman. Don't. String is not a holder for binary data. You have to Base-64 encode it. If you don't you cannot reconstruct the original binary digest value, so putting it into a database is completely utterly and entirely pointless.
    Is that clear enough?

  • Keyevent used for setMnemonic show in editable jtextarea

    I don't know if this has been fix. I notice that if I used the setMnemonic to access a editable jtextarea, that the key I used is inserted into the jtextarea. After searching the web, I found nothing about this problem.
    So, I took the program from the java tutorial, MenuDemo.java and reproduct the same problem but setting the jtextarea to editable (output.setEditable(true). It happens everytime. Below is the MenuDemo.java with the change. By selecting t or b in the A Menu menu,then which ever t or b used will show up in the text area after the expected line displays. I am using 1.5 so this problem may have been fix.
    If anyone knows if it has or a work around, please let me know.
    Thanks
    Kevin
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.JMenu;
    import javax.swing.JMenuItem;
    import javax.swing.JCheckBoxMenuItem;
    import javax.swing.JRadioButtonMenuItem;
    import javax.swing.ButtonGroup;
    import javax.swing.JMenuBar;
    import javax.swing.KeyStroke;
    import javax.swing.ImageIcon;
    import javax.swing.JTextArea;
    import javax.swing.JScrollPane;
    import javax.swing.JFrame;
    * This class adds event handling to MenuLookDemo.
    public class MenuDemo extends JFrame
    implements ActionListener, ItemListener {
    JTextArea output;
    JScrollPane scrollPane;
    String newline = "\n";
    public MenuDemo() {
    JMenuBar menuBar;
    JMenu menu, submenu;
    JMenuItem menuItem;
    JRadioButtonMenuItem rbMenuItem;
    JCheckBoxMenuItem cbMenuItem;
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    //Add regular components to the window, using the default BorderLayout.
    Container contentPane = getContentPane();
    output = new JTextArea(5, 30);
    output.setEditable(true);
    scrollPane = new JScrollPane(output);
    contentPane.add(scrollPane, BorderLayout.CENTER);
    //Create the menu bar.
    menuBar = new JMenuBar();
    setJMenuBar(menuBar);
    //Build the first menu.
    menu = new JMenu("A Menu");
    menu.setMnemonic(KeyEvent.VK_A);
    menu.getAccessibleContext().setAccessibleDescription(
    "The only menu in this program that has menu items");
    menuBar.add(menu);
    //a group of JMenuItems
    menuItem = new JMenuItem("A text-only menu item",
    KeyEvent.VK_T);
    //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead
    menuItem.setAccelerator(KeyStroke.getKeyStroke(
    KeyEvent.VK_1, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription(
    "This doesn't really do anything");
    menuItem.addActionListener(this);
    menu.add(menuItem);
    menuItem = new JMenuItem("Both text and icon",
    new ImageIcon("images/middle.gif"));
    menuItem.setMnemonic(KeyEvent.VK_B);
    menuItem.addActionListener(this);
    menu.add(menuItem);
    menuItem = new JMenuItem(new ImageIcon("images/middle.gif"));
    menuItem.setMnemonic(KeyEvent.VK_D);
    menuItem.addActionListener(this);
    menu.add(menuItem);
    //a group of radio button menu items
    menu.addSeparator();
    ButtonGroup group = new ButtonGroup();
    rbMenuItem = new JRadioButtonMenuItem("A radio button menu item");
    rbMenuItem.setSelected(true);
    rbMenuItem.setMnemonic(KeyEvent.VK_R);
    group.add(rbMenuItem);
    rbMenuItem.addActionListener(this);
    menu.add(rbMenuItem);
    rbMenuItem = new JRadioButtonMenuItem("Another one");
    rbMenuItem.setMnemonic(KeyEvent.VK_O);
    group.add(rbMenuItem);
    rbMenuItem.addActionListener(this);
    menu.add(rbMenuItem);
    //a group of check box menu items
    menu.addSeparator();
    cbMenuItem = new JCheckBoxMenuItem("A check box menu item");
    cbMenuItem.setMnemonic(KeyEvent.VK_C);
    cbMenuItem.addItemListener(this);
    menu.add(cbMenuItem);
    cbMenuItem = new JCheckBoxMenuItem("Another one");
    cbMenuItem.setMnemonic(KeyEvent.VK_H);
    cbMenuItem.addItemListener(this);
    menu.add(cbMenuItem);
    //a submenu
    menu.addSeparator();
    submenu = new JMenu("A submenu");
    submenu.setMnemonic(KeyEvent.VK_S);
    menuItem = new JMenuItem("An item in the submenu");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(
    KeyEvent.VK_2, ActionEvent.ALT_MASK));
    menuItem.addActionListener(this);
    submenu.add(menuItem);
    menuItem = new JMenuItem("Another item");
    menuItem.addActionListener(this);
    submenu.add(menuItem);
    menu.add(submenu);
    //Build second menu in the menu bar.
    menu = new JMenu("Another Menu");
    menu.setMnemonic(KeyEvent.VK_N);
    menu.getAccessibleContext().setAccessibleDescription(
    "This menu does nothing");
    menuBar.add(menu);
    public void actionPerformed(ActionEvent e) {
    JMenuItem source = (JMenuItem)(e.getSource());
    String s = "Action event detected."
    + newline
    + " Event source: " + source.getText()
    + " (an instance of " + getClassName(source) + ")";
    output.append(s + newline);
    public void itemStateChanged(ItemEvent e) {
    JMenuItem source = (JMenuItem)(e.getSource());
    String s = "Item event detected."
    + newline
    + " Event source: " + source.getText()
    + " (an instance of " + getClassName(source) + ")"
    + newline
    + " New state: "
    + ((e.getStateChange() == ItemEvent.SELECTED) ?
    "selected":"unselected");
    output.append(s + newline);
    // Returns just the class name -- no package info.
    protected String getClassName(Object o) {
    String classString = o.getClass().getName();
    int dotIndex = classString.lastIndexOf(".");
    return classString.substring(dotIndex+1);
    public static void main(String[] args) {
    MenuDemo window = new MenuDemo();
    window.setTitle("MenuDemo");
    window.setSize(450, 260);
    window.setVisible(true);

    Yes your are correct. I forgot why I went to 1.5 but until better time come along and I can get a new computer, I will have to live with 1.4.2._06. But, it did fit my problem.

  • In Reply to : How to validate org.jdom.Document object using xsd: dvohra09

    Hi All
    I am creating org.jdom.Document object using constructor Document() and adding children using setRootElement(), setChildren() and addContent() methods. The children are objects of org.jdom.Element. If i want to validate the org.jdom.Document using xsd what i have to do. Thanks in anticipation.

    I tried the below code and it is always giving the
    Parsing fatal error : The markup in the document preceding the root element must be well-formed.
    But it is possible to validate the same Document object as right document after writing it onto xml file using XMLOutputter and parsing it using DOMParser
    Thanks in anticipation
    org.jdom.Document document;
    String documentString=document.toString();
    StringReader stringReader=new
    StringReader(documentString);
    SAXBuilder saxBuilder =new
    SAXBuilder("org.apache.xerces.parsers.SAXParser",true);
    saxBuilder.setFeature("http://xml.org/sax/features/vali
    ation",  true);
    saxBuilder.setFeature("http://apache.org/xml/features/v
    lidation/schema",  true);
    saxBuilder.setFeature("http://apache.org/xml/features/v
    lidation/schema-full-checking", true);
    //Set a error handler with
    setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
    saxBuilder.build(stringReader);

  • I want to make gImage Class extends Image and use Graphics2D

    Sorry, my english short...
    I want to make gImage Class extends Image and use Graphics2D
    I trying to do...
    make class gImage..
    extends Image class. (Inheritance)
    but Image class is abstract class..
    And I want to use gImage class same as Image class.
    I can't use constructor... because by Abstract calss...
    How do i?
    Help me.. plz...
    And I want to use Graphics2D at Applet Game, But not use Java JDK Plug-in...
    No Way?

    You need to use BufferedImage with 2D or RenderedImage with JAI.
    BufferedImage effectivley extends an Image so you can
    draw it to screen in paintCOmponent.
    I use an Extended JPanel to draw an image in a Panel with this.
    MArk

  • Extremely simple but baffling to me: Constructors.

    I haven't a clue what they are. I've read about them online and in the Java API, and I still have no idea what they are.
    My current understanding is this: a constructor is code dedicated towards defining how to treat a variable.
    But...I have to write two programs using constructors and I have no idea what to put in them. And in fact everything I've tried gives compiler errors. I'm sure all of you know the quiet desperation and frustration I'm feeling.
    Anyway, the assignments are:
    1) Create a class called Employee that includes three pieces of information as instance variables - a first name (type String), a last name (type String) and a monthly salary (double). Your class should have a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, set it to 0.0.
    Write a test application named EmployeeTest that demonstrates class Employee's capabilities. Create two Employee objects and display each object's yearly salary. Then give each Employee a 10% raise and display each Employee's yearly salary again.
    2) Create a class called Date that includes three pieces of information as instance variables - a month (type int), a day (type int), and a year (type int). Your class should have a constructor that initializes the three instance variables and assumes that the values provided are correct. Provide a set and a get method for each instance variable. Provide a method displayDate that displays the month, day, and year separated by forward slashes.
    Write a test application named DateTest that demonstrates class Date's capabilities.
    It all seems extremely vague, to me.
    For the first assignment I've got:
    public class Employee
         public String FirstName;
         public String LastName;
         public double Salary;
    Which I think is right. But all attempts to create a constructor that have failed...I don't even know what one does. It seems kind of absurd for my first two labs to be so simple, basically logic exercises, and this to be so mind-destroying.
    There's got to be an if/then to see if the salary inputted is negative, which is simple, no problem.
    But the set and get methods...there's no data inputted into this program, so what the hell is it setting and getting, and how would the syntax work?
    Like:
    public void setFirstName( String FirstName )
    FirstName = FirstName;
    Doesn't work. And I think it's because it refers to itself for its own definition, which is nonsense. But I can't figure out what's right.
    The second assignment is simpler, but it also makes no sense to me. The day, month, and year are not variables. And even if they are variables, the user doesn't input them only to have them displayed, right? So what is the assignment even asking for? This is all taken directly out of the book.
    Any help is appreciated. =/

    FuneralParlor wrote:
    I haven't a clue what they are. I've read about them online and in the Java API, and I still have no idea what they are.That's not a good sign.
    My current understanding is this: a constructor is code dedicated towards defining how to treat a variable.No. They initialize an object.
    When you buy a new XBox, you have to spend some time taking it out of the box, removing the packaging, and plugging the wires together. It's like that.
    But...I have to write two programs using constructors and I have no idea what to put in them. You don't necessarily need to put anything in them. Does your class require initialization on the objects created for it?
    And in fact everything I've tried gives compiler errors. I'm sure all of you know the quiet desperation and frustration I'm feeling.It sounds like you're trying random stuff, hoping something will work. Don't do that.
    Anyway, the assignments are:...
    >
    It all seems extremely vague, to me.It doesn't give you the answers, but it tells you how to do them. It's pretty specific.
    For the first assignment I've got:
    public class Employee
         public String FirstName;
         public String LastName;
         public double Salary;
    Which I think is right.Well, generally fields shouldn't be public; they should be private. Also, you're not following Java naming conventions. Fields should start with a lower-case letter ("firstName" not "FirstName").
    But all attempts to create a constructor that have failed...I don't even know what one does. It seems kind of absurd for my first two labs to be so simple, basically logic exercises, and this to be so mind-destroying.It's simple stuff. I find it hard to believe that you've read your textbook.
    I'll give you a hint. The assignment says:
    Your class should have a constructor that initializes the three instance variables. This means that the constructor will need to take arguments, so you can use the arguments's values to assign to the fields (instance variables).
    But the set and get methods...there's no data inputted into this program, so what the hell is it setting and getting,The assignment tells you exactly what's going to be invoking the setter and getter methods:
    Write a test application named EmployeeTest that demonstrates class Employee's capabilities. [etc]
    and how would the syntax work?
    Like:
    public void setFirstName( String FirstName )
    FirstName = FirstName;
    Doesn't work. And I think it's because it refers to itself for its own definition, which is nonsense. But I can't figure out what's right.Right. In this case, the parameter name is obscuring the field name. This is where the "this" keyword comes in handy:
    this.Firstname = Firstname;Your textbook and teacher should have mentioned this.
    The second assignment is simpler, but it also makes no sense to me. The day, month, and year are not variables. What do you mean they're not variables? The assignment clearly says to make them so.
    And even if they are variables, the user doesn't input them only to have them displayed, right? So what is the assignment even asking for? It's just a super-simplified example. You're right; it's worthless in terms of real-world practicality. It's just something pointless but simple for you to get practice with. Don't worry about it.

  • Constructor in jsp

    How do we define constrctor on jsp..?.Could pls reply to this topic

    in the scriplet ...u can use Constructor like java...
    bye

Maybe you are looking for