Week 5 Cumulative

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is the modulo operator? How is it useful?

% is the modulo operator and it is used to get the remainder of the division between two numbers.

What is the modulo operator and why would we use it?

% is the modulo operator and it is used to get the remainder of the division between two numbers. we might use it to determine if a number is even or odd by using the conditional statement num % 2 == 0.

How do you use increment and decrement operators?

++Sum is a prefix increment operator sum++ is a postfix increment operator --sum is a prefix decrement operator sum-- is a postfix decrement operator increment operators add 1 to the variable they are put next to, prefix before the expression the value is in finishes execution and postfix after the expression finishes execution. decrement does the same but subtracts 1.

What are shorthand assignment operators?

+= -= *= /= they are used to shorten the length of having to perform an arithmetic operation between both sides of the assignment operator sum += 2, is the same as sum = sum + 2

How would you access the last value in an array if you do not know the size of the array?

1. You can get the size of the array using the length value all arrays have [int length = array.length;] 2. You can loop through the array until you get an index out of bounds exception and use exception handling methods like try catch blocks and throws to handle the exception. 3. convert the array to a list and make use of a lists method to get the last element.

What are some common HTTP status codes that can be included in a response?

5 categories of status codes informational responses (100-199): 100 is continue Success responses(200-299): 200 is success, 201 is created redirection message responses(300-399): 300 multiple choice client failure responses(400-499): 400 is bad request (client error) 404 is not found (server cannot find requested resource) server failure responses(500-599): 500 is internal server error.

What is the difference between a checked and an unchecked exception?

A checked exception is caught at compile time while an unchecked exception is caught at runtime. the biggest difference between checked and unchecked exceptions is that checked exceptions are forced by compiler and used to indicate exceptional conditions that are out of the control of the program (for example, I/O errors), while unchecked exceptions are occurred during runtime and used to indicate programming errors (for example, a null pointer).

What are common HTTP verbs used when a client application is making a request?

A request contains the method used, the endpoint, and optional headers and a body A response contains the status code, status message, and optional headers and a body POST: request to create or update a resource. GET: request to retrieve data from specified resource. (most commonly used HTTP method). PUT: similar to POST but is idempotent (calling PUT multiple times always has the same result unlike POST which can have side effects). (use PUT to update and POST to create) PATCH: request to partially update an entity DELETE: request to remove a resource at the specified location. HEAD: similar to GET but does not return a list of users like GET might. (can check what GET returns before using GET). OPTIONS: request to get the methods that the server supports.

What is the difference between assigning and declaring a variable?

Assigning a variable: assigning a variable involves giving a data value to the symbol being assigned to. Declaring a variable means saying that the symbol will hold a value of the given data type. assigning a variable means giving a variable a value to hold. int a; declaration int a = 3; assignment

What is autoboxing and unboxing?

Autoboxing is the automatic conversion made by the Java compiler between the primitive types and their corresponding object wrapper classes. For example, the compiler converts an int to an Integer, a double to a Double, and so on. If the conversion goes the other way, this operation is called unboxing.

What is the difference in syntax between calling a method and creating a method?

Call a method: [meth(arguments);] Create a method: [public void meth(datatype parameter1, datatype parameter2){}]

Can you describe some of the basic entities of a Java program?

Class: is a template used to instantiate objects. It's also called a type when used with a reference variable. A class that is used to instantiate an object determines what state and behavior an object will possess. Method: A method is a block of code that we can invoke again and again. Methods in java usually represent some sort of action. Variable: a way to store data within code, you assign data values to names so that they may be used later in the application. Main Method: The main method is the primary location where code begins executing for a Java program. typically when you execute a java program the main method is called and all other methods and actions are called within the main method.

What are the SQL sublanguages and their purpose?

DDL: Data definition language and involves things like defining data structures in a database. CREATE, ALTER, DROP, TRUNCATE, RENAME DML: Data manipulation language lets you insert, update, delete records. INSERT, UPDATE, DELETE DCL: Data control language lets you change or add access permissions to database objects. GRANT, REVOKE TCL: Transaction control language defines concurrent operation boundaries. COMMIT, ROLLBACK, SAVEPOINT DQL: Data query language Search, filter, group, aggregate stored data. SELECT

What is a foreign key?

Define: A FOREIGN KEY is a field (or collection of fields) in one table, that refers to the PRIMARY KEY in another table. Why is it Important: They are important because they make up the relational part of relational databases. by having fields that point to other tables fields we can perform queries that take into account more than one table. Implementation: you can create a foreign key by altering the table it is in and making one of the columns in that table reference a column in another table. Real World Example: [ALTER TABLE table1 ADD FOREIGN KEY (emp_id) REFERENCES table2(emp_id);]

Describe abstraction and how would you use it in a project?

Define: Abstraction is a programming principle in which we centralize common characteristics and generalize behavior into conceptual classes. In the example above, the Animal class contains characteristics and behaviors common to all animals. Through abstraction, we hide underlying complexity through a simplified interface. Think of a car - you do not need to know how the car works, just how to use the accelerator, brake, and steering wheel. Thus, a car "abstracts" away the internal details of the engine, motor, driveshaft, and other parts. Why is It Important: Abstraction is important to hide the details of implementation from the user and only show the essentials. Implementation: abstract classes use the abstract keyword on themselves, they cannot be instantiated (can't create objects) and can hold abstract methods. a class that inherits from an abstract class must override inherited abstract methods to give them behaviors, or if the child class is itself abstract they must Real World Example: [abstract class Shape {}]

Why would you use an interface over an abstract class?

Define: An interface is similar to an abstract class, but there's a key difference: A class can only inherit one other class, but a class can implement as many interfaces as it needs. To inherit interfaces, a class must implement them and they are REQUIRED to implement all methods, unless the class is abstract. Why is It Important: You might use an interface instead of a class because you don't need to provide implementation details in an interfaces method declaration, and a single class can implement more than one interface, but they can only extend from one parent class. Implementation: To implement an interface you need to use the implements keyword in the class definition and provide implementation for all interface abstract methods. methods in interfaces are public and abstract by default, and variables are public static final. Interfaces like classes can extend from a parent interface inheriting its behaviors and values. you can have default implementations for methods in interfaces and you can make static methods in interfaces. Real World Example:[public interface Abstractor { String computeOutput(..); }]

What is a view and why is it useful?

Define: In MySQL, a view is a virtual table based on the result-set of an SQL statement. A view consists of rows and columns, just like a common table. The view fields are fields from one or more real tables in the database. Why is it Important: Views are important because they are self created tables that can have conditions on what is put into them, you can make a view of all employees over the age of 40 so that an SQL statement can make use of that view instead of going to the employee table and checking if their age is over 40. Implementation: to create a view use a SELECT statement to gather a group of rows and place a condition on what rows are selected and use a GROUP BY operator to sort them in a way you want. Real World Example: [CREATE VIEW [US Employees] AS SELECT EmployeeName, EmployeeID FROM Employees WHERE Country = 'US';]

Describe inheritance and how would you use it in a project?

Define: Inheritance is about a subclass or child class gaining the common state and behaviors of its parent class (super class). There are 4 types of inheritance Single (only one parent no grand parent), Multi-level (in a structure where a child class has its own child) , Hierarchal (a parent has multiple children), and Multiple (a child has multiple parents). Why is It Important: inheritance allows us to go from the general idea of an object like a person to a more specific version of that object like an Artist. (an artist is a person but a person is not always an artist). In programming it allows us to share common attributes and behaviors among similar classes. Implementation: to implement inheritance in your program have a class extend another class to inherit it's behaviors and default state. use the super() keyword to reference the parent class like you would use the this keyword to reference the current instance. Real World Example: [Public class Artist extends Person{}]

How can JUnit annotations help with running our tests?

Define: JUnit annotations are a form of metadata that provide information about the unit test being done. Which the framework then uses to execute the unit test. Why is It Important: They are important because the metadata they provide informs the Java Framework how to execute each of the JUnit tests, like the @AfterEach annotation tells the framework that the JUnit will be run after each test. Implementation: Some of the JUnit annotations are @Test, @BeforeEach, @AfterEach, @BeforeAll, @AfterAll, @Repeat(num) and more. they are placed before the JUnit declaration. assertTrue, assertEquals, assertNull, assertSame and their negative equivalents are the assertions for JUnit testing. Real World Example:

Describe what a join is and explain the different types of joins we can create.

Define: Join is used to get a view of multiple tables at the same time. the view will combine columns and rows from the tables based on the type of join and if they have matching references to the other table. Why is it Important: they are important for viewing results from more than one table at once. and finding rows that have relationships with each other. Implementation: Left Join: all entries of left table and matching entries of right table, using null where there are no matching values. Right Join: all entries of the right table and matching entries of the left table, using null where there are no matching values. Inner Join: only show matching records from left and right tables on the column specified. FULL Join: takes all records from both tables showing overlap where matching values exist. CROSS join: returns all possible combinations of rows between the two tables; SELF join: joins a table to itself. (used if foreign key points to own primary key). Real World Example: Inner join is the most commonly used join in SQL [SELECT * FROM table1 INNER JOIN table2 ON t1_ID = foreign_ID;]

What is normalization?

Define: Normalization is the process of efficiently organizing data in a database. The two main objectives of normalization are, eliminate redundant data ie to make sure that the same data is not stored twice and to ensure data dependencies make sense. Why is it Important: Normalization is important because without it databases could have large amount of repeated entries with redundant information. Space is saved and complexity is reduced. Implementation: There are many forms of normaliztion each building on the last, we will go over the first 3 which are standard. N1: all the fields in the tables are atomic. it can also be described as the elimination of recurring groups of relations.1NF doesn't allow hierarchies of data values. N2: eliminate circular dependencies all non-key attributes must only depend on the primary key and nothing else. (a key attribute could be used to uniquely identify the table) N3: Third normal form (3NF) deals with the elimination of non-key attributes that do not describe the Primary Key.For a relation to be in 3NF, the relationship between any two non key attributes, or groups of non-key attributes, must not be in a one to one relation. Real World Example: Watch video again

Describe the POM.xml file and its importance.

Define: POM stands for Project Object Model and POM files hold the meta data about dependancies and project location, and plugins. POM files have several tags including <project> (root tag of file) <modelVersion> (pom model version) <name> (name of object) <properties> (object setting) <dependencies> (groupID (package group), artifactID (file name), version) <plugins> (third party plugins for Maven) Why is It Important: POM files are important because without the meta data they contain Maven would not be able to properly handle the dependencies between different files. Implementation: Similar in structure to an HTML file with all the tags used Real World Example:

What are constraints and can you describe a few constraints?

Define: SQL constraints are used to help validate data beyond just a simple data type Why is it Important: Constraints are used to define a database schema and are the backbone for defining integrity constraints of the schema. Implementation: some commonly used constraints are 1. NOT NULL (the attribute for this TUPLE cannot be empty) 2. UNIQUE (no other TUPLE can have this value in this column) 3. PRIMARY KEY (combines UNIQUE and NOT NULL) 4. Foreign Key (link to a row in another table preventing destruction of those links) 5. DEFAULT (if no value given provides a defualt value) 6. CHECK (checks if the entered value satisfies a specified condition) 7. CREATE INDEX (Create a sorted index of the column for faster searching.) Real World Example: you can add constraints when the table is created or after when you alter the table

What is SQL Injection and how can we prevent it using the JDBC?

Define: SQL injections are hacking attacks on your database by injecting a change in your SQL statement through needed user input. To prevent SQL injection attacks you can use prepared statements that verify user input and prevent SQL injection attacks, or verify all user input yourself for any special characters that shouldn't be there. Why is it Important: preventing SQL injection attacks are important because if they can get through then the security of your Database becomes compromised and data in it could be stolen or destroyed by a malicious hacker. Implementation: even when using prevention techniques like prepared statements you are not 100% safe from SQL injection attacks, so always be on the lookout and make sure to verify data through user data sanitization. Real World Example: [SELECT * FROM table WHERE id = 'abc OR '1' = '1';] returns all table tuples.

What is HTTP? Why is it important to know about?

Define: Stands for Hyper Text Transfer Protocol. A technique of transmitting data in a particular format, primarily between a server and a browser. It uses an architecture in which a client makes a connection to a server, makes a request, and waits for the response. Why is it Important: HTTP is the most commonly used transfer protocol and is easy to use. HTTP has API's supported in multiple coding languages and is capable of transferring almost any data over the internet. HTTP is extensible meaning it can change if needed. Implementation: A server is a computer or collection of computers that is the destination of the HTTP call. Commonly, this will be a powerful collection of computers that have an increased level of computation power and data storage compared to the client. A client is a computer or collection of computers that is the creator of the HTTP call. Commonly, this will be a single, personal computer. Real World Example: When a HTTP request and response is completed the server stores no record of that request (it is STATELESS) can still log transaction in a database. HTML is files are a commonly used HTTP thing.

What is SQL and why would we use this language?

Define: Structured Query Language or SQL is the standard language for working with RDBM systems. SQL is used to administer and manipulate SQL servers. SQL is a scripting language that is interpreted by the database server. SQL is used to, Define database structure, Manipulate stored data, Define data access permissions, Control concurrent data access, Query stored data. To accommodate the operations of the above categories, SQL is broken into 5 sublanguages Why is it Important: Without the use of SQL we would not be able to effectively interact with RDBMS's and perform actions like SELECT, INSERT, UPDATE, and DELETE on the persistent data stored within. Implementation: We can implement SQL through the use of a RDBMS vendor like Oracle or MySQL. Real World Example: [SELECT * FROM tableName;] returns all rows in the table called tableName;

What is multiplicity?

Define: The Multiplicity is the constraint on the collection of the association objects whereas the Cardinality is the count of the objects that are in collection. It actually acts as a constraint on cardinality. A multiplicity is made up of a lower and an upper cardinality. It tells you the minimum and maximum allowed members of the set. Why is it Important: multiplicity is important because it helps with modeling database creation in ERD's and through those models we know which tables need foreign keys to which other tables or if junction tables need to be created. Implementation: 1:1 relationship: the table that references the other table must have the UNIQUE constraint on is foreign key column. 1:N relationship: The "many" table will have a foreign key point to the primary key of the one table. N:1 relationship:The "many" table will have a foreign key point to the primary key of the one table. N:M relationship: a third junction table needs to be created that has a foreign key to both tables. Real World Example: a one to many relationship is albums to songs, because an album can have many songs, but each song belongs to one album.

Why would I use the WHERE clause?

Define: The WHERE clause is is responsible for filtering the results of a query statement. Why is it Important: It is important because it allows a query to select very specific tuples based off of conditional statements. Implementation: The conditional statements of the WHERE clause make use of several logical operators; AND, OR, NOT, IN, LIKE, and BETWEEN. Real World Example: [SELECT * FROM table WHERE id = 5;]

What is the SDLC? Why is it important?

Define: The software development lifecycle is the standard business practice for building software applications. It's typically divided into six to eight steps: Planning, Requirements, Design, Build, Document, Test, Deploy, Maintain. Some steps might be skipped or omitted depending on the scope of the project that you are working on. Why is It Important: 1. It provides an effective framework and method to develop software applications. 2. It helps in effectively planning before starting the actual development. SDLC allows developers to analyze the requirements. 3. It helps in reducing unnecessary costs during development. During the initial phases, developers can estimate the costs and predict costly mistakes. 4. It enables developers to design and build high-quality software products. This is because they follow a systematic process that allows them to test the software before it is rolled out. 5. It provides a basis when evaluating the effectiveness of the software. This further enhances the software product. Implementation: Planning: estimate cost, create timetable, gather feedback, create goals, build team. define scope and purpose Requirements: Defining requirements is considered part of planning to determine what the application is supposed to do and its requirements.also include defining the resources needed to build the project Design: models the way a software application will work (architecture, user interface, platform, programming, communications, security) Development: start writing code for the application and document user guides for the application. Testing: run your application through different tests to make sure that it works. Deployment: make application available to user Maintenance: work after deployment to fix errors that appear and keep the application operational. Real World Example:

Why are unit tests important?

Define: Unit testing is the testing of individual software components in isolation from the rest of the system, meaning that we test only certain portions of the final product, rather than the whole product itself. This is done by writing unit tests which execute the code we want to inspect. When the code under test deviates from an expected outcome or behavior, the test will fail. If a test passes, it means the application performs as expected (unless there is a problem with the test itself). In Java, the most common unit testing framework is called JUnit. Why is It Important: Unit testing helps testers and developers understand the root causes of errors. Unit testing helps with documentation. Unit testing fixes defects early in the development phase. Unit testing helps with code reusability Implementation: Junit is the most commonly used unit testing framework for Java, here are some of its advantages. 1. Annotations are used to support, identify, and execute test method features. 2. Assertions are used to check actual output versus expected output. 3. It provides Test Runner for executing the tests. 4. JUnit provides a basic built-in template so that you may write small, simple test cases in no time. 5. JUnit tests help you to write independent modules, thereby bettering the coverage of the test and the quality of the application Real World Example:

When would you use an Agile methodology versus Waterfall?

Define: You would use agile instead of waterfall when you are working on a complex project, or one that needs to constantly adapt to client requirement changes. You would prefer waterfall in situations where a human life is at stake and safety/stability is more important than speed and cost savings. agile is a cyclical iterative process while waterfall is a linear sequential process. Why is It Important: It provides a responsive approach to the development of software since it involves user and customer input. Agile is intended for everyone to focus on one task at a time. When compared to the waterfall model, the Agile model has a reduced scope which results in better time allocation and estimation. Implementation: Agile has 4 core values 1. individuals and interactions over processes and tools. 2. working software over comprehensive documentation. 3. customer collaboration over contract negotiation. 4. responding to change over following a plan. additionally some key components of project management are user stories (short user functionality requests), sprints (short periods of time where the team works on some specified requirements), stand up meetings (10 minute meetings where team members detail their progress, goals, and issues they may have), agile board (tracks team progress), and backlog (list of user stories to be addressed during sprint iteration) Real World Example: Waterfall is used in the military where requirements are clearly defined from an early stage and development requires a lot of documentation and oversight. modern software companies like Google or others make use of agile.

What is Maven? Why would we use it?

Define: a dependency manager and build automation tool for Java programs. Maven project configuration and dependencies are handled via the Project Object Model, defined in the pom.xml file. This file contains information about the project used to build the project, including project dependencies and plugins. Maven helps with simplifying the build process, adding jars and dependencies, integration with Git, and documents project changes. Why is It Important: Maven is important because Maven is chiefly used for Java-based projects, helping to download dependencies, which refers to the libraries or JAR files. The tool helps get the right JAR files for each project as there may be different versions of separate packages. After Maven, downloading dependencies doesn't require visiting the official websites of different software. You can visit mvnrepository to find libraries in different languages. The tool also helps to create the right project structure in struts, servlets, etc., which is essential for execution. Maven is also used by a lot of industries and companies outside of just computer science. Implementation: To install Maven you first need to install Java, and have the java environmental variable set. Next unpack the Maven zip file and create a directory for Maven. Real World Example:

What is the difference between a Simple and Prepared JDBC statement?

Define: a simple statement will take in a SQL instruction as a string and execute that instruction, while a prepared statement has a string that contains placeholder ? marks for values that can be updated and changed through functions. Statement does static sql statements, while prepared does pre-compiled sql statements. ? can only be for values not things like column or table names. Why is it Important: Prepared statements are important because they protect against SQL injection by validating user input and preventing special characters to be given that would change your SQL statement. Implementation: to create a statement you first create a connection to the database then using that connection perform a createStatement() method to return a new statement. Use the executeQuery(sql) method to execute a given sql statement and return a resultSet object. to create a prepared statement create a connection, have that connection use the preparedStatement(sql) method with your sql string with ? marks in it. use the returned preparedStatement object to perform setBlank methods to provide values for the ?. after setting all values use executeQuery(sql) to get a resultSet object. Real World Example:

Describe relational database tables.

Define: a table is a RDB object that stores and organizes data in columns(Attribute), rows(TUPLE) and constraints, where each row is a single data instance, each column represents and aspect of the data like name or id number, and constraints limit what can be put into the table or column. All tables in a RDB have a primary key which is a specific column in the table where each data instance MUST have a different value to differentiate data instances. Why is it Important: tables are important because RDB's store data in them and connect the to each other through foreign keys creating relations between different tables. through these relations we can use SQL queries to manipulate and select specific data instances in convenient ways. Implementation: first you need to create a database to put tables in then you would use SQL to CREATE a table that you want. Using SQL you can CREATE (new table), DROP (remove table), TRUNCATE(remove table data), or ALTER(changes the table) tables. Real World Example:

Describe encapsulation and how would you use it in a project?

Define: is the OOP principle of containing related state and behavior together inside a class, and also hiding and preventing change to an object's data members. An object encapsulates or controls the access to its internal state (through getter and setter methods). This prevents arbitrary external interference, which could bring the object into an invalid or inconsistent state. Why is It Important: Without encapsulation there could be errors in your program where data from a class is accessed when it doesn't need to be or changed causing errors in the program. This is especially important in the industry since programs are not written by one person but multiple teams of people over time. You can't assume someone else working on your code will know everything you know about it. Implementation: The act of creating classes means that you are following encapsulation, adding getter and setter methods to those classes to control the input and output from the class and setting all member variables to private is following encapsulation. Real World Example:

Describe polymorphism and how would you use it in a project?

Define: means "taking on many forms". In the realm of programming, it describes how objects can behave differently in different contexts. The most common examples of polymorphism are method overloading, method overriding, upcasting and downcasting. overloading is for multiple methods with the same name and different parameters within the same class, overriding is for modifying a method inherited from a parent class, upcasting is when you cast an object to be its parent class (this is safe and no data is lost, and is done automatically by java compiler), downcasting is the process of casting an object of a superclass to an object of its subclass. Downcasting is a risky operation because it may result in a ClassCastException at runtime if the object being cast is not actually an instance of the subclass. (To avoid this, it is recommended to use the instanceof operator to check if the object can be safely downcasted) Why is It Important: In object-oriented programming, Polymorphism provides the means to perform a single action in multiple different ways. Taking the real world example of animals, if we ask different animals to speak, they respond in their own way. Dog barks, duck quacks, cat says meow and so on. So the same action of speaking is performed in different ways by different animals. Implementation: for static polymorphism have two or more methods with the same name and different parameters in a class, for dynamic polymorphism have a method inherited from a parent class with different behavior/parameters. Real World Example: having a math method that is able to take in strings a parameters as well as integers.

What is referential integrity?

Define: referential integrity is a type of constraint for tables with foreign keys that maintains the integrity of the entries in the table. if a foreign key points to the primary key of another table, the table won't allow entries in it that don't contain a value matching the primary key in the table it is referencing for the foreign key column. Additionally referential integrity prevents direct deletion of a record in a parent table that is being referenced without first deleting the record that is referencing it. can be solved by using CASCADING delete. Why is it Important: This is important because without referential integrity a tuple in one table might be referencing an item in another table that does not exist. Implementation: this constraint is implemented automatically into most RDBMS that are used today. Updating and Deletion in primary key table and Insertion and Updating in the foreign key table can violate the referential Integrity. Real World Example: Say you have a table for employee information and a table for department information. employee has a foreign key referencing department_id. if the department table only has entries 1, 2, and 3 for department_id you can't have an employee entry working in department 4 as that does not exist.

What is the DAO Design Pattern and why should we use it?

Define: stands for Data Access object and the design pattern basically states that you should build objects who's sole responsibility is to access data inside of a database. Why is it Important: The DAO design pattern is commonly used in projects where you need to access a database. It is important to use DAO's because they decouple business logic from code that accesses the database. adding a degree of separation from direct database access and user input. they make your code flexible in case you have to change your database to another provider. Implementation: To implement you need three things 1. Create an interface that defines data access methods (like insert, update, delete, retrieave) CRUD 2. Create subclass that implements those methods 3. model classes that represent the data that you are retriveing ( will hold the values retrieved if that is what you are doing). Real World Example:

What is the JDBC API and the benefits of using it?

Define: stands for Java Database Connectivity, and is used to write java code that can interact with a SQL relational database. Why is it Important: The JDBC API is important because it makes it easier and more convenient for the programmer to interact with a database by following some simple steps. You are able to execute SQL statements using JDBC through a Statement, PreparedStatement, or CallableStatement Object and get back a ResultSet Object which contains data from the database. Implementation: Statement takes in a string as an sql statement to be set and returns a result set that contains the rows of data returned. PreparedStatement protects against sql injection and allows you to put ? into the string for changeable values. preparedStatement.setInt(1,5); preparedStatement.setString(2,"hello"); Real World Example: Statement sta = conn.createStatement() // where conn is a Connection object String sql = "Select * from table;" ResultSet result = sta.exequteQuery(sql);

What is a RDBMS?

Define: stands for Relational Database Management System, that is a set of software that allows programmers to create, administer and update relational databases. Why is it Important: RDBMS is incredibly widespread and essential in large scale application development. RDBMS's have structured data model, large scale concurrent data access, fault tolerance, distributed data storage, enforced data integrity, support for multiple client types. used to store persistent data Implementation: Things to consider when choosing a RDBMS vendor; scalability, vendor license (cost), security features, and support. Also consider your distribution type; Standalone (Individual work most effort to scale), Containers (container images like docker), Managed (AWS easiest to scale). Real World Example: OracleDB, PostgreSQL, MySQL are all RDBMS providers.

What is test driven development?

Define: the TDD process consists of writing unit tests first, before the implemented application code has been written. Then, the implemented application code can be written to make the test pass and the process can be completed for each piece of functionality required. Thus, the process is: 1. Design interface/function 2. Write tests that use that function in many different ways 3. Refactor method signatures to ensure that the functions are intuitive in usage 4. Implement functions 5. Run tests to verify functionality. Why is It Important: Following the TDD process can be useful for ensuring that a valid unit tests always exists for any class or method that is written. Later, when refactoring code, the unit tests give us confidence that we can change the source code without breaking existing functionality. If we mess up somewhere, when the unit tests are run we can pinpoint exactly where the problem lies. This makes debugging much easier. Implementation: Real World Example:

What is a method?

Definition: A method is a block of code that we can invoke again and again. Methods in java usually represent some sort of action. Why is it Important: they prevent redundant lines of code because they are reusable. they also allow objects to have behaviors to them and actions they can perform. Implementation: can be declared in a class and is given a access modifier, return datatype, method name, and parameters. Real World Example: [public void meth(datatype parameter1, datatype parameter2){}]

What is an array? Why is it useful?

Definition: An array is a contiguous block of memory storing a group of sequentially stored elements of the same type. Arrays in Java are of a fixed size and cannot be resized after declaration. an ArrayList is different in that it does not have a fixed size you can continue to add more and more elements to it. Why is it Important: arrays are useful for storing lists of related elements so that any element can be accessed quickly. arrays are objects created with the new keyword and as such make use of a reference variable. Arrays are faster than ArrayLists because adding elements to an array list can cause it to have to create a new array of a larger size to hold all the elements. Implementation: to declare an array specify the data type it will hold and brackets, to access and index in the array make use of brackets as well. [array[2]] will return the element at index 2 of the array. Real World Example: [int[] array = new int[5];] declares an integer array that can hold 5 elements starting from index 0. [ArrayList<Integer> array = new ArrayList<>();] declares an array list.

What is the difference between an array and an ArrayList?

Definition: An array is a contiguous block of memory storing a group of sequentially stored elements of the same type. Arrays in Java are of a fixed size and cannot be resized after declaration. an ArrayList is different in that it does not have a fixed size you can continue to add more and more elements to it. Why is it Important: arrays are useful for storing lists of related elements so that any element can be accessed quickly. arrays are objects created with the new keyword and as such make use of a reference variable. Arrays are faster than ArrayLists because adding elements to an array list can cause it to have to create a new array of a larger size to hold all the elements. Implementation: to declare an array specify the data type it will hold and brackets, to access and index in the array make use of brackets as well. [array[2]] will return the element at index 2 of the array. Real World Example: [int[] array = new int[5];] declares an integer array that can hold 5 elements starting from index 0. [ArrayList<Integer> array = new ArrayList<>();] declares an array list.

What is the difference between an Error and an Exception?

Definition: Error refers to an illegal operation performed by the user which results in the abnormal working of the program (compile time errors, runtime errors, logical errors). Exceptions are the conditions that occur at runtime and may cause the termination of the program. But they are recoverable using try, catch and throw keywords. (checked and unchecked exceptions). Why is it Important: (compile time errors need to be fixed for the application to compile, runtime errors need to be fixed for the application to run, and logical errors need to be fixed for you program to produce the correct result.) (checked exceptions can be recovered from with the try catch keywords or throws, but checked exceptions must be fixed for the application to run). Implementation: An error is an issue in a program that prevents the program from completing its task (Syntax). In comparison, an exception is a condition that interrupts the normal flow of the program (Null pointer or divide by 0 exception). Real World Example: StackOverflowError, ArithmeticException.

What does the term "full stack" mean?

Definition: Full stack technology refers to the entire depth of a computer system application, and full stack developers straddle two separate development domains: the front end and the back end. Front End: part of the application that the user interacts with GUI or CLI. Back End: Application Logic, responding to front end, and interacting with databases. Why is it Important: It is good for software developers to have an idea on both the front end of an application and the back end so that they can easily adapt to fill the role that is needed. Implementation: Real World Example:

What is an operating system?

Definition: Is the main software of a computer. OS X, Linux, and Windows are the main 3 OS's. OS X runs on macs Linux and Windows Runs on PC. OS's store information in a file system. You can interact with the OS through a command line interface (terminal) or Graphical User Interface. Why is it Important: The four main roles of an OS is to provide security, manage the processes of the computer, interact with devices, and interact with computer hardware. Implementation: Real World Example: OS X, Windows, and Linux

What is a primitive datatype? Please list a few and explain them.

Definition: Simple non-complex values, take in space in short term memory (stack) § Boolean: 1 bit (true or false) § Byte: 1 byte (whole numbers) § Short: 2 bytes (whole number data type) § Character 2 bytes ( for character) § Int: 4 bytes (whole number) § Float: 4 bytes (decimal numbers) § Long: 8 bytes (longest whole number data type) § Double: 8 bytes (decimal datatype default)

What is the Scanner class used for? Give an example of how you would use it.

Definition: The Scanner class is used to read in input from a user through either a file, console or other form. Why is it Important: The Scanner class is important because it provides a means of interaction between a user and the program while the program is running. Implementation: to make use of the Scanner class you need to create a scanner object and assign it to a reference variable, using that scanner object you can call methods like nextLine() and assign it to a String variable. Real World Example: [Scanner scanner = new Scanner();] [String text = scanner.nextLine(System.in);] [scanner.close();]

Explain the main method.

Definition: The main method is the primary location where code begins executing for a Java program. typically when you execute a java program the main method is called and all other methods and actions are called within the main method. Why is it Important: The main method is imporant because it is the entry point for code execution in a java program. Implementation: Real World Example: public static void main(String[] args){}

What is a variable?

Definition: a way to store data within code, you assign data values to names so that they may be used later in the application. Why is it Important: they hold data. Implementation: datatype variableName; Real World Example: int num;

What is a conditional statement?

Definition: if, else, else if, these statements use conditions to direct the flow of the program. switch statements are also conditional. Why is it Important: they are important because they allow for branching paths in code based off of certain conditions. Implementation: Real World Example:

What is a stacktrace? How can you use it to debug your application?

Definition: the purpose of a stack trace is to help find the problem in your application so you can resolve it. it appears in your console when you encounter an error/exception. Why is it Important: stack trace is an important debugging tool as it can tell you what the cause of the error/exception was and where it happened. Implementation: it appears in the console when an error / exception occurred, it gives you the thread the problem happened in the error/exception that was thrown, sometimes a small explanation for the problem, and then the line in the file where the problem happened. Real World Example: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3 at Main.main(Main.java:4)

What is a constructor and how is it different from a method?

Description: A constructor declares how an object is to be instantiated and initialized from the class "blueprint". A constructor is declared like a method, except its method signature does not contain a return type, and a constructor always has the same name as the class. The new object created by the constructor is always of the class in which the constructor is declared. Why is it Important: When an object is created some actions might need to happen like assinging its member variables values or calling internal methods. constructors allow for that to happen. Implementation: within a class like a method a constructor is declared except it does not have a return type and the name of the constructor is the same name as the class. every class has a default constructor with no arguments that does nothing, you can have multiple constructors as long as they have different arguments. Real World Example: [public Constructors(int value){}]

What is a package and why would we use one?

Description: A package is a collection of classes, interfaces, and enums organized in a hierarchal manner. Why is It Important: They allow the reuse of classes and interfaces between programs, give your classes to other people, and keep them separate from the Java API. Implementation: the very first line of a .java file, to package the class in that file type [package packageName;] to create a folder to hold that package of classes. If you want to use multiple folders separate them with periods like [package com.revature.myPackage;]. Real world Example: after you have created packages they can be imported into other programs using the import keyword at the top of the file. [import java.util.*;] imports all packages in the java.util file.

Describe what an object is.

Description: An object is an instance of a class in memory. In Java, you never interact with objects directly. Instead, you interact with them through their reference, which is the memory address used by the JVM to find a particular object. Why is it Important: objects are the key building block for OOP as creating instances of classes allows for organized and reusable coding. Encapsulation of data. Implementation: use the new keyword and the given class name the object is for, and assign that value to a reference variable pointing to the location of the object in memory. Real World Example: [ArrayList<Integer> array = new ArrayList<>();]

What is the role of garbage collection in Java?

Description: The process of removing objects from the heap that have no reference to them. Why is it Important: garbage collection is important because it frees up memory for new objects to be created. without GC we run the risk of using up lots of memory with unused objects if we are not careful with them. Implementation: garbage collection is always running in the background by the JVM and we cannot force it to happen, but there are some commands we can use to request for garbage collection. Real World Example: System.gc(), Runtime.getRuntime().gc() Object o1 = new Object(); Object o2 = new Object(); Object o3 = o1; o2 = o3;

What is the difference between using an instance variable and a static variable?

Description: a static variable is the property of a class, not any object that is created from the class blueprint. while an instance variable is the property of an instance of the class (the object created). Why is it Important: This is important because sometimes you want to have values or methods in a class that can be accessed without needing to create an instance of that class. Often when that value is common for all objects created. Implementation: to declare a variable as static all you need to do is add the static keyword before that variables datatype. Real World Example: [static double pi = 3.14;]

What is explicit and implicit casting?

Description: explicit casting is when you specifically type cast a given variable to a different data type through the use of (datatype) next to the variable. implicit casting happens automatically in some expressions where datatypes are converted to another datatype for the expression to evaluate. Why is it Important: there could be situations where you need one variable you have to act like another variable datatype like if a method needs an argument of double but you have an int variable you want to put into it. implicit casting allows for ease of using multiple number datatypes in math expression. Implementation: (int)num converts num variable to an integer value. Real World Example: 2.0 * 1 = 2.0

What are classes used for?

Description: is a template used to instantiate objects. It's also called a type when used with a reference variable. A class that is used to instantiate an object determines what state and behavior an object will possess. A class used as the type for a reference variable determines what behaviors of an object can be invoked, and how any variables get initialized. Why is it Important: classes are important to act as blueprints for creating objects in Java creating the foundation for OOP. Implementation: To create a class you need and access permission keyword followed by the class keyword followed by the className you want and {}. A class can have member variables and methods as well as constructors. Real World Example: [public class HelloWorld{}]

If there was an error in the console when you tried to run your program, how would you debug?

First I would read the error message to determine the type of error and the line where the error took place. following the stack trace of the error message, I would either print out the values of variables or use a debugger tool to find there values to try and determine what went wrong.

Explain the different kinds of loops you can create and use in a program.

For Loop: iterates through its block of code a certain number of times depending on its a declaration, condition, and statement (typically increment or decrement). While Loop: While statements test a condition - if the condition evaluates to true the block of code is run, otherwise the block is skipped. The block is looped through as long as the condition remains true. Do While Loop: An alternative to while loops is the do-while loop. This guarantees that the block will always run at least once..

Give me an example of why you would need to create a method other than the main method.

If there is a block of code that you repeatedly use throughout your program over and over again, you can create a method to shorten the amount of code in your program. Also another reason is to give objects behaviors through methods that they can call upon.

What are the different scopes in Java?

Instance, or object, scope: Instance scope means that the variable is attached to individual objects created from the class. When an instance-scoped variable is modified, it has no effect on other, distinct objects of the same class. Class, or static, scope: Class scoped variables reside on the class definition itself. This means that when objects update a class-scoped variable, the change is reflected across all instances of the class. Class scope is declared with the static keyword. Method scope: Method scope is the scope of a variable declared within a method block, whether static or instance. Method-scoped variables are only available within the method they are declared; they do not exist after the method finishes execution. Block scope: Block scoped variables only exist within the specific control flow block, of which there are several in Java: for, while, and do-while loops, if/else-if/else blocks, switch cases, or even just regular blocks of code declared via curly braces ({}). After the block ends, variables declared within it are no longer available.

What is the difference between the JDK, JRE, and JVM?

JDK: Java Development Kit (holds the JRE and development tools like compiler and debugger) needed to compile java code. JRE: Java Runtime Environment (holds the JVM and java libraries) JVM: Java Virtual Machine (special program that knows how to execute what you write in java) it runs our compiled byte code so Java can execute on any machine with a JRE.

What are some of the benefits of Java?

Java has automatic memory management through garbage collection so developers don't have to pay attention to deallocating memory when an object is no longer being referenced. Java is able to be run on any device with a JRE since it makes use of the Java Virtual Machine. Java is a popular language so it has a large built in library with many features. Java is an Object Oriented Language allowing for the creation of organized and reusable programs.

How is method overriding different from method overloading?

Method overloading is when there exist two or more methods in a class with the same method name, but different method signatures by changing the parameter list. We can change the number of parameters, the types of the parameters, or the order in which the parameters are passed. Which version of the method is executed is determined by the parameters passed when the method is invoked. Note that varying the return type of the method alone is not permitted in some OOP languages. Because the argument list is known at compilation, the compiler knows which version of the method will be executed. Therefore, method overloading is a type of compile-time - or static - polymorphism. Method overriding is when child class modifies a method that it inherits from a parent class overriding the behavior of that method to suit the needs of the child class. This adds flexibility to the class hierarchy dynamic. overriding is considered to be run-time or dynamic polymorphism due to the method called being determined by the object referred to in memory. static methods of a parent class cannot be overwritten but are instead if a child class implements the same static method of a parent class the method becomes hidden.

How would you handle an exception?

Place risky code inside of try catch blocks. have the method signature include the throws keyword and the types of executions that the method will throw.

What are the four levels of access we can give to class members? How are they different from one another?

Public: The member with public modifiers can be accessed by any classes. The public methods, variables or class have the widest scope. Default: When no access modifier is declared the default access modifier restricts access to calls within the same package as the item. Protected: The member with protected modifiers can be accessed by its own class and any class that inherits from it (so any child class can access it). can be accessed outside of package through inheritance. (only a nested class can have protected access modifier). Private: The member with private modifiers can be accessed only by its own class. private is the most restrictive access modifier, and only a nested class can have private as its access modifier.

What steps would you take to debug your program if it crashed with an error message in the console?

Read the stack trace of the error message to try and determine what when wrong. If it is an error message then it might not be a problem with the program and might be a problem with the machine or some other factor. I would after reading the error message I would google similar problems to try and find a solution if I can't think of one on the spot.

What are some operators that can be used in SQL?

SQL can use comparison and arithmetic operators in SQL statements (=, <, >, <=, >=, !=) and (+,-,*,/,%). Between: LIKE: NOT: GROUP BY: WHERE:

What are the SOLID design principles and are they important?

Single Responsibility Principle: SRP states that a class should have only one reason to change. This means that each class should have only one responsibility or job to do. To apply SRP in Java, you should aim to create classes that have a clear and single responsibility. If a class has multiple responsibilities, you should consider splitting it into smaller, more focused classes. Open Close Principle: states that software entities should be open for extension but closed for modification. This means that you should be able to add new functionality to a system without modifying its existing code. To apply OCP in Java, you should aim to design classes that are open for extension but closed for modification. This can be achieved by using interfaces, abstract classes, and polymorphism. For example, instead of modifying an existing class to add new functionality, you could create a new class that implements the same interface and provides the new functionality. Liskov Substitution Principle: states that subtypes should be substitutable for their base types. This means that any instance of a base class should be able to be replaced by an instance of a subclass without affecting the correctness of the program. To apply LSP in Java, you should aim to create subclasses that can be used in place of their superclass. This means that the subclass should not change the behavior of the superclass. Interface Segregation Principle: states that clients should not be forced to depend on interfaces they do not use. This means that interfaces should be small and focused, and clients should only depend on the interfaces they need. To apply ISP in Java, you should aim to create interfaces that are small and focused. This means that you should avoid creating large, general-purpose interfaces that are used by many clients. Instead, you should create multiple small interfaces that are each focused on a specific set of functionality Dependency Inversion Principle: states that high-level modules should not depend on low-level modules. Both should depend on abstractions. Abstractions should not depend on details. Details should depend on abstractions. This means that you should use interfaces or abstract classes to define the behavior o

What methods are commonly overridden from the Object class and why?

The Object class is the root class within java from which all other classes inherit. (any class without an extends clause automatically extends from Object). It is not possible to create a class that does not extend from Object. Some commonly overridden methods from the Object class are 1. equals(): by default the equals method only compares the memory address of objects which will be different unless the same object is being referred to twice. overriding equals allows programmers to compare if two objects have the same state. 2.toString(): overridden to provide readable output of an object ( usually provides a string that contains the state of all member variables for the object). 3.hashCode(): if you override the equals() method you are expected to override. the hashCode() method. The hashCode method is used to hash the object into a hash table, and if two objects have the same state they should have the same hash code.

Describe the difference between the stack and the heap.

The Stack: is used for static memory allocation, it holds primitive variable values, and references to objects. Access to this memory is in Last-In-First-Out (LIFO) order. Whenever we call a new method, a new block is created on top of the stack which contains values specific to that method, like primitive variables and references to objects. blocks on the stack only exist for as long as their method are executing, and accessing stack memory is faster than accessing heap memory. stacks are thread-safe as different threads have different stacks. smaller than heap The Heap: is used for dynamic memory allocation, storing object data, and class data. It's accessed via complex memory management techniques that include the Young Generation, Old or Tenured Generation, and Permanent Generation. This memory, in contrast to stack, isn't automatically deallocated. It needs Garbage Collector to free up unused objects. Unlike stack, a heap isn't thread-safe and needs to be guarded. no size limit

Which datatype represents text in Java?

The String data type

What is the difference between a join and a set operation?

The difference between a join and set operation is that a set operation is for combining different SQL queries, while a join is for combining rows in different tables. Join stitches results Horizontally, while a Union does so vertically. In a set operation: combines two SELECT statements the number of columns in each statement must be the same. Data types must be compatible for each select statement (same). Different Set operations are Union: combines results without repeated values Union All: combines results with repeated values Intersect: combines results common to both tables Minus: results from table1 that are not in table2 [SELECT * FROM EMP1 UNION ALL SELECT * FROM EMP2;]

What is the difference between calling an instance method and a static method?

The difference between calling an instance method and a static method is that an instance method is called using an instance of a given class, (the object created from that class), while a static method can be called without an instance by utilizing the class directly. The static method belongs to the class not the object.

What is the purpose of using getter and setter methods?

The purpose of getter and setter methods is to control the access to private variables within a class. Getter and setter methods are a part of encapsulation and they hide data. The advantage of a setter method is that you can place restrictions on what value the member variable can be changed to and a getter method will be needed to view the value since it will be private and only viewable within the class.

What do a pair of opening and closing curly braces represent?

They represent a block of code. the opened curly brace represents the start of the block and the closing curly brace represents the end of the block.

What are the Maven build lifecycle phases?

Validate => project is correct and all necessary information is available Compile => compiles project source code Test => tests all compiled code Package => packages all compiled code to WAR/JAR file Integration => performs all integration tests on WAR/JAR Verify => runs checks on the results of integration tests Install => installs WAR/JAR to local repository Deploy => copies final WAR/JAR to the remote repository

If I define a variable within a method, how can I access its value outside of the method?

You cannot unless you return that value with the return statement. the variable will be automatically deleted after the method reaches its end. The scope of a variable declared within a method is in that method only.

What information would you need in order to successfully connect to a database?

You need for things to successfully connect to a database. 1. The Databases URL string (for the project to locate the database) 2. username 3. password (to log into the database) 4. database driver ( a third party software that allows you to connect to a specific type of database) Postgres driver, Oracle driver, MySQL driver. You should include the driver in the pom.xml dependencies for a maven project so that you may use that driver. Example: import java.sql.* try{ Connection connection = DriverManager.getConnection(url, username, password); System.out.println(connection.isValid(5)); } catch(SQLexception e){ System.out.println("error"); } It is a good idea to put your process for establising a connection to your database in a utility class with static variables and methods so that you may reduce redundancy and establish a connection through that class.

When would you use a switch statement over an if statement?

You should use a switch statement if you need to compare a given value against multiple other values to see which block of code you wish to execute. Switch is used to check the equality of multiple different cases.

When would you use an if statement over a switch statement?

You should use an if statement when the conditional statement deciding if the block of code executes is not just a simple equality check and is instead more complicated. additionally you should use an if statement if there are not many different branches of possible code execution.

What state and behavior would you define in a subclass but not in the parent class?

You would define states and behaviors specific to that subclass and any classes that inherit from it. You will not implement behaviors or states that are shared among other sibling classes or are specific to those sibling classes.

What state and behavior would you define in a parent class but not a subclass?

You would define states and behaviors that can be applied to all subclasses that will inherit from the parent class.

If you received text input from the user, how would you go about comparing it to a value, like "yes" or "no"?

You would use the String class method equals() to compare the text you recived with the string yes or no. By assigning the user input with a String variable name temp you can compare it with "yes" or "no" by typeing temp.equals("yes") that will return a boolean value of true or false if the user input equals "yes".

How can you iterate over an array?

get the length of the array through array.length then use a loop to go through each index in the array for(int i = 0; i < len; i++){ System.out.println(array[i]); } additionally you can use an enhanced for loop to access each element of the array for(element : array){ System.out.printlin(element); }

What are some operations you can perform on a List?

get() .set() .remove() .add() .size()

What is a flow control statement?

if switch for while do while break continue they control the flow of program execution through branches and loops.

How would you describe the compilation process for Java?

source code is put through a compiler and transformed into bytecode, a linker organizes the bytecode into objects, and blocks. The Java Virtual Machine uses the Just in time compiler to recompile code line by line to fit the environment.

What is the difference between source code and bytecode?

source code is written by a human programmer in the form of programming statements in a programming language like java. byte code is not written by humans and is instead created when source code is put through a compiler so that the computer can read and understand the instructions that the source code is asking for. source code high level human can understand byte code lower level machine can understand

What steps would you take to debug your program if runs, but gives you the wrong results?

§ talk it out (rubber duck method) § print the information to the console. § use google to find the answer. § find all the places in your program where things are working. § Use a debugging tool build into the IDE. § Use testing frameworks.


Ensembles d'études connexes

UNIT 11: Testing and Individual Differences

View Set

Bayerische Sachen: Teil VI (Traditional Bavarian Food)

View Set

FNP Review Dunphy-Chapter 18 Psychosocial Problems

View Set

Classics Unit II - The Genesis of Self-Understanding (8)

View Set

BUSML 4490 Innovation, Entrepreneurship L5 Ch 7

View Set