S.E (Computer ) (Second Semester) EXAMINATION, Time : Two Hours Maximum Marks : 50

Similar documents
* Mrs. K.M. Sanghavi

Unit 4 - Inheritance, Packages & Interfaces

STRUCTURING OF PROGRAM

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Method Overriding in Java

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Pace University. Fundamental Concepts of CS121 1

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

An overview of Java, Data types and variables

CSC 1214: Object-Oriented Programming

String is one of mostly used Object in Java. And this is the reason why String has unique handling in Java(String Pool). The String class represents

Java Bytecode (binary file)

Introduction to Programming Using Java (98-388)

S.E. Sem. III [CMPN] Object Oriented Programming Methodology

Index COPYRIGHTED MATERIAL

5. PACKAGES AND INTERFACES

B2.52-R3: INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING THROUGH JAVA

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Introduction to Java Unit 1. Using BlueJ to Write Programs

AP Computer Science Unit 1. Writing Programs Using BlueJ

Fundamentals of Object Oriented Programming

Java Fundamentals (II)

.Net Technologies. Components of.net Framework

COMP 202 Java in one week

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

Language Fundamentals Summary

Chapter 7 Applets. Answers

CS260 Intro to Java & Android 03.Java Language Basics

CS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM

Object Oriented Programming and Design in Java. Session 2 Instructor: Bert Huang

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Java Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing

AP Computer Science Unit 1. Writing Programs Using BlueJ

1 Shyam sir JAVA Notes

Java Applets. Last Time. Java Applets. Java Applets. First Java Applet. Java Applets. v We created our first Java application

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

CS 11 java track: lecture 1

Sri Vidya College of Engineering & Technology

Module 5 Applets About Applets Hierarchy of Applet Life Cycle of an Applet

CSC 1051 Algorithms and Data Structures I. Midterm Examination March 2, Name:

data_type variable_name = value; Here value is optional because in java, you can declare the variable first and then later assign the value to it.

Brief Summary of Java

SPARK-PL: Introduction

1 Lexical Considerations

CSC Web Programming. Introduction to JavaScript

Program Fundamentals

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

JAVA: A Primer. By: Amrita Rajagopal

Operators and Expressions

9/7/17. Outline. Name, Scope and Binding. Names. Introduction. Names (continued) Names (continued) In Text: Chapter 5

Chapter 1: Introduction to Computers, Programs, and Java

S.No Question Blooms Level Course Outcome UNIT I. Programming Language Syntax and semantics

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements

Java Programming. Atul Prakash

Lexical Considerations

Introduction to Java (All the Basic Stuff)

Getting started with Java

CS321 Languages and Compiler Design I. Winter 2012 Lecture 2

Chapter 5 Names, Bindings, Type Checking, and Scopes

NOTE: Answer ANY FOUR of the following 6 sections:

Lecture 6. Assignments. Java Scanner. User Input 1/29/18. Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4

Selected Java Topics

A variable is a name for a location in memory A variable must be declared

Course Outline. Introduction to java

CS506 Web Design & Development Final Term Solved MCQs with Reference

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

1. Java is a... language. A. moderate typed B. strogly typed C. weakly typed D. none of these. Answer: B

UNIT II Structuring the Data, Computations and Program. Kainjan Sanghavi

2 rd class Department of Programming. OOP with Java Programming

History of Java. Java was originally developed by Sun Microsystems star:ng in This language was ini:ally called Oak Renamed Java in 1995

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 9: Writing Java Applets. Introduction

Programming In Java Prof. Debasis Samanta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

4 Programming Fundamentals. Introduction to Programming 1 1

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

Programming with Java

3. Java - Language Constructs I

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

Full file at

5/23/2015. Core Java Syllabus. VikRam ShaRma

Introduction to Java

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

AP CS Unit 3: Control Structures Notes

Mr. Monroe s Guide to Mastering Java Syntax

Contents 8-1. Copyright (c) N. Afshartous

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Computer Programming, I. Laboratory Manual. Final Exam Solution

PieNum Language Reference Manual

OBJECT ORİENTATİON ENCAPSULATİON

We now start exploring some key elements of the Java programming language and ways of performing I/O

Games Course, summer Introduction to Java. Frédéric Haziza

The Java programming environment. The Java programming environment. Java: A tiny intro. Java features

Properties of an identifier (and the object it represents) may be set at

Lexical Considerations

Computer Science is...

AP Computer Science Unit 1. Programs

Strings. Strings, which are widely used in Java programming, are a sequence of characters. In the Java programming language, strings are objects.

Introduction to Java Applications

Transcription:

S.E (Computer ) (Second Semester) EXAMINATION, 2017 PRINCIPLES OF PROGRAMMING LANGUAGE (2015 PATTERN) Time : Two Hours Maximum Marks : 50 N.B. :- (i) All questions are compulsory (ii)neat diagrams must be drawn wherever necessary. (iii) Figures to the right indicate full marks. (iv) Assume suitable data, if necessary. Q.No Question. Blooms Taxonomy CO Marking Scheme 1 (a) Draw and Explain the SDLC ( 6 ) Knowledge 5 Draw 2 Explain -4 (b) Distinguish named and structure type compatibility(3) Understand 2 Each correct points 1 (c) List & describe programming language qualities(3) Knowledge 1 List -1 Describe - 2 2 (a) Describe the String class & its methods in Java. (5) Knowledge 5 List-1 Explain 3 (b) (c) Differentiate between separate and independent compilation (4) Give and clarify the basic structure of PASCAL program(3) Understand 2 Understand 4 Each correct comparison 1 mark Structure -1 Clarification 2 3 (a) Write Java program for hierarchical inheritance (6) Create 5 Each Class- 1 Main Class- 3 (b) Explain dynamic method dispatch procedure with Explain -2 Example 2 Knowledge 5 suitable example. (4) (c) How to create and access package in Java? (3) Knowledge 5 Creation 2 Access- 1 4 (a) Write a program to input a string and raises a user defined exception if the string contains less than 8 characters. (8) (b) Describe the following attributes of <APPLET > tag i. codebase ii. Code iii width iv. Alt v. Param (5) Create 5 Knowledge 6 Input 2 Defining User defined Exception Class- 2 and Main Logic 4 Each Attribute 1 S.E (Computer ) (Second Semester) EXAMINATION, 2017 PRINCIPLES OF PROGRAMMING LANGUAGE (2015 PATTERN) Time : Two Hours Maximum Marks : 50 N.B. :- (i) All questions are compulsory (ii)neat diagrams must be drawn wherever necessary. (iii) Figures to the right indicate full marks. (iv) Assume suitable data, if necessary. Q.No Question. Blooms Taxonomy CO Marking Scheme 1 (a) Draw and Explain the SDLC ( 6 ) Knowledge 5 Draw 2 Explain -4 (b) Distinguish named and structure type compatibility(3) Understand 2 Each correct points 1 (c) List & describe programming language qualities(3) Knowledge 1 List -1 Describe - 2 2 (a) Describe the String class & its methods in Java. (5) Knowledge 5 List-1 Explain 4 (b) (c) Differentiate between separate and independent compilation (4) Give and clarify the basic structure of PASCAL program(3) Understand 2 Understand 4 Each correct comparison 1 mark Structure -1 Clarification 2 3 (a) Write Java program for hierarchical inheritance (6) Create 5 Each Class- 1 Main Class- 3 (b) Explain dynamic method dispatch procedure with Explain -2 Example 2 Knowledge 5 suitable example. (4) (c) How to create and access package in Java? (3) Knowledge 5 Creation 2 Access- 1 4 (a) Write a program to input a string and raises a user defined exception if the string contains less than 8 characters. (8) (b) Describe the following attributes of <APPLET > tag i. codebase ii. Code iii width iv. Alt v. Param (5) Create 5 Knowledge 6 Input 2 Defining User defined Exception Class- 2 and Main Logic 4 Each Attribute 1

Q.1 a) SDLC consists of following activities: 1. Planning: The most important parts of software development, requirement gathering or requirement analysis are usually done by the most skilled and experienced software engineers in the organization. After the requirements are gathered from the client, a scope document is created in which the scope of the project is determined and documented. 2. Implementation: The software engineers start writing the code according to the client's requirements. 3. Testing: This is the process of finding defects or bugs in the created software. 4. Documentation: Every step in the project is documented for future reference and for the improvement of the software in the development process. The design documentation may include writing the application programming interface (API). 5. Deployment and maintenance: The software is deployed after it has been approved for release. 6. Maintaining: Software maintenance is done for future reference. Software improvement and new requirements (change requests) can take longer than the time needed to create the initial development of the software. There are several software development models followed by various organizations: Waterfall Model: This model involves finishing each phase completely before commencing the next one. When each phase is completed successfully, it is reviewed to see if the project is on track and whether it is feasible to continue. V-Shaped Model: This model focuses on the execution of processes in a sequential manner, similar to the waterfall model but with more importance placed on testing. Testing procedures are written even before the commencement of writing code. A system plan is generated before starting the development phase. Incremental Model: This life cycle model involves multiple development cycles. The cycles are divided up into smaller iterations. These iterations can be easily managed and go through a set of phases including requirements, design, implementation and testing. A working version of the software is produced during the first iteration, so working software is created early in the development process.

Q.1 b) S.No Name Type Compatibility Structure Type Compatibity Name type compatibility ( name equivalence ) means that two variables have compatible types Type compatibility by structure ( structural equivalence) means that two 1 if variables have compatible types if their 1. They are defined in the same declaration types have identical structures. 2. They are defined in declarations that uses the same type name. 2 Easy to implement but highly restrictive More flexible, but harder to implement Subranges of integer types are not compatible with integer types. 3 4 Example : int x,a; x and a both are name equivalent as both are of type integer With structural type compatibility, you cannot differentiate between types of the same structure (e.g. different units of speed, both float) Example : type s1 is struct type s2 is struct { { int y; int w; int y; int w; ; ; In above s1 and s2 are structure equivalent 5 Pascal is Name Compatible C is Structure equivalent Q.1 c) Programming language qualities are : 1. Reliable (no failure) 2. Maintainable (new requirements be easily added..or modified) 3. Efficient (speedy and less space) 1. Reliability is achieved by. Writability : Higher-level languages are more writable than low-level Readabililty: Provision of adding new operations and data types easily enhances readability Simplicity: Allow algorithms to be expressed easily, Eg. Pascal is simpler than C++ but less powerful Safety : If language provides no features that make it possible to write harmful programs.. like goto then its safe Robustness: Ability to deal with undesired events like arithmetic overflow. 2. Maintainability is achieved by. a. Factoring : The language should allow programming to factor related features into one single unit. b. Locality : The effect of language feature is restricted to small local portion of the entire program otherwise if it extends to most of the program the task of making the changes can be exceedingly complex.\ 3. Efficiency earlier was measured by execution speed and space Now-a-days we can measure it by combined quality of language and its implementation If a language does not allow optimization it may adversely affect efficiency

Q.2 a) Java String Class and its methods Ans. String is nothing but a sequence of characters, for e.g. Hello is a string of 5 characters. In java, string is an immutable object which means it is constant and cannot be changed once it has been created. Creating a String : There are two ways to create a String in Java 1. String literal 2. Using new keyword 1. String literal In java, Strings can be created like this: Assigning a String literal to a String instance: String str1 = "Welcome"; String str2 = "Welcome"; 2. Using New Keyword String str1 = new String("Welcome"); String str2 = new String("Welcome"); String Methods 1) char charat(int index): It returns the character at the specified index. Specified index value should be between 0 to length() -1 both inclusive. It throws IndexOutOfBoundsException if index<0 >= length of String. 2) boolean equals(object obj): Compares the string with the specified string and returns true if both matches else false. 3) int compareto(string string): This method compares the two strings based on the Unicode value of each character in the strings. 4) boolean startswith(string prefix): It tests whether the string is having specified prefix, if yes then it returns true else false. 5) int indexof(int ch): Returns the index of first occurrence of the specified character ch in the string. 6) int lastindexof(int ch): It returns the last occurrence of the character ch in the string. 7) String tolowercase(): Equivalent to tolowercase(locale. getdefault()). 8) String touppercase(locale locale): Converts the string to upper case string using the rules defined by specified locale. 9) int length(): It returns the length of a String. Q.2 b) S.No Separate Compilation Independent Compilation 1 The term separate compilation means compile units individually however their compilations are dependent of each other. Program units are compiled separately as well as their compilations are independent of each other. 2 Interface information is used to check the It does not need interface information to correctness of the interface between the parts. check the correctness. 3 It needs information of all program units It does not need any information of other 4 Ada, Modula-2, FORTRAN -90 supports separate compilation. program units. C, FORTRAN-77 supports independent compilation

Q.2 c) Every Pascal program must follow a basic structure. Below is the basic structure that every Pascal program must follow. PROGRAM ProgramName (FileList); variables here if necessary CONST (* Constant declarations *) TYPE (* Type declarations *) VAR (* Variable declarations *) (* Subprogram definitions *) FUNCTION FunctionName(variableList): VariableType; (* variables here if necessary *) BEGIN (* Some Code if necessary; *) (* FunctionName := some expression *) (* More Code if necessary; *) END; BEGIN (* Executable statements *) END. The program statement has the form Program ProgramName (FileList); The ProgramName is the name of the program. The FileList that are enclosed in parentheses in the program template are input and output. These are just there for form -- their presence means nothing. More file variables may be added to this list, but this has no meaning to the program. All declarations following the program statement (before any function or procedure declarations) are global to the entire program. A declaration is basically just a statement; For example: const FirstLetter='a'; This "declares" that the constant named FirstLetter is equal to lowercase 'a'. Type and Variable declarations can be a bit more complicated, but all declarations follow the same basic principle. You are outlining for the compiler what some part of the program is, or what it is equal to. The template above is not a legitimate pascal program. If you don't have any constants, types, or variables to declare, you should leave out the corresponding section. So, the above template, minus the unused sections, would give the following (working) program: program PROGRAMNAME; begin end.

Obviously, this program doesn't actually DO anything. It just starts up, then exits. But it illustrates the most basic building block you need for a working program. Q.3 a) class HierarchicalInheritance { void Display() { System.out.println("This is a content of parent class"); //A.java class A extends HierarchicalInheritance { void DisplayA() { System.out.println("This is a content of child class 1"); //B.java class B extends HierarchicalInheritance { void DisplayB() { System.out.println("This is a content of child class 2"); //HierarchicalInheritanceMain.java class HierarchicalInheritanceMain { public static void main(string args[]) { System.out.println("Calling for child class A"); A aob = new A(); aob.display(); aob.displaya(); System.out.println("Calling for child class B"); B obb = new B(); obb.display(); obb.displayb(); Q.3 b) Runtime Polymorphism or Dynamic method dispatch Dynamic method dispatch is a mechanism by which a call to an overridden method is resolved at runtime. This is how java implements runtime polymorphism. When an overridden method is called by a reference, java determines which version of that method to execute based on the type of object it refer to. In simple words the type of object which it referred determines which version of overridden method will be called.

When Parent class reference variable refers to Child class object, it is known as Upcasting Example class Game { public void type() { System.out.println("Indoor & outdoor"); Class Cricket extends Game { public void type() { System.out.println("outdoor game"); public static void main(string[] args) { Game gm = new Game(); Cricket ck = new Cricket(); gm.type(); ck.type(); gm=ck; //gm refers to Cricket object gm.type(); //calls Cricket's version of type Output : Indoor & outdoor Outdoor game Outdoor game Notice the last output. This is because of gm = ck; Now gm.type() will call Cricket version of type method. Because here gm refers to cricket object. Q.3 c) A java package is a group of similar types of classes, interfaces and sub-packages. Package in java can be categorized in two form, built-in package and user-defined package. There are many built-in packages such as java, lang, awt, javax, swing, net, io, util, sql etc. Advantage of Java Package Java package is used to categorize the classes and interfaces so that they can be easily maintained. Java package provides access protection. Java package removes naming collision. Simple example of java package The package keyword is used to create a package in java.

//save as Simple.java package mypack; public class Simple{ public static void main(string args[]){ System.out.println("Welcome to package"); How to compile java package $ javac -d directory javafilename For example $ javac -d. Simple.java The -d switch specifies the destination where to put the generated class file. You can use any directory name like /home (in case of Linux), d:/abc (in case of windows) etc. If you want to keep the package within the same directory, you can use. (dot). How to run java package program You need to use fully qualified name e.g. mypack.simple etc to run the class. To Compile: javac -d. Simple.java To Run: java mypack.simple Output:Welcome to package The -d is a switch that tells the compiler where to put the class file i.e. it represents destination. The. represents the current folder. How to access package from another package? import package.*; The import keyword is used to make the classes and interface of another package accessible to the current package. Example of package that import the packagename.* //save by A.java package pack; public class A{ public void msg(){system.out.println("hello"); //save by B.java package mypack; import pack.*; class B{ public static void main(string args[]){ A obj = new A(); obj.msg(); Output:Hello

Q.4 a) import java.util.*; class MyException extends Exception{ MyException(String str2) { str1 = str2; public String tostring(){ return ("Output String = "+str1) ; class CustomException{ public static void main(string args[]){ Scanner s1; try{ System.out.print( Enter a string : ); String str = s1.nextline(); int len = str.length(); if (len<8) throw new MyException( String less than 8 characters ); // I'm throwing user defined custom exception above catch(myexception exp){ System.out.println("Hi this is my catch block") ; System.out.println(exp) ;

Q. 4b) APPLET CODE = class file (file or URL) HEIGHT = pixels WIDTH = pixels [ CODEBASE = URL directory ] // [ ] square brackets indicate optional tags [ ALT = alternate text message ] [ ARCHIVE = names of JAR files ] [ ALIGN = alignment ] [ NAME = name for other applets on page ] [ HSPACE = pixel ] [ VSPACE = pixel ] > // notice all these instructions are enclosed withing the first applet tag [ < PARAM NAME = identifier VALUE = value > ] [ < PARAM NAME = identifier VALUE = value > ].......... [alternate HTML ] </ APPLET > WIDTH & HEIGHT Tags - specify the width and height of the applet in pixels CODE & CODEBASE Tags Applet code that will run in an HTML page is specified with the CODE tag. Example Code="X.class" // quotes can be left out on the class identifier but it is good HTML form to quote all attribute values The CODEBASE tag is used to specify an absolute path, a URL, or a relative path (relative to where the calling HTML file is located). The java class identifer is case sensitive and must end with the.class extension. PARAM Tag PARAM tags appear between the <APPLET> param tags </APPLET> This tag allows data to be passed from an HTML page to an applet on that page. <APPLET CODE = Thermostat.class WIDTH = 200 HEIGHT = 200 > < PARAM NAME = label VALUE = "My Excellent Thermostat" > // note quotes allow inclusion of spaces < PARAM NAME = scale VALUE = celsius > < PARAM NAME = increment VALUE = 2 > </ APPLET > An applet reading these values uses the NAME identifiers as parameters to the getparameter( ) method. (Going in, case is not significant.) The string value returned, (representing the VALUE assignment) however is case sensitive. ALT Tag The ALT tag provides an altenate text for browsers that know the tag but don't support applets.

1. < APPLET CODE = Thermostat.class WIDTH = 200 HEIGHT = 200 2. ALT = " Try another browser!" > 3. < /APPLET >