Posts

Showing posts with the label Model Question

Discuss various scopes of JSP objects briefly. Create HTML File with principal, time and rate. Then crate a JSP file that reads values from the HTML form, calculates simple interest and displays it.

   SCOPE OF JSP OBJECTS The availability of a JSP object for use from a particular place of the application is defined as the scope of that JSP object. Every object created on a JSP page will have a scope.  Object scope in JSP is segregated into four parts and they are page, request, session, and application. a) Page Scope- page scope means, the JSP object can be accessed only from within the same page where it was created. JSP implicit objects out, exception, response, pageContext, config, and page have page scope. //Example of JSP Page Scope <jsp:useBean id="employee" class="EmployeeBean" scope="page" /> b) Request Scope-  A JSP object created using the request scope can be accessed from any pages that serves that request. More than one page can serve a single request. Implicit object request has the request scope. //Example of JSP Request Scope <jsp:useBean id="employee" class="EmployeeBean" scope="request" /> c

Write a java program to create login with user id, password, ok button, and cancel button. Handle key events such that pressing 'l' performs login and pressing 'c' clears text boxes and puts focus on user id text box. Assume user table having fields Uid and Password in the database named account. (10)

LoginFrame.java  import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.sql.SQLException; /** * JFrame to handle key events such that pressing 'l' performs login, * ... and pressing 'c' clears text fields and puts focus on user ID * ... text field. */ public class LoginFrame extends JFrame { JLabel userIdLabel, passwordLabel; JTextField userIdTextField; JPasswordField passwordField; JButton okBtn, cancelBtn; JFrame self; public LoginFrame() { self = this; userIdLabel = new JLabel("User ID"); passwordLabel = new JLabel("Password"); userIdTextField = new JTextField(20); passwordField = new JPasswordField(20); okBtn = new JButton("OK"); cancelBtn = new JButton("Cancel"); okBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new JFrame() { { JLabel messageLabel = new JLabel(); LoginService loginService = new LoginService(); String user = userIdTextField.getText();

What are the uses of the final modifier? Explain each use of the modifier with examples.

 Final Modifier  Final Modifier is a non-access Specifier that is used to restrict a class, variable, and method. If we initialize a variable with the final keyword, then we cannot modify its value. The final modifier keyword makes the programmer cannot change the value anymore. The actual meaning depends on whether it is applied to a class, a variable, or a method.  It's a modifier that you can apply on variables, methods, and classes and when you apply the final modifier it can make variables immutable, prevent the method from overriding in subclasses, means no polymorphism, and when you make a class final in Java it cannot be extended anymore, taking out Inheritance from the picture.   The java final modifier can be used in the following ways (i) variable → To Create Constants (ii) Method → To prevent Method overriding  (iii) Class → To prevent inheritance. 2nd Part   The use of each modifier is explained below with example:- (i) To Define Constants  We can use the final modifie

How beam search and logic programming is used to mine graph? Explain.

 Beam search    A beam search is a heuristic search technique that combines elements of breadth-first and best-first searches. Like a breadth-first search, the beam search maintains a list of nodes that represent a frontier in the search space. Whereas the breadth-first adds all neighbors to the list, the beam search orders the neighboring nodes according to some heuristic and only keeps the n (or k or 3) best, where is the beam size. This can significantly reduce the processing and storage requirements for the search. Some applications are speech recognition, vision, planning, machine learning, graph mining, and so on. Beam Search Algorithm 1.Let beam width = n. 2 Create two empty lists: OPEN and CLOSED. 3. Start from the initial node (say N) and put it in the 'ordered' OPEN list. 4. Repeat steps 5 to 9 until the GOAL node is reached. 5. If the OPEN list is empty, then EXIT the loop returning 'False'.  6. Select the first/top node (N) in the OPEN list and move it to th

What is the concept mini batch k-means? How DBSCAN works?

Image
  MINI-BATCH K-MEANS The mini-batch k-means clustering algorithm is the modified version of the k-means algorithm. It uses min-batches to reduce the computation time in large datasets. In addition, it attempts to optimize the result of the clustering. To achieve this, the mini-batch k-means takes mini-batches as inputs which are subsets of the whole dataset, randomly.  The mini-batch k-means is considered faster thank-means and it is normally used for large datasets. Mini Batch K-means algorithm's main idea is to use small random batches of data of a fixed size, so they can be stored in memory. In each iteration, a new random sample from the dataset is obtained and used to update the clusters and this is repeated until convergence. Each mini-batch updates the clusters using a convex combination of the values of the prototypes and the data, applying a learning rate that decreases with the number of iterations. This learning rate is the inverse of the number of data assigned to a clu

Discuss about overfitting and underfitting. How precision and recall is used to evaluate classifier.

Image
   OverFitting Overfitting means the model has a High accuracy score on training data but a low score on test data. An overfit model has overly memorized the data set it has seen and is unable to generalize the learning to an unseen data set. That is why an overfit model results in very poor test accuracy. Poor test accuracy may occur when the model is highly complex, i.e., the input feature combinations are in a large number and affect the model's flexibility. Overfitting happens when the algorithm used to build a prediction model is very complex and it has overlearned the underlying patterns in training data. Overfitting is an error from sensitivity to small fluctuations in the training set. Overfitting can cause an algorithm to model the random noise in the training data, rather than the intended result. In classification, overfitting happens when algorithms are strongly influenced by the specifics of the training data and try to learn patterns that are noisy and not generalized

Describe any five types of OLAP operations.

Image
 Online Analytical Processing Server (OLAP) is based on the multidimensional data model. It allows managers, and analysts to get an insight into the information through fast, consistent, and interactive access to information. Since OLAP servers are based on a multidimensional view of data, we will discuss OLAP operations in multidimensional data. Here is the list of OLAP operations: Roll-up Drill-down Slice and dice Pivot (rotate) Roll-Up The roll-up operation (also known as drill-up or aggregation operation) performs aggregation on a data cube, by climbing up concept hierarchies, i.e., dimension reduction.  Roll-up is like zooming out on the data cubes. The figure shows the result of roll-up operations performed on the dimension location. The hierarchy for the location is defined as the Order Street, city, province, or state, country.  The roll-up operation aggregates the data by ascending the location hierarchy from the level of the city to the level of province. When a roll-up is pe

Why data preprocessing is mandatory? Justify.

Incomplete, noisy, and inconsistent data are commonplace properties of large real-world databases and data warehouses. Incomplete data can occur for a number of reasons. Attributes of interest may not always be available, such as customer information for sales transactions important at the time of entry. Relevant data may not be recorded due to a misunderstanding, or because of equipment malfunctions. Data that were inconsistent with other recorded data may have been deleted. Furthermore, recording of the history of modifications to the data may have been overlooked. Missing data, particularly for tuples with a missing value for some mining results. Therefore to improve the quality of data and, consequently, of the mining results, data preprocessing is needed/mandatory.                                                   OR,  Virtually any type of data analytics, data science, or AI development requires some type of data preprocessing to provide reliable, precise, and robust results for

How trust and distrust propagate in social network Explain.

Image
  Propagation of Trust and Distrust The end goal is to produce a final matrix F from which we can read off the computed trust or distrust of any two users. In the remainder of this section, we first propose two techniques for computing F from CB. Next, we complete the specification of how the original trust T and distrust D matrices can be combined to give B. We then describe some details of how the iteration itself is performed to capture two distinct views of how distrust should propagate. Finally, we describe some alternatives regarding how the final results should be interpreted. Approaches to Trust Propagation A natural approach to estimate the quality of a piece of information is to aggregate the opinions of many users. But this approach suffers from the same concerns around disinformation as the network at large: it is easy for a user or coalition of users to adopt many personas and together express a large number of biased opinions. Instead, we wish to ground our conclusions in

Write the limitation of Apriori algorithm.

Limitations:  Apriori algorithm is easy to understand and its' join and Prune steps are easy to implement on large itemsets in large databases. Along with these advantages, it has a number of limitations. These are: 1. a Huge number of candidates:  The candidate generation is the inherent cost of the Apriori Algorithms, no matter what implementation technique is applied. It is costly to handle a huge number of candidate sets. For example, if there are 10^4 large 1-itemsets, the Apriori algorithm will need to generate more than 10^7 candidate 2-itemsets. Moreover, for 100 itemsets, it must generate more than 2^100 which is approximately 100 candidates in total.  2.  Multiple scans of transaction database so, to mine large data sets for long patterns this algorithm is not a good choice.  3. When the Database is scanned to check C_k, for creating F_k, a large number of transactions will be scanned even they do not contain any k-itemset.                                         OR, Lim

Explain the different components of data warehouse. How data cube precomputation is performed? Describe.

Image
Components of Data Warehouse  A typical data warehouse has four main components: a central database, ETL (extract, transform, and load) tools, metadata, and access tools. All of these components are engineered for speed so that we can get results quickly and analyze data on the fly.                                               Figure: Components of data warehouse The figure shows the essential elements of a typical warehouse. We see the ETL shown on the left. The Data staging element serves as the next building block. In the middle, we see the Data Storage component that handles the data warehouses data. This element not only stores and manages the data; it also keeps track of data using the metadata repository. The Information Delivery component is shown on the right consists of all the different ways of making the information from the data warehouses available to the users. The major four components of Datawarehouse are listed below: 1. Central database A database serves as the foun

Write short notes on (Any TWO) a. Single page application b. Hidden fields c. Await patterns

  a) Single Page Application A single-page application (SPA) is a web application or website that interacts with the user by dynamically rewriting the current web page with new data from the webserver, instead of the default method of the browser loading entire new pages. The goal is a faster transition that makes the website feel more like a native app. In a single-page application, all necessary HTML, JavaScript, and CSS code is either retrieved by the browser with a single page load, or the appropriate resources are dynamically loaded and added to the page as necessary, usually in response to user actions. The page does not reload at any point in the process, nor does it transfer control to another page, although the location hash or the HTML5 History API can be used to provide the perception and navigability of separate logical pages in the application. b) Hidden Fields The hidden field, as the name implies, is hidden. Sometimes we require some data to be stored on the client-side

How do you render HTML with views? Explain.

In the MVC pattern, the view handles the app's data presentation and user interaction. A view is an HTML template with embedded Razor markup. Razor markup is code that interacts with HTML markup to produce a webpage that's sent to the client. In ASP.NET Core MVC, views are .cshtml files that use the C# programming language in Razor markup. Usually, view files are grouped into folders named for each of the app's controllers. The folders are stored in a Views folder at the root of the app. Views that are specific to a controller have been created in the Views/[ControllerName] folder. To create a view, add a new file and give it the same name as its associated controller action with the .cshtml file extension. The Home controller is represented by a Home folder inside the Views folder. The Home folder contains the views for the About, Contact, and Index (homepage) webpages. When a user requests one of these three web pages, controller actions in the Home controller determine w

Express the format of request and response message format. What is the role of adapter class in database connection?

Image
 The format of request and response message format is:-  HTTP HTTP specifications concisely define messages as "requests from client to server and responses from server to client." At its most elemental level, the role of ASP.NET is to enable server-based applications to handle HTTP messages. The primary way it does this is through HttpRequest and HttpResponse classes. The request class contains the HTTP values sent by a client during a Web request; the response class contains the values returned to the client. HTTP Request Message Format The Request-Line consists of three parts: the method token, the Request-URI, and the protocol version. Several methods are available, the most common being the POST and GET methods. The Uniform Resource Identifier (URI) specifies the resource being requested. This most commonly takes the form of a Uniform Resource Locator (URL) but can be a file or other resource. The protocol version closes out the Request-Line.  The general-header is used

Why do we need generics? What are the significances of MSIL?

Generics  Generic is common to write a program that processes a collection - e.g. a collection of numbers, a collection of contacts, a collection of Names, etc. With generic programming, we can write code that handles a collection 'in the general' and C# handles the specifics for each collection type, saving you a great deal of work. Generic collection in C# is defined in System.Collection.Generic namespace. It provides a generic implementation of standard structures like List, Stack, Queues, Dictionaries, etc. E.g. using System;   using System.Collections.Generic;   public class GenericList   {       public static void GenericListMethod()       {           List<int> genericList = new List<int>();          // No boxing, no casting:           genericList.Add(12);           genericList.Add(13);           genericList.Add(14);           genericList.Add(15);        }  }  There are mainly two reasons to use generics as in the following: 1. Performance: Collections that s

Explain the process of compiling and executing .NET application.

Image
  The process of compiling and executing the .NET application are:-  C# programs run on the .NET Framework, which includes the common language runtime (CLR) and a unified set of class libraries. The CLR is the commercial implementation by Microsoft of the common language infrastructure (CLI), an international standard that is the basis for creating execution and development environments in which languages and libraries work together seamlessly. Source code written in any .NET languages (C#, VB.Net, etc.) is compiled into a Microsoft Intermediate Language (MSIL) or simply(IS) that conforms to the CLI specification. The IL code is stored on disk in an executable file called an assembly, typically with an extension of .exe or .dll. CLR performs just in time (JIT) compilation to convert the IL code to native machine instructions. The CLR also provides other services related to automatic garbage collection, exception handling, and resource management. Code that is executed by the CLR is som

Differentiate between abstract class, sealed class and interface. What is the task of Object Relational Mapper?

 The differentiate between abstract class, sealed class, and interface are as follows:- Abstract Class A class is said to be an abstract class if we can’t instantiate an object of that class without creating its sub-class. Such class only exists as a parent of derived classes from which objects are instantiated. Abstract Class contains at least one abstract method. Abstract classes are used to provide an Interface for its subclasses. Classes inheriting an Abstract Class must provide a definition to the abstract method. Example:  using System; namespace ConsoleApp {   class Program   {      static void Main(string[] args)      {        Demo d;     //d is Reference Type variable of Abstract Class Demo         Demo1 d2 = new Demo1();         d = d2;         d.Display();         Console.ReadKey();       }     }     abstract class Demo     //Abstract Class     {         public abstract void Display();     //Abstract Method     }     class Demo1: Demo     //Concrete Class     {         publi

How do you host and deploy the ASP.NET core application.

There are 2 types of hosting models in ASP.NET Core: 1. Out-of-process Hosting Model: In Out-of-process hosting models, we can either use the Kestrel server directly as a user request facing server or we can deploy the app into IIS which will act as a proxy server and send requests to the internal Kestrel server. In this type of hosting model, we have two options: a) Using Kestrel: Kestrel is a cross-platform web server for ASP.NET Core. Kestrel is the webserver that's included by default in ASP.NET Core project templates. Kestrel itself acts as edge server which directly server user requests. It means that we can only use the Kestrel server for our application. b) Using a Proxy Server: Due to the limitations of the Kestrel server, we cannot use this in all the apps. In such cases, we have to use powerful servers like IIS, NGINX or Apache. So, in that case, this server acts as a reserve proxy server which redirects every request to the internal Kestrel sever where our app is runn

Write an application showing sql injection vulnerability and prevention using ado.net.

  Consider the following action method that validates user login. [HttpPost] public IActionResult SubmitLogin1(String uname, String pwd) {     SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=db_Mac1; Integrated Security=True");     con.Open();     SqlCommand cmd = new SqlCommand("select * from tbl_login where uname=' "+uname+" ' and password=' "+pwd+" ' ", con);     SqlDataReader dr = cmd.ExecuteReader();     if (dr.Read())     {         return Content ("Login Successful");     }     else     {        return Content("Login Unsuccessful");     } } The above action method is vulnerable to SQL injection attacks. It is because we've used the form input values name and pwd with no data validation at all including Empty form validations. Nothing bad will happen if we're sure that this value will only come from trusted sources, but this is not always. If the attacker doesn'

How does the system manage state in stateless HTTP? Design a page to show client side validation for login page using jquery or angular or react.

  HTTP is called a stateless protocol because each command request is executed independently, without any knowledge of the requests that were executed before it.  A few techniques can be used to maintain state information across multiple HTTP requests: 1. Cookies: A web server can assign a unique session ID as a cookie to each web client and for subsequent requests from the client they can be recognized using the received cookie. 2. Hidden fields of the HTML form:  Web server can send a hidden HTML form field along with a unique session ID as follows:         <input type = "hidden" name = "sessionid" value = "12345">         This entry means that, when the form is submitted, the specified name and value are automatically included in the GET or the POST data. Each time the web browser sends the request back, the session_id value can be used to keep the track of different web browsers. 3. URL rewriting: We can append some extra data at the end of each