0% found this document useful (0 votes)
12 views39 pages

PPL QP Solution

The document is an examination paper for a course on Principles of Programming Languages, specifically focusing on Java and LISP. It includes various questions covering topics such as Java characteristics, string operations, constructors, garbage collection, command line arguments, and exception handling. The paper consists of 8 questions, each requiring detailed explanations and code examples.

Uploaded by

raniaghav07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
12 views39 pages

PPL QP Solution

The document is an examination paper for a course on Principles of Programming Languages, specifically focusing on Java and LISP. It includes various questions covering topics such as Java characteristics, string operations, constructors, garbage collection, command line arguments, and exception handling. The paper consists of 8 questions, each requiring detailed explanations and code examples.

Uploaded by

raniaghav07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 39
‘Total No. of Questions : 8] P-9114 SEATNo.: [Total No. of Pages : 3 s [6179]-239 S.E. (Computer Engineering) PRINCIPLES OF PROGRAMMING LANGUAGES (2019 Pattera) (Semester - IV) (210255) Time : 2% Hours) Instructions to the Sdidates: 7) AnswenOll 06 92, 0.3 or 4, 0.5 0 06, 0.7 or 08 2 Figiires to the right indicate full marks, BY Neattiagrarns must be drawn wherever necessary. 9 Mate gable assumption whenever neces. ~S a ‘[Max. Marks : 70 > 2 Q1) a) _jiBStify the meaning of each characteristic of fava in the statement "java 8 simple, architecture -neutral Reale, ..\interpreted and robust and secured programming language ’S> s [6] b) Define String in Java {Ging Fplain the following operations of class string in Java with exibale. 4GTo find the length of a string. 2. To compare two strings 3. EXcaction of character from a string [6] O ©) Define Constructor, Skipw the Bxample about overloading of default, parameterized, and Copy“constructors. NY «OR Q2) a) Write a program @'print the area of a circle by creating a class'named "Area’ having tw0'methods. First method named as. yoda takes the radius of the circle as a parameter and the second-tnelhod Hamed as get “Ate eure the area opeice, The rads ober the keyboard? & b) Explain the Garbage Collection concept ir Java Programming with code example, AOS (61 c) Explain command line arguments and variable length arguments in Java with an example. S [6] PTO. BY Other Subjects: www.pyqspot.com Q3) Q4) Q5) 6) a) Elaborate the significance of the keyword ” super "in Java. With code example of each case. vv [6] g b) Explain in brief the interface andpackage in Java with code examples.[6] c) Create a custom Exceptigiyclass. You need to consider two integer inputs that the \ust Supply, You will display the sum of the integers if and only ifthe sums less than 100. If it is not less than 100, throw your custon?exception (51 > & or a) Elabératé on the significance ofthe keyword " final” in java. With code exdnbple of Pach case 2 [6] b) pao Exception Handing mechanism in an [6] ©) Writ program to create interface A in a package in this interface we ‘two methods meth! and meth2. Implemefits this interface in another _.tlass named MyClass by mers package. (51 Ss a) Explaindifferent ways to ign in Java? With code example. gy Vv @ b) Explain the below metiods indetail i) Isalive O” i) Notify OR a) Explain the uses of is Alive() and join() me examples. [6] ») (61 0 (6) [6179]-239 2 Other Subjects: www.pyqspot.com Q7) a) Explain the features of LISP programming. [6] b) Explain the following Equality prédicates using a suitable example. [6] ES i) EQUAL Ss 2 EQ EQL Nos ¢ S ©) _ Explain thefollowiig number predicates usinga suitable example, (5] a ERE i GERORS’ ve in)” EVENP ¢ v) .ODDP & OR v Q8) a) Explain the following fanetiona waghgulta mS exarles. [6] w SX ) CARO eS) S i CDRO Yi ii) FIRSTQ W C Vv b) Describe Logical Pri sing. Enlist its features. Also, list the commonly used Lo; ogiainming languages. % fi V ©) Evaluate the follow’ i) (car (cdr “(12 3 4$))) (car (cdr “(a (Wee) d e))) ii) (car (cdr era 234567ED)))) x [6179]-239 2 oO EY Other Subjects: www.pyqspot.com Ani 1, Java is simple and small programming language Java is a simple programming language. Even though you have no programming background you can learn this language comfortably. The programmers who worked on C or C+ can learn this language more efficiently because the syntax of Java resembles with C and C-++In fact Java is made more clear and adaptable than C++. 2, Java is robust and secure Following are reasons that make Java more secured than other programming languages 1, Java does not support the concept of pointers directly. This makes it impossible to accidentally reference memory that belongs to other programs or the kernel. 2. The output of Java compiler is not executable code but it is a bytecode. The instructions of bytecode is executed by the Java Virtual Machine 0VM). That means JVM converts the bytecode to machine readable form, JVM understand only the bytecode and therefore any infectious code can not be executed by JVM. No virus can infect bytecode. Hence it is difficult to trap the internet and network based applications by the hackers, 3. In programming languages like C or C++ the memory management is done explicitly by the user. That means user allocates or deallocates the memory. Whereas in Java its automatically done using garbage collection, Thus user can not perform the memory management directly. 4, Ifan applet is executing in some browser then it is not allowed to access the file system of local machine. 3. Java is a platform independent and portable programming language Platform independence is the most exciting feature of Java program. That means programs in Java can be executed on variety of platforms. This feature is based on the goal - write once, run anywhere and at any time forever. Java supports portability in 2 ways - Java compiler generates the byte code which can be further used to obtain the corresponding machine code. Secondly the primitive data types used in Java are machine independent. 4. Ja can be compiled and interpreted Normally programming languages can be either compiled or interpreted but Java is a language which can be compiled as well as interpreted, First, Java compiler translates the Java source program into a special code called bytecode. Then Java interpreter interprets this bytecode to obtain the equivalent machine code. This machine code is then directly executed to obtain the output. 5. Java is a dynamic and extensible language This language is capable of dynamically linking new class libraries, methods and objects. Java also supports the functions written in C and C ++, These functions are called native methods. 6, Java is a designed for distributed systems BY, Other Subjects: www.pyqspot.com This feature is very much useful in networking environment. In Java, two different objects on different computers can communicate with each other. This can be achieved by Remote Method Invocation(RMI), feature is very much useful in client-server communication. Q1.b) Define String in Java programming. Explain the following operations of class string in Java with example.1. To find the length of a string. 2. To compare two strings 3. Extraction of character from a string. Ans String is a collection of characters. In Java String defines the object. We can make use of String to denote the collection of characters. Let us look at a sample program in which the string object is used in order to handle some text. String Literal In Java String can be represented as a sequence of characters enclosed within the double quotes. 1, Finding Length of String We can find the length of a given string using the method length(). Follo length() method for strings. 1g program shows the use of Java Program [Str_| Glass)str_lengthDeno fe public static void main (strin { char strJJ=("P'." ngthDemo.Java) args) 10". 1G", String S=new String(str); system.out.printIn("The string Sis "+3); ysten.out.printIn("the length of string is "+S. length ()}; system.out.print ("the string in character array is "; for(int i=0;ijavac str_lengthDeno.java D:\>java Str_lengthDeno The strings is PROGRAM The length of string is 7 The string in character array is PROGRAM Hy BY, Other Subjects: www.pyqspot.com 2. compare two strings Sometimes we need to know whether two strings are equal or not. We use method equals() for that purpose. This method is of Boolean type. That is, if two strings are equal then it returns true otherwise it returns false. The syntax is boolean equals(String Str); Java Program [StringCompareDemo. Java] class StringcompareDeno ~~ { public static void min(stringl] args) ii String strl=new Steing("INDIA") ; String str2=new String("india") ; Af (ste] equals (stx2)==true) ‘system.out.printin("\n The two strings are equal") ; (\nthe two strings are not equal"); 3. Extraction of character from a string. As we know that the string is a collection of characters. String class provides the facility to extract the character from the string object. There is a method called charAt(index) with the help of which we can extract the character denoted by some index in the array. For example String fruit=new String("mang. char eh; eh= fruit.charAt(2 ); System.out printin(ch); The output of above code fragment will be n because at the index position 2 of string object fruit the character nis present. EXO Other Subjects: www.pyqspot.com Ql.c) Define Constructor. Show the example about overloading of default, parameterized, and copy constructors. Ans: Constructor + Definition: The constructor is a specialized method for initializing objects. ‘+ Name of the constructor is same as that of its class name. In other words, the name of the constructor and class name is same. ClassTest { Class Name Test) ft 4 [body of constructor + } ‘+ Whenever an object of its associated class i created, the constructor is invoked automatically. ‘+ The constructor is called constructor because it creates values for data fields of class. Types of constructor:Default constructor Parameterized constructor Copy constructor 1. Default constructor : The default constructor is a constructor for which there are no arguments or parameters passed. For example EY Other Subjects: www.pyqspot.com Java Program public class Test { int @ Test() //no argument constructor { a0, } } class MainClass { public static void main(String argsll) { Test obj=new Test(); } 2. Parameterized construetor : The parameterized constructor is a constructor in which the parameters are passed to the constructor function, For example Java Program public cass Test { int Test(int x)//parameterized constructor { } } class Main public staticvoidnain (String args1]) { Test obj=new Test (10); } 3. Copy constructor Copy constructor is a kind of constructor which can be initialised object of the same class. This object is created already. The use of copy constructor is 1. To initialize one object from another object of same type. 2. The object can be passed as a parameter to the function, BY, Other Subjects: www.pyqspot.com 3. The copy of the object can be returned from the function, Syntax of copy constructor classname (const classname &obj) { // body of constructor } Example- [fatauesseconseunsannes: Program to read complex numbers and to copy it into another using copy constructor I class Complex { private double real, ings public Complex (double 1, double i) //parameterized constructor { thiscreal = 7 this.ing= ir } Complex (Complex q // copy constructor { Svstem.out .print1n("InvokinaCopy constructor:. EY Other Subjects: www.pyqspot.com void display() { systen.out.printin(real+ "+ "+ img + "My } } public class TestClass { Invoking Copy Constructor public static void main(stringl} args) { Complex objl = new Complex (10,20); Complex obj2 = new Complex (obj)? Complex 0bj3 = obj2: cbj3.crtisplay(): } } Invoking copy constructor... 10.0 + 20.04 Output Q2) a) Write a program to print the area of a circle by creating a class named ‘Area’ having two methods. First method named as 'setRadius' takes the radius of the circle as a parameter and the second method, named as get 'Area' returns the area of the circle. The radius of circle is entered through the keyboard? Ans: import java.util Scanner; class Area { private double radius; public void setRadius(double radius) { this.radius = radius; , public double getArea() { return Math.PI * radius * radius; BY, Other Subjects: www.pyqspot.com 4 } public class Main { public static void main(String[] args) { Scanner scanner = new Seanner(System.in); Area circleArea = new Area(); ‘System. out.print("Enter the radius of the circle: "); double radius = scanner.nextDouble(); circleArea.setRadius(radius); ‘System.out printin("Area of the circle: " + circleArea.getArea()); scanner.close(); } EY Other Subjects: www.pyqspot.com Q2) b) Explain the Garbage Collection concept in Java Programming with code example. Ans: + Garbage collection is a method of automatic memory management. * It works as follows, Step | : When an application needs some free space to allocate the nodes and if there is no free space available to allocate the memory for these objects then a system routine called garbage collector is called Step 2 : This routine then searches the system for the nodes that are no longer accessible from an external pointer. These nodes are then made available for reuse by adding them to available pool. The system can then make use of these free available space for allocating the nodes. + Garbage collection is usually done in two phases - marking phase and collection phase. + Inmarking phase, the garbage collector scans the entire system and marks all the nodes that can be accessible using external pointer. + During collection phase, the memory is scanned sequentially and the unmarked nodes are made free. Marking phase : For marking each node, there is one field called mark field. Each node that is accessible using external pointer has the value TRUE in marking field. Collection phase :During collection phase, all the nodes that are marked FALSE are collected and made free. This is called sweeping. There is another term used in regard to garbage collection called Thrashing. Example: public class GarbageCollectionExample { public static void main(String[] args) MyClass objl = new MyClass(); MyClass obj2 = new MyClass(); obj = null; System.ge(); 3 } class MyClass { public MyClass() { System.out.printIn("Object created"); a @Override protected void finalize() throws Throwable { System.out.printin("Object destroyed"); ' EY Other Subjects: www.pyqspot.com Q2) c) Explain command line arguments and variable length arguments in Java with an example. Ans: command line arguments + Using command line arguments we can provide the input to the program during the execution. + For example while executing the program testjava we can provide the command line argument like this - c\>jeve bast 10 20 Wand 20 are the command line arguments + The command line parameters can be read in an array of strings. For keeping track of total number of command prompt arguments a integer count can be maintained. Java Program[CommandDemo java] oe c ee statievoid main (string argsl]) ink 50; oY fering systen.out.printin(""\nfoLLowing are the strings entered at conmand prompt & ater length} oO steel]; ssi; eel < 2 simon \rthe total number ef argunents EXO Other Subjects: www.pyqspot.com variable length arguments + Java allows the method to use variable length arguments ie. allows t create the methods that can accept the arguments of length zero or multiple. This is called as varargs in Java. The varargs uses three dots after the data type. The syntax is as follows- Return type name_of_function(data type ... variable name) Following Java program illustrates the use of such variable arguments. Java Program class Test ( public static vold main(Stringft arg) Q3) a) Elaborate the significance of the keyword " super " in Java. With code example of each case. Ans: Super is a keyword used to access the immediate parent class from subclass. There are three ways by which the keyword super is used. Fig 481 Use of super Let us understand these uses of keyword super with illustrative Java programs. if Other Subjects: www.pyqspot.com 1. The super() is used to invoke the class method of immediate parent class. Java Program{B java) 2. The super() is used to access the class variable of immediate parent class. EY Other Subjects: www.pyqspot.com 3. The super() is used to invoke the immediate parent class constructor. class A { AD System.out printin("Constructor of Class A’); } class B extends A { 2) { System out printin("Constructor of Class B's b public static void main(String argsl]) Bobj-new BO; } } Constructor of Class A Constructor of Class B Output Q3) b) Explain in brief the interface and package in Java with code examples. Ans: Packages + Package is defined using a keyword package. + The syntax for declaring the package is package name of package * This package & defined at the beginning of the program. + The package statement defines the name space in which the classes are stored. If we omit the package then the default classes are put in the package that has no name. Other Subjects: www.pyqspot.com * Basically Java creates a directory and the name of this directory becomes the package name, + For example - In your program, if you declare the package as - package My. Package; here we must create the directory name My Package in the current working directory and the required classes must be stored in that directory. Note that the name of the package and the name of the directory must be the same. This name is case sensitive. + We can create hierarchy of packages. For instance if you save the required class files in the subfolder MyPkg3 and the path for this. subfolders C:\MyPkgl \MyPkg2\MyPkg3 then the declaration for the package in your java program will be ~ package MyPkg1.MyPkg2MyPkg3; Java Program[PackageDemo.Java] import My Package A; //rhe java cass A is referenced here by import statement class PackageDerno { Public Static void main(String args{!) throws NoClassDefFoundError t ‘A obj=new AQ; //creating an object ofclass A bj set_vaii(10} /Using the object of class A, the methods present obj display(); //in class A are accessed Z + Interface * The interface can be defined using following syntax access modifier interface name_of interface { return type method name 1(parameter1.parameter2,...parametern): return type method namel{parameteri,parameter®,...parametern); type static final variable name=value; * The access modifier specifies the whether the interface is public or not. If the access specifier is not specified for an interface then that interface will be accessible to all the lasses present in that package only. But if the interface is declared as public then it will be accessible t any of the class. * The methods declared wi the interface have no body. It is expected that these methods must be defined within the class definition. EY Other Subjects: www.pyqspot.com Java Program{InterfaceDemo java] class A implenents my interface HS public voidmy method (int §) { systen.out.printin(*\nThe value in the class A "¥i); } public void another_method() //Defining another method not deciared in interface { system.out.printIn("\nThisis another method in class a"); t ie class InterfaceDemo { public staticvoid main string args!) 1 HorR-obj=new Al) is also allowed ‘A obji=new Al; obj my_method(100); obj1. another, method); } y Q3) c) Create a custom Exception class. You need to consider two integer inputs that the user must supply, You will display the sum of the integers if and only if the sum is less than 100. If it is not less than 100, throw your custom exception Ans: // Custom exception class class SumTooLargeException extends Exception { public SumTooLargeException(String message) { super(message); / Main class public cla: CustomExceptionExample { public static void main(String[] args) { EY Other Subjects: www.pyqspot.com try { 1/ Get user inputs int num1 = getUserInput("Enter the first number: "); int num2 = getUserlnput("Enter the second number // Calculate the sum it sum = num + num2; 1/ Check if the sum is less than 100 if (sum < 100) { System.out.printin("Sum: " + sum); } else { throw new SumTooLargeException("Sum is too large!"); } } catch (SumTooLargeException e) { System.out printIn(e.getMessage()); // Helper method to get integer input from the user private static int getUserInput(String message) { Scanner scanner = new Scanner(System.in); ‘System.out.print(message); return scanner.nextInt(); EY Other Subjects: www.pyqspot.com Q4) a) Elaborate on the significance of the keyword " final" in java. With code example of each case. Ans: Use of Final Keyword The final keyword can be applied at three places + For declaring variables + For declaring the methods + For declaring the class Final Variables and Methods + A variable can be declared as final. If a particular variable is declared as final then it cannot be modified further, +A variable can be declared as final. If a particular variable is declared as final then it cannot be modified further, dass Test { final void fin) ‘ yetemoutprntin(\n Helo his fanction dedared using al) } » lass Test! extends Test { final void fin) ‘ yetemoutprintn'\n Helo, this another fieton’ + 2 Output D.\pjavac Testjava Testjava:10: fin) Test cannot override fun() in Test; overridden method final final void fung) 1eror Final Classes to Stop Inheritance If we declare particular class as final, no class can be derived from it. Following Java program is an example of final classes. BY, Other Subjects: www.pyqspot.com final class Test { void fun{) ‘Sytemoutprinin(\n Helo this fnction in base das 3 } dass Testl extends Test { final void fun() { ‘System.outprintin('n Hello, this another function’ Di } Test java:8: cannot inherit from final Test class Testl extends Test Output terror Q4) b) Explain various Exception Handing mechanism in java Ans: Handling try-eateh Block + The statements that are likely to cause an exception are enclosed within a try block. For these statements the exception is thrown. + There is another block defined by the keyword catch which is responsible for handling the exception thrown by the try block. + As soon as exception occurs it is handled by the catch block.The catch block is added try block. Refer fig, mediately after the try block Exception] Exception ‘causing | object statements] gets created here Tom ‘exception cea "| ach block ExCEREON| conten handing | hander statements 1) the method fun is for handling the exception divide by zero. This is an arithmetic exception hence we write static void fin(int aint) throws ArithmeticException This method should be of static type. 2 Also note as this method is responsible for handling the exception the try-catch block should be within fur. BY, Other Subjects: www.pyqspot.com Multiple eatch clause + It is not possible for the try block to throw a single exception always. ‘+ There may be the situations in which different exceptions may get raised by a ty block statements and depending upon the type of exception thrown it must be caught. + To handle such situation multiple catch blocks may exist for the single uy block statements. = of fexceptionoccurs if catch (Exception type e) { s-lfexception is handled here » catch (Exception type e { snd/exception ishandled here > catch (Exception type e { wo/fexception is handled here Nested try Statements + When there are chances of occurring multiple exceptions of different types by the same set of statements then such situation can be handled using the nested ty statements, BY, Other Subjects: www.pyqspot.com ¢) Write a program to create interface A in a package; in this interface we have two methods meth! and meth2. Implements this interface in another class named MyClass by importing your package. Ans: First, create the interface A in a package named mypackage: package mypackage; public interface A { void meth1(); void meth2(); } Then, create a class MyClass which implements the interface A: package mypackage; public class MyClass implements A { @Override public void meth1() { ‘System.out.printIn("Inside meth 1() method"); } @Override public void meth2() { System.out.printin("Inside meth2() method"); , public static void main(String{] args) { MyClass obj = new MyClass(); obj.meth1(); obj.meth2(); i . Inside meth1() method Inside meth2() method EY Other Subjects: www.pyqspot.com Q5) a) Explain different ways to implement Threads in Java? With code example. An Creating Multiple Threads using Alive() and join() ‘There are two methods that are commonly used while handling more than one thread in the Java program and these methods are isAlive() and join(). The purpose of these two methods is to check whether a thread has finished its execution or not. The isAlive() Method Syntax public final boolean isAlive() Java Program public class ThreadDemo extends Thread { public void run() { ‘System out printin(‘Begin’); uy { ‘Thread sieep(600); } catch(InterruptedException ie) { } ‘System.out.printin("End’); + public static void main(String|} args) { ‘ThreadDemo tl =new ThreadDemo(); ‘ThreadDemo t2=new ThreadDemo(); tH.start( ‘System.out.printin(‘Is Thread! alive? "+11 isAlive()); ‘System.out.printin(‘Is Thread? alive?" +12.isAlive()); t2start(); ‘System out printin(‘Now Is Thread2 alive?" +t2.isAlive()); BY, Other Subjects: www.pyqspot.com The join() Method ‘This method waits until the thread on which it is called terminates. Syntax {inal void join() throws InterruptedException Using join method, we tell our thread to wait until the specified thread completes its execution, Java Program public class ThreadDemo extends Thread. { public void run() { ‘System out printin('Begin"); try { ‘Thread sleep(500); , catch(InterruptedException ie) 1 , ‘System out printin(End’); } public static void main(String] args) { ‘ThreadDemo t1=new ThreadDemo(); ‘ThreadDemo t2=new ThreadDemo(); ‘System out printin(‘Starting first thread’); t.start); uy { 11 join()//waiting for t1 to finish , catch(InterruptedException ©) { + ‘System out printin('Starting another thread’); t2startt) Q5) b) Explain the below methods in detail i) Isalive Notify iii) GetPriority An EY Other Subjects: www.pyqspot.com 1) The isAlive() Method ‘Syntax public final boolean isAlive() Java Program public class ThreadDemo extends Thread { public void run() { System. out.printin(‘Begin’); try { ‘Thread sleep(600); } ccatch(InterruptedException ie) { } System out printin("End”); , Public static void main(String!) args) { ‘ThreadDemo t1 =new ThreadDemo(); ‘ThreadDemo t2=new ThreadDemo(); tstart(; ‘System out printin("Is Thread alive? "+1.isAlive()); System out printin("Is Thread2 alive?" +t2.isAlive()); t2start(; ‘System out printin('Now Is Thread alive?’ +t2.isAlive() This method is used to check if the thread is alive or not. This method returns true if thread is still running and not finished otherwise it returns false. ‘Syntax Public final boolean isAlive() ii) Not In Java, the notify() method is used in conjunction with wait() method to implement inter-thread communication. It’s part of the mechanism provided by Java for inter-thread communication in multi- threaded programs. EY Other Subjects: www.pyqspot.com Here's a breakdown of how notify() works: 1. Ownership: notify() method is called on an object which is also the lock owner. This means that the notify() method can only be called from a synchronized block or method, where the object's intrinsic lock (mutex) is held. 2. Notifying Threads: When notify() is called, it notifies one of the threads that are waiting on the object's monitor. Which thread gets notified is not defined and depends on the scheduler's decisior 3. Waking up Threads: The notified thread is awakened from the wait set associated with the obje. monitor. However, just being notified doesn’t guarantee that the thread will proceed immediately. It's merely marked as eligible to be run by the scheduler. 4, Continuation: Once the thread receives the notification and regains the lock on the object, it can continue its execution from the point where it was paused. GetPriority The priority_val is a constant value denoting the priority for the thread. It is defined as follows - o MAX_PRIORITY = 10 © MIN_PRIORITY = 1 © NORM_ PRIORITY =5 * The function getPriority is used to get the priority of the thread. Thread_Name getPriority(); + Preemption © Preemption is a situation in which when the currently executed thread is suspended temporarily by the highest priority thread. © The highest priority thread always preempts the lowest priority thread. Q5) c) List the Features, advantages and limitations of Vue JS Ani Features of VuedS 1) Components : This feature allows the web developer to create custom elements which can be reused in HTML. 2) Event Handling : Any event can be handled using VueJS script with the help of v- onattribute. 3) Data Binding : This feature helps to manipulate or assign values to HTML attributes or change the style. 4) Animation : Vue JS helps to show animation of the elements on the web page. 5) Computed Properties : This is a feature that can immediately sense the changes made in the UI and make necessary actions, There is no need to perform additional coding for that. EY Other Subjects: www.pyqspot.com 6) Ligheweight and Efficient : The Vue JS is very light weight and efficient JavaScript framework. Advantages: 1. Simplicity and Ease of Learning: Vue,js is designed to be approachable and easy to learn, even for developers who are new to front-end development. Its syntax is simple and intuitive, making it easy to pick up and use. 2. Flexibility: Vue,js is highly adaptable and allows developers to use it in various ways, whether it's building a small widget or a full-fledged single-page application. It can be integrated into existing projects without much hassle. Component-Based Arc encourages building UI in be easily composed and reused across different parts of an application, leading to cleaner and more maintainable code. 4. Reactivity: Vue.js provides a reactivity system that makes it easy to manage the state of your application and automatically update the DOM when the state changes. This simplifies data binding and ensures that the UI always reflects the current state of the application. 5. Performance: Vue,js is known for its performance optimizations, such as virtual DOM and efficient re-rendering strategies, which help to ensure smooth and responsive user interfaces, even for complex applications. 6. Growing Ecosystem: Vue,js has a vibrant ecosystem with a wide range of libraries, tools, and plugins that extend its functionality and provide solutions for common tasks, such as routing, state management, and form validation. Limitation: Maturity and Ecosystem Size: While Vue.js has grown rapidly in popularity, it may not have the same level of maturity or ecosystem size as some other frameworks like React or Angular. This could mean fewer third-party libraries, tools, and resources available compared to more established frameworks. 2. Less Corporate Backing: Vue.js is maintained by a smaller core team compared to some other frameworks, and it may not have the same level of corporate backing or support. This could potentially affect the long-term stability and sustainability of the framework. 3. Learning Curve for Advanced Features: While Vue.js is easy to get started with, mastering some of its more advanced features, such as custom directives or render functions, may require a deeper understanding of the framework and its underlying concepts. 4, Limited Tooling Support: While Vue.js has a growing ecosystem of tools and plugins, it may not have the same level of tooling support as more established frameworks. This could mean fewer options for debugging, testing, or performance profiling compared to other frameworks. 5. Community Size: While the Vue.js community is growing rapidly, it may not be as large or active as the communities around other frameworks like React or Angular. This could mean fewer resources, tutorials, or community support available for developers. BY, Other Subjects: www.pyqspot.com Q6) a) Explain the uses of is Alive) and join() methods in the java thread with examples. An: The isAlive() Method This method is used to check if the thread is alive or not. This method returns true if thread still running and not finished otherwise it returns fals ‘Syntax public final boolean isAlive() Java Program public class ThreadDemo extends Thread { public void run() { ‘System out printin("Begin’); ty { ‘Thread sleep(600);, } ccatch(InterruptedException ie) { } ‘System out printin( End’); } public static void main(Stringl] args) { ‘ThreadDemo t1 =new ThreadDemo(); ‘ThreadDemo t2 =new ThreadDemo(); tstand; ‘System out printin(‘Is Thread! alive? "+41 isAlive(); ‘System.out printin(‘Ts Thread2 alive?" +12.isAlive()) t2stan); ‘System out printin("Now Is Taread2 alive? +t2.isAlive()); ‘The join() Method This method waits until the thread on which itis called terminates Syntax final void jin() throws InterruptedException Using join method, we tell our thread to wait until the specified thread completes its EY Other Subjects: www.pyqspot.com Java Program public class ThreadDemo extends Thread. { Public void run() { ‘System out-printin("Begin’); try { } ccatch(InterruptedException ie) { : ‘System out printin(End’), » ‘Public static void main(Stringl] args) { ‘ThreadDemo ti =new ThreadDemo(); ‘ThreadDemo t2=new ThreadDemo(); System out:printin( ‘Starting first threa t.start; uy 4 11join(.//waiting for t1 to finish + ccatch{InterruptedException e) { } ‘System out printin(‘Starting another thread); t2start(); Q6) b) Explain the thread life cycle model in Java. Ans: Introduction to Thread Definition of thread : Thread is a tiny program running continuously. It is sometimes called as light-weight process. Creating Thread ‘+ InJava we can implement the thread programs using two approaches - ‘© Using Thread class © sing runnable interface. EY Other Subjects: www.pyqspot.com Exends Implements “Thread Runnable (Class) {intertace) rund) method ‘1 : Creation of Java thread ‘+ The run0 method is the most important method in any threading program. By using this method the thread's behaviour can be implemented. The run method can be written as follows - public void rind) { statements for implementing thread y For invoking the thread's run method the object of a thread is required. This object can. bbe obtained by creating and initiating a thread using the start() method. ‘* Constructor of Thread Class : Following are various syntaxes used for writing the constructor of Thread Class. Thread’) ‘Thread\ String 5) ‘Thread(Runnable obj) ‘Thread(Runnable obj, String 8); * Various commonly used methods during thread programming are as given below - Method Purpose start) __The thread can be stared and invokes the run method run)___Once thread is started it executes in run method. setName() We can give the name to thread using this method. _getName()_ The name of the thread can be obtained using this name. join __This method waits for thread to end BY, Other Subjects: www.pyqspot.com Q6) c) Write a short note on React JS and Angular JS. Ans: React JS Let us start the introduction of ReactJS with a real-world example. Suppose that on a Facebook page, you click the “like” on some photograph and then by the time you scroll down the same page, the like count gets incremented by some number, even without reloading your Facebook page, This magic change happens because of out React}S! React} by Facebook, This library is responsible only for the view layer of the application. That means this JavaScript for building user interfaces. ed an open source, component-based front end JavaScript library maint Features of ReactJS * Virtual DOM : DOM stands for Document Object Model. It also provides a way to update the content, structure and style of the document. Virtual DOM is a representation of original DOM. When user updates something on the web application, DOM gets updated. Updating the DOM is very slow, most of the javascript frameworks update the whole DOM which makes it slower. But actually there is no need to update the whole DOM, instead, these frameworks should update only the part of DOM that is required to update. This is what the virtual DOM does. This is why React}S’s DOM manipulation is much faster than other frameworksDue to this property, whenever any change is made in the web application, then those changes are reflected on the web page within no time. ‘* Components : This feature allows the web developer to create custom elements which can be reused in HTML. ‘+ JSX: JSX is an extension of JavaScript syntax. JSX can be seen as a combination of javascript and XML. The syntax of JSX is very simple that makes writing ‘components very easy. Angular JS ‘© Angular JS is a powerful JavaScript framework. ‘ Itis an open source front-end enabled web application framework. ‘It islicensed under Apache license version 2.0. ‘+ It extends HTML DOM with additional attributes. It is more responsive to user actions. BY, Other Subjects: www.pyqspot.com Features of Angular JS There are core features Angular JS that are widely used by web developers. These are - 1. Data Binding : It allows the automatic synchronization between model and view components. 2. Scope : There are some objects from model that can be correlated to controller and. view. 3. Controller : These are basically JavaScript functions that are bound to particular scope. 4. Directives : The directives is designed to give HTML new functionality. 5. Filters : This feature allows to select subset from array of items. 6. Routing : This feature allows to switch between multiple views. 7. Services : There is a support for many built in services for Angular JS. 8. Dependency Injection : It is a software design pattern that helps the developer to develop and understand the application easily. Q7) a) Explain the features of LISP programming. Ans: LISP (LISt Processing) is one of the oldest programming languages, dating back to the late 1950s. It’ known for its unique features and powerful capabilities, many of which have influenced other programming Janguages. Here are some key features of LISP programming: 1, S-Expressions: LISP represents both data and code in the form of symbolic expressions, known as ‘S-expressions. An S-expression can be a symbol, a list of $-expressions, or an atomic value. This uniform representation allows for a simple and consistent syntax. 2. Homoiconicity: LISP is homoiconic, meaning that its code is represented in the same structure as its data. This allows programs to manipulate and generate code as if it were data, enabling powerful metaprogramming techniques such as macros. 3. Dynamic Typing: LISP is dynamically typed, meaning that variable types are determined at runtime rather than compile time. This flexibility simplifies coding and allows for rapid prototyping and development. 4. Garbage Collection: LISP typically features automatic garbage collection, which manages memory allocation and deallocation, freeing programmers from manual memory management tasks and reducing the risk of memory leaks. 5. Functional Programming: LISP supports functional programming paradigms, including first-class functions, higher-order functions, and lexical closures. Functions are treated as first-class citizens, meaning they can be assigned to variables, passed as arguments, and returned as values 6. Recursion: Recursion is a fundamental technique in LISP programming. LISP encourages recursive solutions to problems, and its simple syntax facilitates the implementation of recursive algorithm: 7. Symbol Manipulation: LISP provides powerful tools for manipulating symbols and symbolic expressions. This enables symbolic computation, symbolic differentiation, and symbolic algebra, making LISP suitable for tasks such as artificial intelligence and symbolic mathematics. EY Other Subjects: www.pyqspot.com 8. Interactive Development Environment: LISP environments typically provide an interactive development environment (REPL - Read-Eval-Print Loop) that allows developers to evaluate expressions, define functions, and interactively experiment with code. This facilitates exploratory programming and rapid iteration. 9. Macros: LISP macros allow developers to define domain-specific languages and extend the language itself. Macros transform code at compile time, enabling syntactic abstraction and the creation of expressive and concise code. 10. Portability: LISP programs are often highly portable across different platforms and implementations. Standardization efforts, such as the Common Lisp standard, help ensure compatibility and interoperability between different LISP dialects. These features contribute to LISP's reputation as a powerful and expressive programming language, particularly well-suited for tasks involving symbolic computation, artificial intelligence, language processing, and rapid prototyping. Despite its age, LISP remains influential and continues to be used in various domains, both in academia and industry. Q7) b) Explain the following Equality pres i) EQUAL i) EQ iii) EQL iv)= ates using a suitable example, Ans: i) EQUAL The EQUAL predicate checks if two objects are structurally identical, meaning they have the same structure and contain the same elements. For lists and arrays, it checks if the elements at corresponding positions are EQUAL. For non-lists, it checks if the objects are identical (i.e., they occupy the same memory location). Example: (equal (1.2 3) '(123)) => T (equal 'foo 'foo) >T (equal "bar" "bar") (equal 123 123) i) EQ The EQ predicate checks if two objects are identical, meaning they occupy the same memory location. It's a ‘more strict comparison compared to EQUAL. Example: (eq (1 2 3) "(1 2 3)) ;=> NIL (Not identical) EY Other Subjects: www.pyqspot.com (eq 'foo 'foo) T (Identical) (eq "bar" "bar") NIL (Not identical) (eq123 123) ==> T (Identical) iii) EQL The EQL predicate checks if two objects are equivalent, meaning they are either identical or represent the same value (for numbers and characters). Example: (eql (1 23) '(1.23)) (eql'foo 'foo) (eql "bar" "bar") (eql 123 123) NIL (Not equivalent) T (Equivalent) NIL (Not equivalent) T (Equivalent) iv) = ‘The = predicate is used specifically for comparing numbers. It checks if all the arguments are numerically equal Example: (22) 3) > NIL 2.0) => T (2 is considered equal to 2.0) Q7) ¢) Explain the following number predicates using a suitable example. i)NUMBERP ii) ZEROP PLUSP iv) EVENP vy) ODDP Ans: i) NUMBERP. numberp : It takes one argument and returns true if the argument is a number otherwise returns NIL. >(aumberp 10) iy >(numberp ‘a) NIL. BY, Other Subjects: www.pyqspot.com ii) ZEROP zerop :The zerop predicate checks if a number is zero Example: (zerop -3) ;=> NIL PLUSP plusp :The plusp predicate checks if a number is positive Example: (plusp 0) ;=> NIL iv)EVENP Evenp : It takes one numeric argument. If the number is even then it returns T otherwise it returns NIL >(evenp 10) T >(evenp 11) NIL v) ODDP Oddp : It takes one numeric argument. If the number is odd then it retums T otherwise it returns NIL. >(oddp 10) NIL >(oddp 11) fH Q8) a) Explain the following functions with suitable examples. In Lisp programming, CAR, CDR, and FIRST are functions used to manipulate lists. They operate on cons cells, which are the fundamental building blocks of Lisp lists. Each cons cell has two parts: the car (holds the first element) and the cdr (holds the rest of the list), BY, Other Subjects: www.pyqspot.com 1. CAR ‘The CAR function returns the first element of a list. Example: (car'(1.23.4)) > 1 (car '((a b) ¢ d)) => (ab) (car '() => NIL (empty list) In the first example, (ear "(1 2 3 4)) returns 1, the first element of the list. In the second example, (ear ((a b) €d)) returns (a b), which is a list itself. Ifthe list is empty, (ear 'Q) returns NIL. 2.CDR ‘The CDR function returns the rest of the list after the first element. Example: (cdr'(1.23 4) => (23.4) (cdr ((a b) ¢ d)) (cd) (cdr '()) ;=> NIL (empty list) In the first example, (edr "(1 2.3 4)) returns (2 3 4), which is the list excluding the first element 1. In the second example, (edr "((a b) ¢ d)) returns (¢ d). If the list is empty, (ede '0) returns NIL. 3. FIRST. ‘The FIRST function is an alias for CAR and returns the first element of a list. Example (first (1 2.3.4)) => 1 (first '((a b) ¢ d)) ==> (ab) (first 'Q) ;=> NIL (empty list) FIRST and CAR are synonymous, so (first "(1 2 3 4)) is equivalent to (car "(12 3 4)), and both return 1. Similarly, (first '((a b) ¢ d)) and (car "((a b) ¢ d)) return the same value (a b). If the list is empty, (first 0) returns NIL. Q8) b) b) Describe Logical Programming. Enlist its features. Also, list the commonly used Logical programming languages. Ans: Logical programming is a programming paradigm that is based on formal logic. It focuses on specifying what should be computed, rather than how it should be computed. In logical programming, programs are expressed as collections of logical statements and rules, and computation is performed by making logical inferences to derive new information from existing facts and rules. BY, Other Subjects: www.pyqspot.com Features of Logical Programming: Declarative Style: Programs in logical programming languages are written in a declarative style, where the programmer specifies the desired results or relationships rather than the step-by-step procedure for achieving them, Logical Inference: Computation is performed through logical inference, where the system derives new facts from existing facts and rules using logical reasoning. Pattern Matching: Logical programming languages often support pattern matching, allowing the system to match data structures against patterns specified in rules or queries. Backtracking: Backtracking is a key feature of logical programming languages, enabling the system to explore multiple solutions by undoing choices that lead to dead ends, Non-determinism: Logical programming languages support non-deterministic computation, allowing multiple possible solutions to be explored until a satisfactory solution is found. Recursive Rules: Recursive rules are commonly used in logical programming languages to define relationships or computations in terms of themselves, enabling elegant and concise specifica ms. Unification: Unification is a fundamental operation in logical programming, used to combine logical terms and variables by finding substitutions that make them equal. ‘Commonly Used Logical Programming Languages: Prolog: Prolog is one of the most widely used logical programming languages. It provides a powerful mechanism for defining logical rules and queries, and it is commonly used in artificial intelligence, natural language processing, and expert systems. Datalog: Datalog is a subset of Prolog designed for database query languages. It is used in database management systems and knowledge representation. Answer Set Programming (ASP): ASP is a logical programming paradigm that focuses on finding answer sets, which are collections of logical statements that satisfy a given set of rules and constraints. ASP is commonly used in combinatorial optimization and planning problems. ‘Mercury: Mercury is a logic-based functional programming language that combines the features of logic programming with the efficiency of functional programming. It is used in areas such as software analysis, verification, and web development. ECLiPSe: ECLiPSe is a constraint logic programming language that extends Prolog with constraint- solving capabilities. It is used in areas such as scheduling, planning, and optimization, Allloy: Alloy is a declarative modeling language based on relational logic. It is used for software modeling, analysis, and verification, particularly in the field of formal methods. BY, Other Subjects: www.pyqspot.com Q8) c) Evaluate the following forms of LISP, i) (car (cdr (123 45))) ii) (car (cdr “(a (bc) de))) ii) (car (cdr (cdr “(1 234567 ED)))) Ans: i) (car (cdr (123.4 5))) 1, (cdr (1 23 455)) evaluates to (2 3 4 5), as it returns the rest of the list after the first element, 2. (car "(23 45)) evaluates to 2, as it returns the first element of the list. So, the result of the expression is 2. ii) (car (edr "(a (b ¢) de) 1. (cdr "(a (b ©) d e)) evaluates to ((b c) d e), as it returns the rest of the list after the first element. 2. (car ((b 6) d e)) evaluates to (b c), as it returns the first element of the list. So, the result of the expression is (be). (car (cdr (cdr (12.3 4567 ED)))) 1. (cdr "(123.4567 ED)) evaluates to (2 3.4 5 6 7 ED), as it returns the rest of the list after the first element. 2. (edr (2 3.45 67 ED)) evaluates to (3 4 5 67 ED), as it returns the rest of the list after the first element. 3. (car (3.45 67 ED)) evaluates to 3, as it returns the first clement of the list. So, the result of the expression is 3. = (car (edr (123 45))) evaluates to 2. + (car (cdr "(a (b ¢) d e))) evaluates to (b 0). © (car (cdr (cdr "(1 23.4 5 6 7 ED)))) evaluates to 3 BY, Other Subjects: www.pyqspot.com

You might also like