1/34
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
How do you run code from command prompt?
open command prompt and change directory to the file_path using cd file_path
compile the file using javac file_name
run the file using java file_name
What are the foundations of OOPS?
abstraction - abstract classes and interfaces
abstract methods CANNOT be static and do not contain a body
when an abstract class is called by a non-abstract class, the methods have to be overriden in the non-abstract class even if not used.
abstract classes CANNOT be instantiated (have an object created of them)
uses keyword extends
abstract classes are used as a blueprint of a class to reduce code redundancy
interface uses keyword implements
polymorphism - method and object overloading
method overloading - multiple methods with same names as long as they have different parameters
object overloading - className objectName = new constructorName();
if constructorName is different from className then the constructorName is the subclass of the superClass className
objects can be created from the same class but with different constructors
inheritance - overriding
uses keyword extends
methods and variables from superClass can be used in subClass now
can only extends one class at a time but can be chained —> C extends B, B extends A, C will have all of B and A
keyword final:
variable = cannot be changed
class = cannot be inherited
encapsulation - getters and setters
sometimes variables are set as private in order to limit access
in order to access these private variables then public methods from the same class that manipulate them can be called
getters - getter method is used to fetch the variable
setters - setter method is used to change the variable
what is a constructor?
A constructor is a special method that has no return type, non-static, can have access modifiers, and must be the same name as the class.
when you create an object of a constructor (instantiate), the constructor is invoked so the constructor can be used to initialize properties.
can have multiple constructors as long as they have different parameters
what is the this keyword?
this is used to refer to the current instance (object) in a method/constructor
used mostly when variables have the same name to give clarity
only used with non-static methods/constructors
Explain non-static vs static
non-static - when you create an object of a class an instance of that class is created. So changes to that instance of the class are not reflected on the original or other instances of the same class
static - there is no separation. any changes done to the original will be reflected on anything that calls it
what is break vs continue?
continue - will stop the code for that iteration of the loop but continue on with the rest of the loop until it’s finished
break - will stop the execution of the rest of the code for that iteration and the rest of the loop
what is while loop vs do-while loop
while loop will condition before running the loop
do-while loop will always run the code in the body once before checking the condition to loop
how to tell if a number is even?
use the MOD operator %
if n%2 == 0 then the number is even
how to tell if a word is a palindrome?
set the string to a char array using .toCharArray()
create a new empty String variable to save the reversedWord
use a for loop to concatenate the chars into the reversedWord String variable starting with the last letter decrementing
set each to lower case using .toLowerCase() to make it not case sensitive
then compare the original String and reversedWord String using an if condition to see if they match
what does keyword final mean in terms of variables, methods, and classes?
variables - means it cannot be changed
methods - it cannot be overridden but can be inherited
classes - cannot be inherited
what is overloading vs overriding?
overloading is having multiple methods with the same name but with different parameters
comes from polymorphism
overriding is when a subClass has the same method name and arguments as a superClass, calling the method will call the local method and override the superClass
can be worked around by using the super keyword
comes from inheritance
keyword final can be used to stop overriding
what is ArrayList vs LinkedList? which one do you use more often?
ArrayList - the items are added in as a queue. so if any items in the middle or beginning are removed then all items are shuffled back to fill that space. so it is a little slower when dealing with large amounts of data.
LinkedList - the items are added in a linked chain. so if any items in the middle or beginning are removed then only the connection to the link is move. so it is faster when dealing with large amounts of data cuz there isn’t much data moving around
ArrayList is used more often in my work activities because i don’t deal with enough data to warrant using LinkedLists
how do you connect to a database using java?
setup properties for the JDBC driver using Class.forName(JDBC driver)
create a connection to the DB using DriverManager.getConnection(url, username, password)
empower the connection reference variable to give it the power to execute queries by creating a statement object using statement = .createStatement() method
execute the queries using the .executeQuery() method to return a ResultSet object
loop thru the ResultSet using a while loop with conditions while( resultSet.next()) to extract the data from the columns based on columnName and save that to a columnValue variable
close the connection with a finally block using if connection and resultset != null .close() method respectively
how would you remove duplicate letters in a String?
use a LinkedHashMap to keep letters in order as theyve been added
Set an empty String variable for the new String
set the original String to an array using .toCharArray()
iterate thru the new Array using a for loop where it will set each char as the key and 1 as the value
with an if condition that if the char does not already have value 1 in the map then it will be added to the map with that value and then concat into the new String variable
name some data collections
list
ArrayList, LinkedList
set
HashSet, LinkedHashSet, TreeSet
map
HashMap, LinkedHashMap, TreeMap
ArrayList vs Array
array - fixed size
ArrayList - dynamic size
runtime vs compile time
compile time - shows an error while compiling before running. shows which method will be run during compile time
example is method overloading. method that will be run is determined by parameters
run time - shows an error after executing. determines which method will be run when you execute
overriding
how do you get text from an element? get page title?
.getText() method
.getTitle() method
how do you deal with dynamic elements?
use relative xpath
find a stable element and make a relative xpath of it
then use xpath axes to get to the desired element
what are the different types of xpaths?
absolute - start at the root node and then go all the way to the desired element
relative - find the element in relation to a node
what are the testNG annotations?
@BeforeSuite
@BeforeTest
@BeforeClass
@BeforeMethod
@Test
@AfterMethod
@AfterClass
@AfterTest
@AfterSuite
what is @DataProvider?
used to connect to the datasheet to run the same test but with multiple sets of data
project object model vs page object model
project object model - an .xml file that contains dependencies that configure the project once built
page object model - a design pattern used to test web applications where each individual page of an application will have its own class. the class will contain WebElements found on that page and methods that utilize the elements
what are the different waits in selenium?
explicit - waits for a condition with a specific amount of time
implicit - waits a specific amount of time to look for WebElements
fluent - waits for a condition with a specific amount of time with polling intervals where it checks if the condition is met
what are some common exceptions you’ve encountered in selenium?
NullPointerException - object reference being used isn’t initialized so it’s null
NoSuchElementException - element cannot be found
AssertionError - expected condition is not met
FileNotFoundException - file not found at given path
TimeoutException - excepted condition is not met with a WebDriverWait
IOException
how do you handle drop down elements?
Use the Select class to select/deselect options in a dropdown
use method .selectByVisibleText(), .selectByIndex(), .selectByValue(),
how to handle alerts/popups?
use the .switchTo().alert() method with either
.dismiss()
.accept()
.getText()
.sendKeys()
how to handle iFrames?
use .switchTo().frame(“frameName”)
have to return to default frame in between switching frames with .switchTo().parentFrame() OR .switchTo().defaultContent()
how to send keyboard events
use Actions class
with .sendKeys(keyName.ENTER).build().perform()
how to mouse hover
use Actions class
with .moveToElement(WebElement).build().perform()
how to deal with multiple tabs?
use .switchTo().window(windowHandle)
find window handle with .getWindowHandle()
how to read config files?
use either:
FileReader
BufferedReader
InputStream
Scanner
InputStream example:
Create InputStream object with FilePath
InputStream input = new FileInputStream(“filePath”)
create properties object as prop
use prop.load(input)
use prop.getProperty(“keyName”) to get the value
what is GitHub
git = repository to store codes
GitHub = open source web based software that hosts git services
what is a test suite? test case? test step?
test suite = test class
test case = method annotated by @Test
test step = statements ending with semicolon
what is cucumber?
cucumber is an automation testing tool used as a bridge between a feature file written in gherkin to step definitions written in java. runs the test cases with a runner class
Given - pre-condition
When - action taken
Then - validation