Ignou Mca Mcsl-024 Solved Assignments-2011_2

  • View

  • Download

Embed Size (px)

Text of Ignou Mca Mcsl-024 Solved Assignments-2011_2

Course Code Course Titlle Assignment Number Assignment Marks Maximum Marks Last Date of Submission

: : : : : :

MCS-024 Object Oriented Technologies and Java Programming MCA (1)/024/Assign/2010 100 25% 15th October, 2010 (for July, 2010 session) 15th April, 2011 (for January, 2011 session)

There are eight questions in this assignment which carries 80 marks. Rest of 20 marks are for viva-voce. Answer all the questions. Also in your programs give appropriate comments to increase understandability. Please go through the guidelines regarding assignments given in the Program Guide for the format of presentation.

Question 1: a) What is Object Oriented Paradigm? Why Object Oriented Programming is preferred over structured programming. (5 Marks) Object-oriented programming (OOP) technique is merely a way of organizing programs, and it can be accomplished using any language. Working with a real object-oriented language and programming environment, however, enables you to take full advantage of object oriented methodology and its capabilities for creating flexible, modular programs and reusing code. Object-oriented programming (OOP) is a programming paradigm that uses "objects data structures consisting of data field and methods together with their interactions to design applications and computer programs. Programming techniques may include features such as data abstraction, encapsulation, modularity, polymorphism, and inheritance.

Object Oriented Programming V/s. Structured ProgrammingObject-oriented programming has taken the best ideas of structured programming and has combined them with several powerful concepts that allow you to organize your programs more effectively. When programming in an object-oriented fashion, you decompose a problem into its constituent parts. Each component becomes a self-contained object that contains its own instructions and data related to that object. We still maintain a resemblance of the one entry, one exit paradigm for control structures which is at the heart of structured programming. Objects are Heart of the Object Oriented Programming Language. Task-centric vs. Data-centric Structured Programming is Task-centric. Object Oriented Programming is Data-centric. Based On Structured programming is based around data structures and subroutines. Object oriented programming shifts primary focus to the data itself. Re-usability In Structured Programming we can not reuse of code, but in Object Oriented Programming we reuse of code. Information Hiding When we have ways to reuse our code through one way or other, we are also in need of some security regarding our source code. To protect it from unauthorized access/ alteration in object oriented programming, this is called Information Hiding. Example Structured Programming supported by languages such as C. Object Oriented Supported By languages such as VB, Java.

b) What is platform independence? Explain advantages of a programming language which is platform independent. (3 Marks) Platform Independence: Platform-independence is a programs capability of moving easily from one computer system to another. Java is compiled to an intermediate form called Java byte-code or simply byte code. A Java program never really executes immediately after compilation on the host machine. Rather, this special program called the Java interpreter or Java Virtual Machine reads the byte code, translates it into the corresponding host machine instructions and then executes the machine instruction. A Java program can run on any computer system for which a JVM (Java Virtual Machine) and some library routines have been installed. The second important part which makes Java portable is the elimination of hardware architecture dependent constructs. For example, Integers are always four bytes long and floating-point variables follow the IEEE 754.You dont need to worry that the interpretation of your integer is going to change if you move from one hardware to another hardware like Pentium to a PowerPC. You can develop the Java program on any computer system and the execution of that program is possible on any other computer system loaded with JVM. For example, you can write and compile the Java program on Windows 98 and execute the compiled program on JVM of the Macintosh operating system. The same concept is explained in Figure given below.

Java programs can run on any machine and operating system that support Java Virtual Machine as we are showing following figure where we have shown that a program after compiling converts into a byte code which is able to execute on any platform Windows/Linux/Macintosh.

c) Explain why Java is platform independent.

(2 Marks)

Platform independence is one of the most significant advantages that Java has over other programming languages, particularly for systems that need to work on many different platforms. Java is platform-independent at both the source and the binary level. At the source level, Javas primitive data types have consistent sizes across all development platforms. Javas foundation class libraries make it easy to write code that can be moved from platform to platform without the need to rewrite it to work with that platform. Platform-independence doesnt stop at the source level, however. Java binary files are also platform-independent and can run on multiple platforms without the need to recompile the source. At the binary level Java binary files are actually in a form called bytecodes. Bytecodes are a set of instructions that look a lot like machine code, but are not specific to any one processor.

Question 2: a) List different data types available in java. DataType available in Java are as following: Integer DataType Byte DataType Short DataType Int DataType Long DataType Floating DataType Double DataType Char DataType Boolean DataType (2 Marks)

b) What are different bitwise operators available in Java? Write a Java program to explain the use of bitwise operators. (6 Marks)Following are Bitwise operators.

Operator& | ^ > >>> ~ = >>>= x&=y x|=y x^=y

Use of bitwise OperatorsBitwise AND Bitwise OR Bitwise XOR Left shift Right shift Zero fill right shift Bitwise complement Left shift assignment (x = x > y) Zero fill right shift assignment (x = x >>> y) AND assignment (x = x & y) OR assignment (x + x | y) XOR assignment (x = x ^ y)

c) Explain the need of Unicode.

(2 Marks)

Unicode is a computing industry standard designed to consistently and uniquely encodes characters used in written languages throughout the world. The Unicode standard uses hexadecimal to express a character. For example, the value 0x0040 represents the Latin character A. The Unicode standard was initially designed using 16 bits to encode characters because the primary machines were 16-bit PCs. When the specification for the Java language was created, the Unicode standard was accepted and the char primitive was defined as a 16-bit data type, with characters in the hexadecimal range from 0x0000 to 0xFFFF. Because 16-bit encoding supports 216, (65,536) characters, which is insufficient to define all characters in use throughout the world, the Unicode standard was extended to 0x10FFFF, which supports over one million characters. The definition of a character in the Java programming language could not be changed from 16 bits to 32 bits without causing millions of Java applications to no longer run properly. To correct the definition, a scheme was developed to handle characters that could not be encoded in 16 bits. The characters with values that are outside of the 16-bit range, and within the range from 0x10000 to 0x10FFFF, are called supplementary characters and are defined as a pair of char values.

Question 3: a) What is an array? Explain how an array of variable size is defined in Java.

(3 Marks)

An array is a structure that holds multiple values of the same type, the length of an array is established when the array is created (at runtime). After creation, an array is a fixed-length structure. When a variable of an array type is declared, the size of the array is not identified, and the array object is not allocated. To allocate storage for an array, you can use the new operator to create an array object of a specific size. The following statement: char ch[]=new char[24]; creates a char array of length 24, the individual component variables of which can be referenced by ch[0], ch[1],.,ch[23]. The following statement creates an array of type Dice[] of length 6: Dice[] d= new Dice[6]; Array can also be allocated by specifying their initial values. For example, the following allocates a String array of length 7 that contains abbreviations for the days of the week: String days[]={sun, mon, tue, wed, thu, fri, sat}; The length of an array can always be found by appending Length to the name of the array. For example, days returns the integer 7 as the length of days[]. Alternate Array Declaration Syntax Arrays are declared by declaring a variable to be of an array type. For example, the following declares nums to the array of type int: int[] nums: the declaration can also be written as follows: int nums[]; You can place the brackets after either the type of the variable name.

b) Explain why main method in Java is always static.

(2 Marks)

The method is static because otherwise there would be ambiguity: which constructor should be called? Especially if your class looks like this: public class JavaClass { protected JavaClass(int x) { } public void main(String[] args) { } } The keyword static indicates that the method is a class method, which can be called without the requirement to instantiate an object of the class. This is used by the Java interpreter to launch the program by invoking the main method of the class identified in the command