CSCI - 201

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

CSS id attribute, class attribute

#id .class

abstract

(M + Classes) abstract method must be overridden in a subclass or subclass becomes abstract

final

(M + V) Final variable can be initiated only ONCE, either inline or constructor Final method cannot be overridden by a subclass

Loops - how many ways to do loops?

4 ways to loop: For, while, do...while, recursion (direct or indirect) While vs. do...while: While tests condition before code, do...while tests condition after code.

HTML Links

<a href="csci.html">CSCI 201</a>

*** Annotations

Allow us to specify configuration parameters that are used by the application server

Dynamic Web Content

Allows different data to be shown on the same web page.

What is one important benefit of AJAX?

Allows for just part of a page to be reloaded with direct access to the server.

AJAX

Asynchronous JavaScript and XML which uses: › A browser built-in XMLHttpRequest object to request data from a web server › JavaScript and HTML DOM to display the data › AJAX allows just a portion of a page to be updated instead of forcing a reload on the entire page.

Unchecked exceptions

Avoid handing: › RunTimeException › NullPointerException › NumberFormatException › ArrayIndexOutOfBoundsException › ArithmeticException

Volatile memory

CPU (Registers, Cache, ALU), Main Memory

Concurrent programming examples:

Chatting, message updates, multi-player games

Inheritance

Create a class that absorbs an existing class's data and behaviors and enhances. The existing is base class, new class is derived class.

Hyper-threading

Firmware logic to trick the OS to think it has more than one core when it only has one physical one.

Non-volatile memory

Hard drive and external storage

Buffered Reader syntax

InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); String line = br.readLine(); int num = Integer.parseInt(line);

How does an interface inherit from other interfaces?

It extends them.

Interface

Like a class, but no method implementations. When a class implements an interface, it must implement all methods, or else it is an abstract class. A class can implement as many interfaces as it wants.

Object vs Class What are key features?

Object is high-level term for the idea behind a class. Class is the actual implementation of an object. Once class is made, you can create instances of the class, (referred to as an object as well) Have: data & methods

Abstract methods

Only contain declarations and no implementations. Any class that has an abstract method must be declared abstract.

Abstract class

Parent class guarantees that child will provide an implementation. Cannot be instantiated

Scanner vs. Buffered Reader

Scanner parses tokens from contents of stream while bufferedReader just reads the stream. BR is synchronized while scanner is not, so use BR when working with multiple threads. BufferedReader has larger buffer memory, so use if you want to get long stream.

What ways can you read from user?

Scanner, BufferedReader, Command line

Only able to call methods based on ______-time type of an object because if a method only exists in a child and you have an instance of a parent

compile

HTML Block Tags (2)

div and span tags - div is block-level element - span is inline element

HttpServlet methods

doGet, doPost, service (dispatches to doGet or doPost if not overridden), init

CSS Frameworks

such as Bootstrap to help with responsiveness and other common tasks

AJAX form validation

var xhttp = new XMLHttpRequest(); › Open ›Send ›responseText.trim().length >0 › getElementById().innerHTML = xhttp.responseText;

JSP Scopes (4)

› Application › Session › Page › Request

JSP embedded java tags (5)

› Declaration <%! %> › Directive <%@ %> › Expression <%= %> › Scriptlet <% %> › JSTL - explained in a later slide

Ways to include JavaScript (3)

› In an attribute of a tag › In a <script> tag › In an external JavaScript file (typically named with a .js extension)

Why should form validation be done in ________-side?

› Server side › Careful when using client-side JavaScript b/c users can disable JS in their browsers

Purpose of Multi-threaded programming

› add functionality to your program (does not actually have 20 things running at a time, but appears as so)

Purpose of parallel programming

› speed up execution of your program by using redundant resources typically on your computer (multiple sections of a process or multiple processes executing simultaneously in different cores/CPUs with shared mem space

Purpose of Distributed Programming

› speed up execution of your program by using resources typically on other computers Multiple sections of a process executing on different CPUs with different memory spaces (could be on different computers)

static

(M + V) Only one instance of static variable/method exists Do not need an instance to access static Non-static variables can only be accessed by non-static methods.

synchronized

(M) synchronized methods need a lock on the object so no other sync method on same object can execute until first terminates

volatile

(V) not allow a cached value to be used in threads - all threads will be the same value when accessing volatile variable

transient

(V) will not persist using serialization

Servlets

- Java classes that can serve dynamic web content - Compiled and executed on server and generate client-side code to send to browser - To create servlet, extend [HttpServlet] class

Back-End web languages

- Most dynamic content is based on a server program running - Languages: Java, PHP, Ruby, Python, Server-side javascript, C, Perl, C#

HTML

-- Hypertext Markup Language: used for processing, definition and displaying data. -- Tag based language

Paragraph Tags

-- Separate logical display blocks. -- Line breaks used for formatting

JSP

-- embed Java in your HTML file -- get converted to servlets the first time they are accessed -- <% %> is scriptlet

java.io.Serializable interface: What are the benefits?

1. Allows us to specify to the JVM that the current object can be stored in an [ObjectOutputStream] and retrieved from [ObjectInputStream] (this includes all of the private variables from inherited classes as well) 2. It saves the programmer time of not needing to parse the data when reading it back in from the file.

3-Tier Architecture

1. Client 2. Server: Web/Application Server + Database

CSS included 3 ways:

1. Inline in an HTML element through the style attribute <body style = "---"> 2. In the <style> tag in <head></head> 3. In an external file that is included in an HTML in <link> tag ex: <link rel="stylesheet" type="text/css" href="test.css"/>

Garbage Collector Steps (3)

1. Marking: determine which memory is in use and which are not 2. Normal deletion: removes unreferenced objects leaving referenced objects and pointers. Downside: fragmentation. 3. Deletion with compaction: deletes unreferenced objects and compacts the remaining. Process itself is slower, but allows for faster memory allocation later.

HTML inline frame

<iframe src = "" height ="200" width = "400"/>

HTML Images

<img src="j_m.png"/>

Single Inheritance

A extends B. "Super" calls parent constructor Recall: Classes can be abstract without abstract methods If you have a single abstract method, the class must be abstract as well.

What kind of boolean operators are there? (2 types)

Bitwise: & | Logical: && || !

JavaScript is Front or Back-end?

Both. Traditionally front, but server-side JavaScript (node.js) exists as well.

Difference between Java and C++: Redefining/Overriding methods in base and child.

C++: If Function is not virtual, the function in the child redefines it. The function executed is based on compile-time type. Java: No redefining of methods, ALWAYS OVERRIDDEN. Method in RUNTIME instance is always called.

Can runtime errors be fixed at compile time?

Cannot fix at compile time. Unlike syntax or compile-time errors. Ex: memory leaks or logic errors

Java Exception Handling (2 types)

Checked and Unchecked Exceptions

Based on inheritance, an object with compile-time type of a parent can take on the form of a ________ at runtime

Child

JSTL

Collection of useful JSP tags that allow front-end programmers to write code with similar Java functionality without actually having to learn Java.

JavaScript

Front-end interpreted language that gives programmers more control and functionality than HTML and CSS

Checked exceptions

Handle! › SQLException › IOException › FileNotFoundException

Name the types of parameters in Java and how they are passed (2)

If parameter is primitive type, it is passed by value. If it is an object, it is passed by reference.

Where do JavaScript functions belong?

In <head> tag or in external JS file.

Inheritance vs Composition

Inheritance: is-a relationship Composition: has-a relationship

JSPs and HTML Forms - how can data be processed? (4)

JSPs can be used to process the data submitted from an HTML form through request variable =========USING========= › HttpServletRequest request › HttpServletResponse response › PrintWriter out › HttpSession session

Conditional Statements in Java (3 types)

Java has 3: if-else, switch-case and conditional ternary operator ?: switch statements can only take in a byte, short, int or char and values must be hard-coded. Every switch can be written as an if, but not vise-versa.

Java compared to C++ (speed, platform)

Java is slower than c++ by about 20%, but it is platform independent (runs on all OS), not compiled to native code. C++ generates an .exe code which depends on the OS. Java is platform independent, JVM turns it into bytecode, but JVM is dependent on OS.

What does Garbage Collection do?

Low priority thread that comes around when main program is waiting. Memory no longer referenced, GC will delete that reference. We can make a suggestion with System.gc(), but not immediate, just asks to run sooner.

Order of catching

More specific → more general. Try to avoid handling the generic exception.

What determines how many actual number of processes running? (3)

Multiple processors, multiple cores, hyper-threading

Method

Must exist within a class All must return a value or have return type void To call a method, you must have an instance of the class, unless the method is static Recursive method: calls itself

Polymorphism

Object with a type of parent can take on the form of a child at runtime. Compile time is left hand side, runtime is right hand side. Java ALWAYS looks at runtime type. You can override to use parent's method by using super.METHOD

How many public classes can exist in a java file?

One

Static variable

One instance of that variable regardless of how many instances of the class. Always stay in memory, never cleaned by GC.

HTML Formatting and Preformatting

Performatted: Courier New, including whitespace. <pre> Many tags to format text.

Servlets & PrintWriters

PrintWriter out = response.getWriter(); out.println("<DOCTYPE html>"); ...

Program vs. Processes vs. Threads

Programs › An executable file residing in memory, typically in secondary storage Processes › An executing instance of a program › "Task" Threads › Any section of code within a process that can execute at what appears to be simultaneously › Shares the same resources allotted to the process by the OS kernel

Forwarding from a Servlet

Request and response objects can be forwarded to the page next = "/validUsername.jsp" RequestDispatcher dispatch = getServletContext().getRequestDispatcher(next);

If parent has method declared in it, when method is called on object with compile time type of parent, it calls the method in _________ type of the object.

Runtime

Serialization

Save all data from parent classes up the hierarchy, save the exact state of a program.

Scanner syntax

Scanner in = new Scanner(System.in); String name = in.nextLine(); There are also: nextDouble(); nextInt();

Servlets and HTML forms

Servlets can be used to process the data submitted from an HTML form through the [HttpServletRequest] variable in doGet, doPost or service methods ex: request.getSession() request.getParameter()

Exceptions

Should not be a part of normal execution because it is 10x SLOWER! Handle everything with if else, if possible. Use try-catch blocks and optional finally clause that will be executed regardless (for closing files etc.) When you catch an exception, it won't continue, that's why you should use finally.

Java supports single or multiple inheritance?

Single. Only allow a derived class to inherit from one base class. Multiple: C++, what if more than one parent implements the same function?

Which types of variables of the class are not serialized?

Static and transient variables "Transient" just means will not be serialized. If a variable in the serializable class is another object, that object must be serializable too, or an exception will be thrown (NotSerializableException).

How does [Time Slicing] work for Java?

The OS switching processes and native threads in and out of the CPU. › NOTE: In Java, JVM switches threads in and out of CPU and OS switches the JVM in and out of the CPU

Network Serialization

Transmitting data over a network to another program with serialization.

How do you instantiate a child class?

Use keyword extends. When child is instantiated, parent must be instantiated first in child's constructor

Headings

Used for different levels in a document.

Is it required for the name of the public class to be the name of the file?

Yes

What does it mean for a class to be encapsulated?

a class is encapsulated if all of the data is declared private.

HTML Forms common attributes? (2)

action and method <form action="submit.html" method = "GET"> <input type = "text" name = "fname"/> <br/>

constructor

called when class is instantiated, typically initialize member variables can be overloaded, no return type

fully encapsulated

if all data is declared private and you provide an accessor and manipulator (getter and setter)

Command Line Syntax

if(args.length)==2) String name = args[0];

String

immutable, value of that String cannot be changed AT ALL reference to a String can be changed String API has many methods, constructors, comparators etc.

Package in Java

logical arrangement of code package named: edu.usc .class file must be in folder usc, which is in folder edu

How to define an array and are they primitive variables?

must user "new" operator int nums[] = new int[10]; multidimensional: new int[10][20]; not primitive variables so passed by reference: public static void myMethod(int numArr[]){}

Syntax of the main method in java is:

public static void main(String [] args) The args variable is used for reading parameters from the command line.

Access methods for inheritance

public, protected, <package>, private

Types of access Modifiers for access in Java (4)

public: any other piece of code can access the variable or method private: only the class in which that variable or method is declared can access it <package> any class in same package can access protected: any class declared in the same package or who inherits can access


संबंधित स्टडी सेट्स

Chapter 34: Hematology and Oncology

View Set

Chapter 39: Caring for Clients With Head and Spinal Cord Trauma

View Set

Microeconomics Chapter 10.2-book notes- PROFIT-MAXIMIZING OUTPUT FOR THE MONOPOLIST

View Set