Internet Technology (AS21)
Internet technology module at FHNW 2021, major in BIT by Devid Montecciari
Internet technology module at FHNW 2021, major in BIT by Devid Montecciari
Set of flashcards Details
Flashcards | 130 |
---|---|
Language | English |
Category | Computer Science |
Level | University |
Created / Updated | 20.09.2021 / 11.01.2024 |
Weblink |
https://card2brain.ch/box/20210920_internet_technology_as21
|
Embed |
<iframe src="https://card2brain.ch/box/20210920_internet_technology_as21/embed" width="780" height="150" scrolling="no" frameborder="0"></iframe>
|
How could you write "Welcome" in Java script?
document.write('Welcome");
document is the object
dot is the member operator
and write() is the method this the sting as argument
How do you add JavaScript to a page?
The code in your web document is generally loaded and executed in the order it appears on the page. if JS loads and tries to run before the HTML and CSS it is affecting has been loaded, errors can occur
There are three main ways:
- Internal JS is ok, comes before </body>
- External JS - best
- inline JS handlers - NO, bad practice
are usually loaded or inserted inside the head
What are the most common rules when naming variables in java script?
- must begin with a letter, $ or _, must not start with a number
- name can contain letters, numbers, $,_ must not use - or . in a variable name
- cannot use keywords or reserved words
- all variables are case sensitive.
- if name is made up of more than one word, use camel case
how do you declare a function in js?
function sayHello() {document.write('Hello');}
Describe the main feature of the browser object model in js
window.innerHeight
window.innerWidth
window.screenX
window.screenY
window.print()
- Window
- Document
- History
- Location
- Navigator
- Screen
Describe the document object model
document.title
document.lastModified
document.write()
document.getElementById()
- document
- html
- head
- title
- body
- div
- head
- html
how do you use comparison operators in js?
- == compares two values to see if they are the same
- != compares two values to see if they are not the same
- === is preferable to == as it compares two values to check both the data type and the value are same
- !== is preferable to != as it compares two values to check both the data type and the value are not same
What is an anonymous function in js?
a function without a name. used for code that only needs to run once within a task, rather than repeatedly being called by other parts of the script.
can also be used as a function expression and stored in a variable or immediately invoked function jus start with (function...)
setTimeout(function() {
console.log('execute later after 1 second')
},1000);
What are cross-site scripting (XSS) attacks and how to protect against it?
- adding html to a page using innerHTML may make it susceptible to cross-site scripting attacks
- XSS involves an attacker placing malicious code into a site using what is known as untrusted data
- source of untrusted data:
- user creates a profile
- multiple contributors to a website
- data from third-party sites
- files such as images/videos are uploaded
- XSS can give an attacker access to information in:
- The DOM (including form data)
- Website cookies
- session tokens containing login information of users
Protect against it
- validate every information that is sent to the server, do not let users submit HTML or JS code
- validate again on the server-side in case the client-side validation is bypassed by disabling JS
- save markup and scripts only from trusted sources in the db
- escape potentially dangerous characters after the data leaves the database
- innerHTML can be safely used to add markup to a page for own trusted code- but content from any untrusted sources should be escaped and added as text (not markup) using properties like textContent
transform this into an arrorw function
1. with a return
2. with a default return
3. without parentheses
hello = function () {return "Hello World"; }
- hello = () => {return "Hello World";}
- hello = () => "Hello World";
- hello = val => "Hello " + val;
What is a js map object?
a map holds key-value pairs where the keys can be any datatype. it remembers the original insertion order of the keys and is an iterable object.
const fruits = new Map();
fruits.set("apples", 500);
fruits.get("apples"); // returns 500
fruits.has("apples"); // returns true if exist
fruits.clear() // removes all elements
const bananas = {name: 'banana'};
fruits.set(bananas, 300);
fruits.get("bananas") // returns undefined (catch the string)
what are classes in js?
JS classes are templates for JS objects. you can use the keyword class to create a class and always add a method constructor().
a JS class is not an object but a template for JS objects
e.g. class Car {
constructor (name, year) {this.name=name; this.year = year;}} const myCar1 = new Car("Ford", 2014);
what are promises in js?
- A Promise is a JavaScript object that links "Producing Code" and "Consuming Code“
- "Producing Code" can take some time and "Consuming Code" must wait for the result
- A JavaScript Promise object contains both the producing code and calls to the consuming code
- let myPromise = new Promise(
function(myResolve, myReject) { // "Producing Code" (May take some time)
myResolve(); // when successful
myReject(); // when error
});
// "Consuming Code" (Must wait for a fulfilled Promise)
myPromise.then(
function(value) { /* code if successful */ },
function(error) { /* code if some error */ } );
- let myPromise = new Promise(
what is jquery?
jquery is a script written in JS. it finds elements using CSS-style selectors and provides jquery methods to work with the elements
a function called jQuery() or $() lets you find one or more elements in the page.
what are similarities and differentces of jQuery to DOM?
Similarities
- jquery selectors perform a similar task to traditional DOM queries, but the syntax is much simpler
- the jQuery object can be stored in a variable, just like DOM nodes
- jQuery methods and properties (like DOM methods and properties) can be used to manipulate the DOM nodes that you select
Differences
- It is cross-browser, and there's no need to write fallback code
- selecting elements is simpler (because it uses CSS-style syntax) and is more accurate
- event handling is simpler as it uses one method that works in all major browsers
- methods affect all the selected elements without the need to loop through each one
- once you have make a selection, you can apply multiple methods to it
What is a Content delivery network?
- A CDN is a series of servers spread out around the world
- they are designed to serve static files (such as HTML, CSS, JS, image, audio, videos) very quickly
- the CDN tries to find a server near you , then sends files from that server so the data does not travel as far
- when including jQuery in your pages, you can try to load it from one of these CDNs
- it is a good practice to include a fallback version that is stored on your own servers in case the CDN version does not load
what is the jquery document ready event?
all jQeury methods are included inside a document ready event
this prevents the jQuery code from executing before the document is finished loading
if the jQuery code executes before the page is ready, some action may fail e.g. hiding an element that is not yet created
$(document).ready(function() {....});
What is AJAY?
- Ajax is a technique for loading data into part of a page without having to refresh the entire page
- The data is often sent in a format called JavaScript Object Notation (or JSON)
- The ability to load new content into part of a page improves the user experience because the user does not have to wait for an entire page to load if only part of it is being updated
- Ajax allows you to request data from a server and load it without having to refresh the entire page
- Ajax has led to the rise in single page applications (SPA)
what is an asynchronous processing model?
When a browser comes across a <script> tag, it will typically stop processing the
rest of the page until it has loaded and processed that script. This is known as a
synchronous processing model
➢ With Ajax, the browser can request some data from a server and - once that data
has been requested - continue to load the rest of the page and process the user's
interactions with the page
➢ It is known as an asynchronous (or non-blocking) processing mode
how does ajax work?
- the browser requests data from the server
- browsers implement an object called XMLHttpRequest to handle Ajay requests
- once a request has been made, the browser does not wait for a response from the server
- when the server has finished responding to the request, the browser will fire an event
- this event can be used to trigger a JS function that will process the data and incorporate it into one part of the page
// creates the request object
var xhr = new XMLHttpRequest();
//prepare request, third argument specifies if request is asynchronous or not
xhr.open('GET', 'data/test.json',true);
//send request
xhr.send('search=ardiuino');
xhr.onload= function() {if(shr.status ===200 {//process response}}
what is JSON?
JSON is a lightweight data-interchange format
it is self-describing and language independent. it uses JS syntax but the JSON format is text only.
what is typescript?
is a superset of JS - has specific rules about how different types of values can be used. has constructors that are missing in JS and is open source (designed at Microsoft)
how can you integrate typescript into your project?
via npm npm install typescript --save-dev
how does typeScript work?
- does not run in the browser
- it is transpiled i.e., compiled to create JS code
- the JS code can then be run in the browser or on the server-side inside Node.js
- tsc is the typeScript compiler
What is AngularJS?
- commonly used for single page applications (SPA)
- angularJS is a JS framework
- developed by google
- it can be added to a HTML page with a <script> tag using a CDN
What is Angular
- written in typeScript
- includes:
- a component-based framework for building scalable web applications
- a collection of libraries that cover a wide variety of features
- a suite of developer tools to help develop, build, test, and update the code
what is NodeJS
- open-source and cross-platform JS runtime environment
- node.js runs the V8 JS engine, the core of Google Chrome, outside of the browser
- node.js allows to write the server-side code in addition to the client-side code in the same language - JS
how it works
- a node.js app runs in a single process, without creating a new thread for every request
- node.js performs an I/O operation asynchronously: instead of blocking the thread and wasting CPU cycles waiting, Node.js will resume the operations when the response comes back
- event loop is responsible for handling simpler tasks and the thread pool manages the heavy tasks
What is the difference between Layers and Tier?
Layers are a way of organizing your code
Tiers are about where your code runs
what are the three common layers?
- presentation
- client
- presentation (server/browser)
- business
- data access/persistence
- integration data source
- resources legacy/db
what is the difference between a traditional vs a microservice way?
Traditional way
- built
- service.war
- application server
- bins/libs(JVM)
- operating system
- infrastructure
- deployment
- installation
- configuration of application server
- deployment and start of archive
- characteristics
- maintenance of the application server required
- dependency to application server and its configuration
- Jave EE Application Servers
Microservice way:
- build
- service.jar
- bins/libs (JVM)
- operating system
- infrastructure
- deployment
- just run it. java -jar service.jar
- characteristics
- easy to deploy
- fast start-up time
- self-contained Jar
- embedded Java Servers: spring boot...
What is Spring boot?
Is a Java based framework for building microservices
- spring-boot - convention over configuration
- simplifies the use of Spring-based technologies
- it builds easier thanks to preconfigured dependencies and auto-configuration
- it ships easier thanks to simple JAR packaging
- runs easier thanks to embedded servers.
What is apache maven?
is a build, project management and comprehension tool used primarily for JAva project
important maven elements to understand
- standard project structure
- POM(Project Object Model)
- Workflow
- Maven Central
- Build lifecycle
what is the apache maven standard project structure
every apache maven project is based on this standard project structure:
- the sry/main/java directory contains the project source code.
- the sry/test/java directory contains the test source
- the pom.xml file is the project's Project Object Model orPOM
What is the pom.xml file?
it is the core configuration of the apache maven project
it is a single XML-based configuration file that contains the majority of information required to build a project
it contains
- project identification
- project version
- project description
- build settings
- dependencies
what is a @postConstruct?
What are @Configuration and @Bean?
- @Configuration indicates that a class is a configuration class that may contain @Bean definitions.
- The @Bean can then be injected resp. @Autowired somewhere.
- @Bean annotation tells that a method produces a bean to be managed by the Spring container.
- @Bean is a method-level annotation and has an implicit @Scope("singleton") default value.