Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
CUSTOMER_CODE SMUDE DIVISION_CODE SMUDE EVENT_CODE Oct2016 ASSESSMENT_CODE MIT103_Oct2016 QUESTION_TYPE DESCRIPTIVE_QUESTION QUESTION_ID 12944 QUESTION_TEXT List and explain the various features of Java. The various features of Java are: •Simple •Secure •Portable •Object-oriented •Robust SCHEME OF EVALUATION •Multithreaded •Architecture – neutral •Interpreted •High performance •Distributed •Dynamic Brief explanation of each feature (any 10) Marks: 1x10=10 QUESTION_TYPE DESCRIPTIVE_QUESTION QUESTION_ID 12945 QUESTION_TEXT Explain the following methods associated with the String object in Java. Give the syntax. i.toCharArray ii.regionMatches iii.compareTo iv.lastIndexOf v.trim SCHEME OF EVALUATION i.toCharArray Syntax: char [ ] toCharArray( ) – returns the String object into array of characters. ii.regionMatches Syntax: boolean regionMatches(int startIndex, String str2, int str2StartIndex, int numChars); or boolean regionMatches(boolean ignoreCase, int startIndex, String str2, int str2StartIndex, int numChars); Compares a specific region inside a string with another specific region in another string. There is an overloaded form that allows you to ignore case in such comparisons. iii.compareTo Syntax: int compareTo(String str); Here, str is the String being compared with the invoking String. The result of the comparison is returned and is interpreted as shown: Value 1.Less than zero 2.Greater than zero 3.Zero Meaning 1.Invoking string is less than str 2.Invoking string is greater than str 3.Two strings are equal iv.lastIndexOf() Syntax: int lastIndexOf(char ch); or int lastIndexOf(String str); Searches for the last occurrence of a character or substring. v.Trim Syntax: String trim(); Returns a copy of the invoking string from which any leading and trailing whitespace has been removed. (Marks: 2 x 5 =10) QUESTION_TYPE DESCRIPTIVE_QUESTION QUESTION_ID 72588 QUESTION_TEXT Write a Short note on following SWING components a. JRadioButton b. JOptionPane c. JComboBox d. JDialog e. JFrame SCHEME OF EVALUATION a. JRadioButton this class represents Swing radio buttons, By using radio buttons, you can select an option from a given list of mutually exclusive options. b. JOptionPane this class represents the option panes in Swing. Option panes are dialog boxes that displays some information to the user or get confirmation from the user so that the program can be executed further based on the choice the user makes. c. A Swing combo box is an enhancement over the AWT component called Choice. The Combo box is a pull down list with a capability to display the selected item in a display area. You can also enter an item in the display area to edit it into the list. d. This class represents the layered panes in Swing. Layered panes create the dimension along the depth of a component. You can position components on each layer of the layered pane. Swing applets and frame contain layered panes by default. e. This Class represents the Swing frame that is more sophisticated than the AWT frame; You can add components in layers, add a menu bar or paint over the component. (2 marks each) QUESTION_TYPE DESCRIPTIVE_QUESTION QUESTION_ID 120578 QUESTION_TEXT What is a package in Java? How do you define a package in Java? Explain the class member access permissions in Java. Java provides a mechanism for partitioning the class name space into more manageable chunks. This mechanism is the package. The package is both a naming and a visibility control mechanism. (1 Mark) Defining a Package: SCHEME OF EVALUATION Include a package command as the first statement in a Java source file. Any classes declared within that file will belong to the specified package. The package statement defines a name space in which classes are stored. If you omit the package statement, the class names are put into the default package, which has no name. The general form of the package statement: package pkg; Here, pkg is the name of the package For example, the following statement creates a package called MyPackage. package MyPackage; We can create a hierarchy of packages. To do so, simply separate each package name from the one above it by use of a period The general form of a multileveled package statement is : package pkg1[.pkg2[.pkg3]]; For example, a package declared as package java.awt.image; needs to be stored in java/awt/image, java\\awt\\image, or java:awt:image on your UNIX, Windows, or Macintosh file system, respectively. (4 Marks) Access Protection: (5 marks) QUESTION_TYPE DESCRIPTIVE_QUESTION QUESTION_ID 120579 Briefly explain the various constants and methods used in QUESTION_TEXT i. ii. i. SCHEME OF EVALUATION ActionEvent class AdjustmentEvent class ActionEvent Class: An ActionEvent is generated when a button is pressed, a list item is double-clicked, or a menu item is selected. The ActionEvent class defines four integer constants that can be used to identify any modifiers associated with an action event: ALT_MASK, CTRL_MASK, META_MASK, and SHIFT_MASK. In addition, there is an integer constant, ACTION_PERFORMED, which can be used to identify action events. (2 Marks ) ActionEvent has these three constructors: ActionEvent(Object src, int type, String cmd) ActionEvent(Object src, int type, String cmd, int modifiers) ActionEvent(Object src, int type, String cmd, long when, int modifiers) Here, src is a reference to the object that generated this event. The type of the event is specified by type, and its command string is cmd. The argument modifiers indicates which modifier keys (ALT, CTRL, META, and/or SHIFT) were pressed when the event was generated. The when parameter specifies when the event occurred. You can obtain the command name for the invoking ActionEvent object by using the getActionCommand( ) method, shown here: String getActionCommand( ) For example, when a button is pressed, an action event is generated that has a command name equal to the label on that button. (3 marks) ii. AdjustmentEvent class An AdjustmentEvent is generated by a scroll bar. The AdjustmentEvent class defines integer constants that can be used to identify them. (2 Marks) In addition, there is an integer constant, ADJUSTMENT_VALUE_CHANGED that indicates that a change has occurred. The constructor: AdjustmentEvent(Adjustable src, int id, int type, int data) src is a reference to the object that generated this event. The id equals ADJUSTMENT_VALUE_CHANGED The type of the event is specified by type, and its associated data is data. The getAdjustable( ) method returns the object that generated the event. The type of the adjustment event may be obtained by the getAdjustmentType( ) method. (3 Marks) QUESTION_TYPE DESCRIPTIVE_QUESTION QUESTION_ID 120581 a. What are the rules for overriding a method in Java? b. Write any three uses of Inheritance. QUESTION_TEXT a. 1. The method name and the order of arguments should be identical to that of the superclass method. 2. SCHEME OF EVALUATION The return type of both the methods must be the same. 3. The overriding method cannot be less accessible than the method it overrides. 4. An overriding method cannot raise more exceptions that those raised by the superclass. b. 1. Inheritance reduces redundancy in code. Code redundancy means writing the same code in different places, leading to unnecessary replication of code. Inheritance helps you to reuse the code. 2. Maintain code easily, as the code resides at one place. Any changes made to the superclass automatically change the behavior of the subclass. 3. Extend the functionality of an existing class by adding more methods to the subclass. (10 marks)