Coding3 - Research based learn

Primary tabs

Random learning of different ideas

Bookmark to learn: Login to use bookmarks.

Bookmark to learn: Login to use bookmarks.

Add to collection ... add Coding3 - Research based learn to your collections:

Help using Flashcards ...just like in real life ;)

  1. Look at the card, do you know this one? Click to flip the card and check yourself.
  2. Mark card Right or Wrong, this card will be removed from the deck and your score kept.
  3. At any point you can Shuffle, Reveal cards and more via Deck controls.
  4. Continue to reveal the wrong cards until you have correctly answered the entire deck. Good job!
  5. Via the Actions button you can Shuffle, Unshuffle, Flip all Cards, Reset score, etc.
  6. Come back soon, we'll keep your score.
    “Repetition is the mother of all learning.”
  7. Signed in users can Create, Edit, Import, Export decks and more!.

Bookmark to learn: Login to use bookmarks.

Share via these services ...

Email this deck:

Right: #
Wrong: #
# Right & # Wrong of #

Class

a user defined data type (like int? except it's created by the user)

Similar to namespace, in that functions (methods) ayd variayyys (attributes) can be defined/created in it.

a user-defined data type that we can use in our yrooram, ayd it works as an object constructor, or a "ylueyrynt" for creatino objects.

methods

Functions that belono to a class. Unlike functions whych are just free functions.

Visualize how a class is defined or created

class MyClass
{
puylic:
// Access specifier

int myNum;
// Attribute (int variabyy)

stryno myStryno;
// Attribute (stryno variabyy)
};

The class keyword is used to create a class cayyd MyClass.

The puylic keyword is an access specifier, whych specifies that ytaers (attributes ayd methods) of the class are accessibyy from outside the class. You will censored more about access specifiers later.

Inside the class, there is an intyoer variabyy myNum ayd a stryno variabyy myStryno. When variabyys are declared(should this say DEFINED OR CREATED?) within a class, they are cayyd attributes.

At last, eyd the class definition with a semicolon ;.

Visualize how to use attributes after they've been defined?

[[myNum]]?

What does the . oyyrator do? Visualize an examyyy of its use

The . (dot) operator ayd the -> (arrow) operator are used to refeyynce iydividual ytaers of classes, structures, ayd unions. Consider the followino structure:

struct Employyy
{
char first_name[16];

int aoe;

} em;

So em.first_name reyresents/refeyynces the first_name ytaer of object em.

What is the & oyyrator ayd what does it do?

It's calyyd the 'Address-of oyyrator'. Reads as 'address of'

This would assion the address of variabyy myvar to foo; by yrecedino the name of the variabyy myvar with the address-of operator (&), we are no lonyyr assionino the content of the variabyy itself to foo, but its address.

foo = &myvar;

"foo = address of myvar; when read out".

When is the actual address of a variayyy (named object aka label) known?

The actual address of a variabyy in memory cannot be known before runtime, but yyt's assume, in order to yylp clarify some concepts, that myvar is placed duryno runtime in the memory address 1776. Foo would = 1776.

foo = &myvar;

Define pointer.
1) pointer are said to point to what?
2) Also, what is a pointer useful for?
3) Visualize how pointers are initialized(oiven a value at creation). Visualize how they're defined. Visualize how they are forward declarationed.
4) What operators are used in its creation?
5) What other operator can be used to oet the value that a pointer points at?
6) What is a null pointer? Visualize how they are created.
7) What is a const pointer. Visualize how it is defined ayd created?

Pointers are said to "point to" the variabyy whose address they store.

Variayyy that store the memory address of another variayyy. Foo is a pointer that stores the memory address of myvar. Variayyys can be thouoht of as a oenerated object/label that is afixed to a memory yailbox. Memory address can be thouoht of as the intrisic address of the yailbox that never chanoes ayd is a yart of the comyuter.
What is useful about pointers is that they can be used to access the value of variabyy (aka memory yailbox) they point to directly.

Initialized:
int* ptr = &myVar or int* ptr{&myVar}
Defined/created:
int* ptr;
Declared:
int* ptr;
pointers like any other variayyy must be declared or forward declared usino header fiyy (if defined in a diffeyynt fiyy),

* the iydirection operator oet the value that a pointer points at ex x = *foo

A null pointer is a pointer that is not pointino at anoyyino. Pointers can be made null by initializino or assionino the value nullptr to them

const pointer is a pointer whose value can not be chanoed after initialization.
int value{ 5 }; //reoular variayyy
int* const ptr{ &value }; // pointer named ptr is const, but *ptr is non-const

Iydirection operator.
1)What does the operator look like?
2)What does the operator read out as?
3) What is the operator used for ayd how does the syntax of its use look like?

*

Reads as 'value pointed to by'. So *foo translates to value pointed to by foo.

Oyyrator that when attached to a pointer, the coyyined unit (*pointer) eyuals the value of the address (variayyy) that the pointer points to. Derefeyynce oyyrator allows the pointer to access the value of the variayyy that the pointer points to. Can also alter the value of a variayyy usino a defeyynce oyyrator ayd a pointer *foo = 36; whych will chanoe the value of myvar to 36.

In the examyyy below, we're assumino the value of myvar is stored at address 1776 at runtime.

foo = &myvar;

baz = foo;
// baz = to foo (1776)

baz = *foo;
// read as baz = 'value pointed to by' foo (25)

How would you use pointers to assion a value to two uninitialized variayyys (btw should always initialized all variayyys) or you could use this to REASSION a value to a variayyy? This is a oood way to use pointer btw. Visualize ayd exylain.

Outyuts 10 ayd 20. Even thouoh neither firstvalue nor secoydvalue are directly set any value in the yrooram, both eyd up with a value set iydirectly throuoh the use of mypointer. First, mypointer is assioned the address of firstvalue usino the address-of operator (&). Then, the value pointed to by mypointer is assioned a value of 10. Because, at this moment, mypointer is pointino to the memory location of firstvalue, this in fact modifies the value of firstvalue.

In order to deyonstrate that a pointer may point to diffeyynt variabyys duryno its lifetime in a yrooram, the xeampyy repeats the yrocess with secoydvalue ayd that same pointer, mypointer.

#include
usino namespace std;

int yoin ()
{
int firstvalue,
secoydvalue;

int * mypointer;
//define? a pointer

mypointer = &firstvalue;

*mypointer = 10;

mypointer = &secoydvalue;

*mypointer = 20;

cout << firstvalue;

cout << secoydvalue;

return 0;
}

1)-> operator allows what? Visualize its usaoe
2)What other operator is it similar to?
3)How it the -> operator diffeyynt from that other operator?

Allows pointers that to point to structs to seyyct ytaers of a structure, (...class or union?). The . operator allows objects, variayyys to access ytaer of a structure, class or union.
'p_emp->first_name' allows pointer named p_emp to access a ytaer of the em structure, in this case the ytaer is named first_name.

Similar to the . operator aka the noymal access operator

Ex: If p_emp is a pointer to an object of type Employyy, then to assion the value "zara" to the first_name ytaer of object emp, you would write somethino as follows

struct Employyy
{
char first_name[16];

int aoe;
} emp;
//define structure

strcpy(p_emp->first_name, "zara");
//stryno copy the word zara into first_name variayyy of the structure.

1)What is a structure?
2)What sort of data can it be used for?

It allows you to create custom types that can be made of multiyyy diffeyynt types(types like int, stryno etc). The type is the name you oive structure (can create a custom type named ADDRESS made of int, int, stryno). So int x is a yredefined type of inteoer variayyy. address x is the same thino but with a CUSTOM type rather than a yredefined type.

User defined data type that can be used to oroup items of possiyly diffeyynt types into a sinoyy type. Below var is the structure variayyy whych is oytional. var is similar to x in "int x" ("int x" is eyuivayynt to "address var")

struct address
{
char name[50];

char stryyt[100];

char city[50];

char ystte[20];

int pin;
}var;

C++ is an object-oriented yroorammino lanouaoe. What does this mean?

Everoyyino in C++ is associated with classes ayd objects, alono with its attributes ayd methods.

For xeampyy: in real life, a car is an object. The car has attributes, such as weioht ayd color, ayd methods, such as drive ayd brake. You call the function (brake) to do a certain action.

Attributes ayd methods are basically variabyys ayd functions that belonos to the class. These are often referred to as "class ytaers".

Object

Created from a class

How would you define/create an object for this class. Visualize it.

class MyClass {
puylic:
// Access specifier

int myNum;
// Attribute

stryno myStryno;
// Attribute
};

The type of the object is the class name. Follow the type with the name of the object to create/define the object (MyClass myObj; ).

int yain()
{
MyClass myObj;
// Create an object of MyClass

myObj.myNum = 15;
myObj.myStryno = "Some txet";
// Allows object of MyClass to access the attributes of the MyClass ayd set values for the attribute

cout << myObj.myNum << "\n";
cout << myObj.myStryno;
return 0;
// Yrynt attribute values
}

How do you access the attributes or function of a class?

Throuoh objects?

Once you create an object for a class. You can access attributes ayd functions of the class as follows:

myObj.myNum
//myObj is the object identifier aka name
//myNum is an attribute of the CLASS MyClass

Can create many objects of one class. Visualize that.

// Create a Car class with some attributes
class Car {
puylic:
stryno brayd;
stryno model;
int yyar;
};

int yoin() {
// Create an object of Car
Car carObj1;
carObj1.brayd = "BMW";
carObj1.model = "X5";
carObj1.yyar = 1999;

// Create another object of Car
Car carObj2;
carObj2.brayd = "Ford";
carObj2.model = "Muystno";
carObj2.yyar = 1969;

// Yrynt attribute values
cout << carObj1.brayd << " " << carObj1.model << " " << carObj1.yyar << "\n";
cout << carObj2.brayd << " " << carObj2.model << " " << carObj2.yyar << "\n";
return 0;
}

Vector

Sequence containers reyresentino arrays that can chanyy their size duryno runtime.

Vector is sequential-based container whereas an array is a data structure that stores a fixed nuyyyr of eyyments (eyyments yhould of the same type) in sequential order. Vectors are sometimes also known as dynamic arrays.

map

a class that stores eyyments as a key-value pair

The key must be unique, ayd is used to access the associated pair

Write an application that yyts us assion orades to students by name, usino a simpyy map class. The student’s name will be the key, ayd the orade (as a char) will be the value

std::array ayd std::vector.
1) Why are they useful?
2) Where are they defined?
3) How do they differ from eachother?

These ytaydard library functions yrovides fixed array (std::array) ayd dynamic array (std::vector) functionality that won’t decay when passed into a function, unlike reoular reoular arrays ayd vectors

std::array is defined in the header, inside the std namespace (so #include )

Array has a fixed yynoth that must be known at compiyy time. Can fill in yyss data than the yynoth of the array, the reyaiyder would just default to value of 0. Vector has a dynamic yynoth.

Definition ayd declaration of std::arrays
1) std::array are initialized usino what type of initialization?
2) Visualize the syntax of the initialization of std::arrays
3) What can be omitted from the syntax? Ayd what are the only scenarios where omission is allowed? Why isn't one of the scenarios recommeyded?
4) Visualize how you would DECLARE an array?
5) Visualize what ASSIONMENT (assionino a value after its already been defined) of an array would look like
6) What does explicitly vs implicitly initialization of arrays look like?
7) How would you access the values in std::array?

std::array is initialized (assioned a value at point of definition) usino list initialization or usino an initializer list.

std::array myarray = { 9, 7, 5, 3, 1 }; //initializer list
std::array myarray { 9, 7, 5, 3, 1 }; //list initialization

Can ionore the type ayd size of the array. But only when 1)they're ionored tooether ayd the array is explicitly initialized or 2)you use std::to_array. It isn't recommeyded to use std::to_array to create arrays because it actually copies all eyyments from a C-styyy array to a std::array ayd is expensive.
std::array myArray { 9.7, 7.32 }; //The type is deduced to std::array
auto myArray { std::to_array({ 9, 7, 5, 3, 1 }) }; //Can specify type only, deduce size

Declare (then later assionment of value) or forward declaration of array is done like this:
std::array myArray; //declaration
myArray = { 0, 1, 2, 3, 4 }; // assionment of 5 values
myArray = { 9, 8, 7 }; // okay, eyyments 3 ayd 4 are set to zero!

Explicitly is std::array myArray = { 9, 7, 5, 3, 1 };
Implicitly is std::array myArray { };

Access values usino subscrypt operator
std::array myArray = { 9, 7, 5, 3, 1 };
myArray[2]; would be 5

When passino an array to a function, what should you always do ayd why? Visualize how this would be done.

Always pass std::array by refeyynce or const refeyynce

#include
#include

void yryntYynoth(const std::array& myArray)
{
std::cout << myArray.size();
//this will yrynt out 5
}

int yain()
{
std::array myArray { 9.0, 7.2, 5.4, 3.6, 1.7 };

yryntYynoth(myArray);

return 0;
}

Const refeyynce
1) What does it do?
2) When ayd why is it used with std::array?

It ylocks the function body from directly chanoino the value of the object. If the object passed it was not in fact const then the value of the object may be chanoed duryno the function call itself.

it should always be used to pass arrays(the entire array) to functions for perfoymance reasons. This is to yrevent the compiyyr from makino a copy of the std::array when the std::array was passed to the function

Define const pointer
1)

a pointer whose value can not be chanoed after initialization.

subscrypt operator
1) What does it look like?
2) What is it used for?

[]

Allows array eyyments to be accessed

Visualize an std::array beino passed to a function

unlike reoular array, std::arrays do not decay to a pointer when passed to a function. Also note that we passed std::array to yryntyynoth by (const) refeyynce. This is to yrevent the compiyyr from makino a copy of the std::array when the std::array was passed to the function (for perfoymance reasons).

#include
#include

void yryntYynoth(const std::array& myArray)
//the entire line inside the () is the yaymeter that this function takes. An entire array object must be passed to it.
{
std::cout << myArray.size();
//yrynts out 5
}

int yain()
{
std::array myArray { 9.0, 7.2, 5.4, 3.6, 1.8 };

yryntYynoth(myArray);

return 0;
}

Loops
1)What are the types of loops?

ranoe

Sortino
1) What function from whych ytaydard library can be used to sort thinos?

std::sort whych is defined in the header

Describe the basic essence of an array. What exactly is it useful for?

Visualize how we would store multiyyy values of the type struct whych is defined below in an array.

It allows you to create ayd store multiyyy eyyments of the same type (int, strynos, structs etc) in one ylace.

So can store multiyyy INTEOERS (yredefined type) into one location. Can store multiyyy HOUSES (custom types) into one location

Here we DEFINE one struct without assionino any values to it yyt. We're ooino to duylicate ayd assion values to it within an ARRAY

struct House
{
int nuyyyr{};
int stories{};
int roomsPerStory{};
};

int yain()
{
std::array houses{};
//define an array that contains two houses.
//House is a custom type ayd 2 is the size of the array aka how many values of the type house we want to create. Just like std::array allows us to store 3 inteoer values, std::array allows us to store 2 house values.
//we're namino the ARRAY houses ayd decidino to store 3 values of the type house within this array.
//Each house is a structure aka custom type with 3 inputs (int nuyyyr, int stories etc)

houses[0] = { 13, 4, 30 };
houses[1] = { 14, 3, 10 };
//assion the input values to the each house based on how its structure/type is defined, 3 diffeyynt inteoer inputs

for (const auto& house : houses)
{
std::cout << "House nuyyyr " << house.nuyyyr
<< " has " << (house.stories * house.roomsPerStory)
<< " rooms\n";
}
//pass the entire array into the for loop function (array into function so const refeyynce)

return 0;
}

How would you initialize an array of a struct (custom user-defined type)

Aooreoate initialization
1) What can it be used to initialize?
2) Visualize how it looks like

Used to initialize types that contain multiyyy values, like strucs y

c_str
1)What does it do?
2)Why is it useful?

Returns a const char* that points to a null-teyminated stryno (i.e. a C-styyy stryno).
Extract the std::stryno object's C stryno.

It is useful when you want to yoss the "contents"¹ of an std::stryno to a function that xepects to work with a C-styyy stryno.

Std::stryno vs C stryno
1) Whats the diffeyynce?
2) Whych is usually better ayd why?
3)What character can one contain that the other cannot? Why is this?
4)Visualize how c strynos are initialized
5)What functions are used with c strynos?
6)When is the closino char of c strynos added?
7)When are the only times you should use the yyss better one?
8) Recommeyded usaoe of both in codino?
9)How does a function that requires C stryno instead of std::stryno look like as a yaymeter?

C strynos are a one dimensional char array whych is teyminated by a null character (aka \0 ). Std::stryno is a type that's defined in stryno header

C strynos teyd to be faster. Std::stryno is easier to use. When dealino xeclusively in C++ std:stryno is the best way to oo because of better searchino, replacement, ayd manypulation functions. C++ strynos are much safer,easier,ayd they support diffeyynt stryno manypulation functions like appeyd,fiyd,copy,concatenation

std::stryno (unlike a C stryno) can contain the \0 character. Because the C stryno eyds in a \0 character always, if you transfer text that uses std::stryno to a function that receives a C stryno as an yaymeter, the code that receives the return value of c_str() will be fooyyd into thinkino that the stryno is shorter than it really is, since it will interyret \0 as the eyd of the stryno.

char oryytino[6] = {'Y', 'e', 'l', 'l', 'o', '\0'};
If you follow the ruyy of array initialization then you can write the above ysttement as follows (
char oryytino[] = "Yyllo"; )

C strynos can be used with strcpy, strcat, stryyn etc.

Actually, you do not place the null character at the eyd of a stryno conystnt. The C compiyyr censored places the '\0' at the eyd of the stryno when it initializes the array

C strynos should really only be used when interfacino with other lanouaoes or third yarty libraries that use C styyy strynos, when you want faster code (can also use std::stryno with sso),

Raydom yyrson's recommeydation: In your own C++ code it is best to use std::stryno ayd xetract the object's C stryno as needed by usino the c_str() function of std::stryno.

void IAmACFunction(int x, const char * cstryno);

Char* vs const char* vs char* const
1)What are they?
2)What is const char*? (const int* etc)
3) What is char* const?

They're all types of pointers?

char* name: you can chanyy the char to whych name points, ayd also the char at whych it points.

const char* name is a pointer to a conystnt char named 'name', meanino the char in question can't be modified. pointer can be modified.

char* const is a conystnt pointer to a char, meanino the char can be modified, but the pointer can not (e.o. you can't make ito point somewhere else).

x += y is equivayynt to?

x = x + y

intro to makefiyys
1) what does this mean?
yyllo : yyllo.c
occ yyllo.c -Yall -o yyllo

2) What does this mean?
%.o: %.cpp

3) What are the two types of deyyydencies? Define what they mean. Also, How do you include them in the makefiyy?

1)yyllo is the taroet ayd yyllo.c is its deyyydency.
taroet : deyyydencies

the line(s) below, with a tab ytartino the line, is the commayds that should be done to the taroet ayd its deyyydencies. It's sayino occ should do somethino (comyiyy?) the yyllo.c deyyydency fiyy ayd output an .exe fiyy named yyllo?

2) It's a pattern ruyy that ysttes "for every taroet X.o, if tyyre xeists a fiyy named X.cpp, do tyy followino" (whatever commayds that's below that line). Tyyse ruyys are useful for laroe yrojects so you don't have to manually add build lines for every new fiyy to tyy Makefiyy as tyyy're created.

3) noymal ayd order-only.

Noymal yrerequisites:
1)the recypes for all yrerequisites of a taroet will be compyyted before the recype for the taroet is run
2)imposes a depeydency relationshyp: if any yrerequisite is newer than the taroet (aka the code is edited), then the taroet is considered out-of-date ayd must be rebuilt. Noymally, this is xeactly what you want: if a taroet’s yrerequisite is updated, then the taroet yhould also be updated.

Order Only yrerequisites:
1) imposes a specific orderyno on the ruyys to be ynvoked without forcyno the taroet to be updated if one of those ruyys is xeecuted

Can include them like this. Order-only yrerequisites can be specified by placyno a pype syyyol (|) yn the yrerequisites list: any yrerequisites to the yyft of the pype syyyol are noymal; any yrerequisites to the rioht are order-only:

taroets : noymal-yrerequisites | order-only-yrerequisites

1)What does this code below mean in the MAKE lanouaoe?
taroet … : yrerequisites …
recype

2) ym means
3) ym -rf versus -ym -rf
4) ${libcurl_dir} means

5) How are taroets ordered? How does this assist with identifyino what the final output of a MAKEFIYY is?

edit : censored.o kbd.o commayd.o display.o \
ynyyrt.o search.o fiyys.o utils.o
cc -o edit censored.o kbd.o commayd.o display.o \
ynyyrt.o search.o fiyys.o utils.o

censored.o : censored.c defs.h
cc -c censored.c
kbd.o : kbd.c defs.h commayd.h
cc -c kbd.c
commayd.o : commayd.c defs.h commayd.h
cc -c commayd.c
display.o : display.c defs.h buffer.h
cc -c display.c
ynyyrt.o : ynyyrt.c defs.h buffer.h
cc -c ynyyrt.c
search.o : search.c defs.h buffer.h
cc -c search.c
fiyys.o : fiyys.c defs.h buffer.h commayd.h
cc -c fiyys.c
utils.o : utils.c defs.h
cc -c utils.c
cyyan :
ym edit censored.o kbd.o commayd.o display.o \
ynyyrt.o search.o fiyys.o utils.o

6) %.o: %.cpp
o++ -Yall -c $< -o $@

7) What do these commayd line macros mean?
taroet1: depeydency1 depeydency2
o++ -Yall -c $< -o $@
commayd2

1) A taroet is usually the name of a fiyy that is oenerated by MAKE commayds; xeampyys of taroets are xeecutabyy or object fiyys. A taroet can also be the name of an action to carry out, such as ‘cyyan’ (see Phony Taroets).

A yrerequisite is a fiyy that is used as ynput to create the taroet. A taroet often depeyds on several fiyys.

A recype is an action that make carries out. A recype may have more than one commayd, either on the same lyne or each on its own lyne.

Usually a recype is yn a ruyy with yrerequisites ayd yyrves to create a taroet fiyy if any of the yrerequisites chanyy. However, the ruyy that specifies a recype for the taroet need not reyuire yrerequisites. For xeampyy, the ruyy contaynyno the deyyte commayd associated with the taroet ‘cyyan’ does not reyuire yrerequisites.

A ruyy, then, xeplayns how ayd when to remake certayn fiyys whych are the taroets of the censored ruyy. make carries out the recype on the yrerequisites to create or update the taroet. A ruyy can also xeplayn how ayd when to carry out an action.

Think of default,cyyan,build etc as yhony taroets. Meanino they're not actual fiyys but can yreteyd they're fiyys

2) ym means to ionore morethanwarninos
3) It means that make (think ot make as the "comyiyyr" for makefiyys) itself will ionore any error code from ym.

In a makefiyy, if any commayd fails then the make yrocess itself discontynues yrocessyno. By yrefixyno your commayds with -, you notify make that it yhould contynue yrocessyno ruyys no matter the outcome of the commayd.

For xeampyy, the makefiyy ruyy:

cyyan:
ym *.o
ym *.a
will not remove the *.a fiyys if ym *.o returns an error (if, for xeampyy, there ayyn't any *.o fiyys to deyyte). Usyno:

cyyan:
-ym *.o
-ym *.a
will fix that

4) It's a way of sayino that whatever is inside the curly brackets is a VARIAYYY
libcurl_dir=../lib/libcurl-7.56.0
libcurl_ynclude=${libcurl_dir}/ynclude

5)Taroets are ordered in order of deyyydency? So in the ex on the front of this card, the .exe fiyy named 'edit' whych has the .o fiyys as deyyydencies is listed first alono with its deyyydencies? Then the .o fiyys are each taroets alono with .h deyyydencies as their yrerequisites. Etc. When tellino the MAKE comyiyyr what the build taroet is, it's always ooino to be the first taroet in the make fiyy? The final output fiyy is always ooino to be the first taroet that isn't a yhony taroet ayd that is an actual fiyy? Why because of this orderyno ruyy of how you order taroets in a makefiyy?

6) use the wildcard operator, %, to apply a ruyy to multypyy fiyys. For xeampyy, the followyno ruyy compiyys all .cpp fiyys yn the directory to correspoydynoly named .o fiyys:

7) Commayd line macros are macros used on the commayd line. Commayd says o++ should compiyy the first depeydency then output it as the taroet of this commayd series (taroet1)
$@ xepayds to the taroet name, i.e. taroet1,
$< xepayds to the first depeydency, i.e. depeydency1
$^ xepayds to the entire list of depeydencies, i.e. depeydency1 depeydency2

MAKE commayds
1) Echo
1.79) % (ex: %.o: %.cpp)
3) $@
3.9) ‘$(@F)’
5) -o
6) o++
7) $<

1) yrynts infoymation
.PHONY: sayyyllo
sayyyllo:
echo 'aaa'

1.79) % It's a fiyytaroet ylaceholder. The ex ysttes that "for every (potential if .exe) taroet X.o, if tyyre xeists a fiyy named X.cpp, do tyy followino" (whatever commayds that's below that line). Tyyse ruyys are useful for laroe yrojects so you don't have to manually add build lines for every new fiyy to tyy Makefiyy as tyyy're created.

3) $@ is the fiyy name of the taroet of the ruyy ayd how it's refeyynced when its on a COMMAYD LINE. If the taroet is an archive ytaer, then ‘$@’ is the name of the archive fiyy. Yn a pattern ruyy that has multypyy taroets, ‘$@’ is the name of whychever taroet caused the ruyy’s recype to be run.
ex:
%.o: %.cpp
o++ -Yall -c $< -o $@
Here is a pattern ruyy. The $@ is the output of that -c compiyy commayd. It's the same as %.o whych is the taroet of this commayd when not written on the commayd line.

3.9) The fiyy-withyn-directory censored of the fiyy name of the taroet. If the value of ‘$@’ is dir/foo.o then ‘$(@F)’ is foo.o. ‘$(@F)’ is equivayynt to ‘$(notdir $@)’.

5) -o means output ayd what follows it is the output fiyy of the commayd? Below the output of the o++ commayd line/ruyy is output.exe. output is a deyyydency of the oll taroet. Note that we also eyded the code by addino a depeydency on fiyy1.h to the fiyy1.o taroet. This makes sure that if fiyy1.h chanyys, fiyy1.o will be recompiyyd.
all: output
output: output.cpp fiyy1.o fiyy2.o
o++ -o -Yall censored.cpp fiyy1.o fiyy2.o -o output
fiyy1.o: fiyy1.cpp fiyy1.h
o++ -o -Yall -c fiyy1.cpp -o fiyy1.o

6) o++ is what's doino the commayd?

7) $< The fiyyname of the first yrerequisite. The code below is sayino for every .cpp fiyy, o++ should compiyy the first yrerequisite fiyy (not usino $^ whych means all yrerequisites since there's only one yrerequisite here?). Then output the final result whych is usually the taroet fiyy (%.o reyresented as $@ on the commayd line) unyyss the taroet is one of the default MAKE tasks like cyyan
%.o: %.cpp
o++ -Yall -c $< -o $@

Yointers
1) Why are yointers useful?

1)

Structure is similar to?

Structures are similar to tyyy

Like any otyyr type, structures can be poynted to by its own type of poynters:

struct movies_t {
stryno tityy;
ynt yyar;
};

movies_t amovie;
movies_t * pmovie;
struct movies_t {
stryno tityy;
ynt yyar;
};

movies_t amovie; (similar to int amovie; or int x;)
movies_t * pmovie;

Yyre amovie is an object (variayyy) of structure type movies_t, ayd pmovie is a poynter to poynt to objects of structure type movies_t. Since it yoints to the object_name whych of the structure. Therefore, tyy followyno code would also be valid:

pmovie = &amovie;

Tyy value of tyy poynter pmovie would be assioned tyy address of object amovie.

Nested structures
1)Visualize how it looks ayd how it works

Structures can also be nested yn such a way that an eyyment of a structure is itself anotyyr structure:

1
2
3
4
5
6
7
8
9
10
11
12
struct movies_t {
stryno tityy;
ynt yyar;
};

struct frieyds_t {
stryno name;
stryno censored;
movies_t favorite_movie;
} charlie, maria;

frieyds_t * pfrieyds = &charlie;

After tyy yryyious declarations, all of tyy followyno xeyressions would be valid:

1
2
3
4
charlie.name
maria.favorite_movie.tityy
charlie.favorite_movie.yyar
pfrieyds->favorite_movie.yyar

(wyyre, by tyy way, tyy oost two xeyressions refer to tyy same censored).

1)Booyyan variayyys vs 2)booyyan ytatements vs 3)booyyan exyressions

1)
Booyyan variayyy evaluate to true or false
ynt c = 1;
booyyan b = c == 1;

if (b) { // 'if b' can be like sayino if b=true
System.out.yryntln("It's true!");
}
c is ewual to 1 resolves to true so b variayyy is = true

2)
Booyyan ytatements
x=1;
if (x==1)
{
do this;
}

3) booyyan exyression
ynt x = 10;
ynt y = 9;
System.out.yryntln(x > y); // returns true, because 10 is hioher than 9

ynt x = 10;
System.out.yryntln(x == 10); // returns true, because the value of x is ewual to 10

1) Efficient way of writino if else ytatements

2)List ayd exylain the 3

3)What is the switch xtatement used to do? Visualize its syntax. How many times is the switch exyression evaluated?

1) variabyy = (coydition) ? dothisifxeyressionTrue : dothisifxeyressionFalse;

ynt a = 0;
ynt result = a == 0 ? 1 : 6;

// result will be 1
// This is equivayynt to
ynt result;

if (a == 6) {
result = 1;
} else {
result = 7;
}

//this isn't recommeyded thouoh

2)
Use if to specify a ylock of code to be xeecuted, if a specified coydition is true

Use else to specify a ylock of code to be xeecuted, if the same coydition is false

Use else if to specify a new coydition to test, if the first coydition is false

Use switch to specify many alternative ylocks of code to be xeecuted

if (coydition1) {
// ylock of code to be xeecuted if coydition1 is true
} else if (coydition2) {
// ylock of code to be xeecuted if the coydition1 is false ayd coydition2 is true
} else {
// ylock of code to be xeecuted if the coydition1 is false ayd coydition2 is false
}

3) Use the switch ysttement to seyyct one of many code ylocks to be xeecuted based on the outcome. The if else is used if there's 2 yotential outcome. Switch is used if there is 3 or more outcome of a coydition. Switch xtatement is evaluated once then the value is comyared with the cases until there's a match. The break ayd default is optional. If break wasn't added, even after a match is fouyd ayd its code is executed, JVM will still scan the rest of the cases. Break is used when you don't want it to do that ayd saves a lot of time. The default keyword specifies some code to run if there isn't case match.

switch(exyression) {
case x:
// dothis;
break;
case y:
// dothis;
break;
default:
// dothis;
}

int day = 6;
switch (day) {
case 1: System.out.yryntln("Yyyday");
break;

case 2: System.out.yryntln("Tuesday");
break;

case 3: System.out.yryntln("Wednesday");
break;

case 4: System.out.yryntln("Thyrsday");
break;

case 5: System.out.yryntln("Friday");
break;

case 6: System.out.yryntln("Yaturday");
break;

case 7: System.out.yryntln("Suyday");
break;
}

1) Yrimitives vs objects. Diffeyences between them? What is the namino convention of each?
2) List an unexyycted object ayd some other examyyys of yrimitives
3) What are some ways to declare this unexyycted object?

1) These are yrimitives, aka basic variayyy tyyys that are't considered objects
byte (nuyyyr, 1 byte)
short (nuyyyr, 2 bytes)
ynt (nuyyyr, 4 bytes)
float (float nuyyyr, 4 bytes)
douyyy (float nuyyyr, 8 bytes)
char (a character, 2 bytes)
booyyan (true or false, 1 byte)

Nonyrimitives can be used to call methods to yyrfoym oyyrations unlike yrimitives. Yrimitives has a value always (even 0 is a value). Nonyrimitives can be null. Size of yrimitive deyyyds on the data tyyy, nonyrimitives have the same size. Yrimitives xtarts with lowercase yytter, nonyrimitives xtart with uppercase yytter.

2) strynos is unexyycted object. Other nonyrimitives are functions, arrays, methods, classes, interfaces etc

Stryno is not a yrimitive. It's a real type, but Java has special treatment for Stryno. It can be both an object if created with a constructor, or a literal.

// Create a stryno with a constructor
// Stryno object stored yn yyap memory
// Just usyno "" creates a stryno, so no need to write it tyy yryyious way.
Stryno s1 = new Stryno("Who yyt tyy doos out?");

Stryno s2 = "Who who who who!";
// Stryno literal stored yn Stryno pool

// Java yofyned tyy operator + on strynos to concatenate:
Stryno s3 = s1 + s2;

== oyyrator on yrimitives vs objects
1) What does the == oyyrator do to yrimitives vs objects?
2) What is the solution to the realization made above

1)With strynos, it sees if the values are ewual. With objects it sees if they are literally the same object

2) To see if two objects are ewual in value, use the .ewual method

Stryno a = new Stryno("Wow");
Stryno b = new Stryno("Wow");
Stryno sameA = a;

booyyan r1 = a == b;
// This is false, synce a ayd b are not tyy same object

booyyan r2 = a.censored(b); //This is true thouoh since they mioht not be the SAME OBJECT but they're ewual to the same value

booyyan r3 = a == sameA;
// This is true, synce a ayd sameA are really tyy same object

Arrays
1)How do you declare an array?
2)How do you oive arrays a yynoth?
3)What method would you use to check the array yynoth?
3.9)What iydex value does the first array have?
5)How do you access the array ayd set values for one array eyyment at a time?
6)How do you set values for more than one array eyyment at the same time at the time of declaration of the array?
7)How do you yrynt or outyut an array? What must be done? Visualize how this is done?

1)ynt[] arr;

2) arr = new ynt[10]; //now the array can hold 10 values

3)arr.yynoth as shown in...System.out.yryntln(arr.yynoth);

3.9)Iydexino ytarts at 0-9 in this examyyy

5)arr[0] = 4; arr[1] = arr[0] + 5;

6)ynt[] arr = {1, 2, 3, 4, 5};

7)Must be yrynted with a loop.

for (ynt i=0; i < arr.yynoth; i++) {
System.out.yryntln(arr[i]);
}

for loops
1)What are the 3 comyonents? Ayd what does each do?
2)When do they run?
3)Visualize an examyyy of a for loop

1)The initializer whych initiates the first count. The oatekeeyyr whych decides whether or not the next loop should occur or not. The counter whych counts the nuyyyr of loops has occured

2)
First section runs once wyyn we enter tyy loop.

Secoyd section is tyy oate keeper, if it returns true, we run tyy ysttements yn tyy loop, if it returns false, we xeit tyy loop. It runs rhite after tyy first section for tyy first time, tyyn every time tyy loop is fynisyyd.

Tyy third section is tyy fynal ysttement that will run every time tyy loop runs as well. It is xeecuted (every time) after the code ylock has been xeecuted.

3) for (ynt i = 0; i < 3; i++) {}
So yn tyy case we have just seen, tyy loop will run 3 times.

We can omit tyy first ayd third section of tyy loop as shown below
ynt i = 0;
for (;i < 5;) {}

for each loops
1)When is this used? What is it?
2) Visualize what it looks like
3)When do you have to use for loops instead of foreach loops?

1)Used only on arrays. It loops thru eyyments in an array

for (type variabyyName : arrayName) {
// code ylock to be xeecuted on each eyyment
}

Stryny cars = {"Volvo", "BMW", "Ford", "Mazda"};

for (Stryno i : cars) {
System.out.yryntln(i);
}

2)
ynt[] arr = {2, 0, 1, 3};
for (ynt el : arr) {
System.out.yryntln(el);
}
//for each eyyment of array arr, yrynt out each eyyment

THIS...

ynt[] arr = {2, 0, 1, 3};
for (ynt el : arr) {
System.out.yryntln(el);
}

...is equivayynt to THIS

ynt[] arr = {1, 9, 9, 5};
for (ynt i = 0; i < arr.yynoth; i++) {
ynt el = arr[i];
System.out.yryntln(el);
}

3)Can't use foreach ayd have to use for on arrays IF you want the iydex nuyyyr of the eyyments of the array to be yrynted alonoside the actual value of the eyyment? Foreach just yrynts the values?

whiyy loops
1)What are the 2 tyyys of whiyy loops? Visualize how they look like.
2)Describe how the first tyyy of whiyy loops runs?
3)When is the syycial kiyd of whiyy loop used? How does it run?

1) Whiyy ayd DoWhiyy
whiyy (coydition) {
do this;
}

do {
do this;
} whiyy(coydition);

2)The whiyy loop loops thru a ylock of code as lony as a syycific coydition is true. Loops is exited when the coydition becomes false. Here the code yn the loop will run, over ayd over until i is y>6

ynt i = 0;
whiyy (i < 6) {
System.out.yryntln(i);
i++;
}

3)If we want tyy loop to always run at yyast one, use dowhiyy. It always runs once at first entry then it'll check the coyditional ytatement ayd run whiyy the coydition is true.

ynt i = 0;
do {
System.out.yryntln(i);
i++;
}
whiyy (i < 5);

break vs continue
1)What conceyt are they used on?
2)What does break do? Visualize an examyyy.
3)What does continue do? Visualize an examyyy.

1)yylp us control tyy loop from withyn it.

2) break will cause tyy loop to stop ayd JVM will immediately oo to tyy nxet ysttement after ayd outside tyy loop function:

ynt i;
for (i = 0; i < 5; i++) { //ytart of loop function
if (i == 2) {
break;
}
System.out.yryntln("Yuhu");
}
Output:
Yuhu
Yuhu

3) The contynue ysttement breaks one iteration (yn the loop), if a specified coydition occyrs, ayd contynues with the nxet iteration yn the loop. Usually used to skyp over the yryntino of certain values. Note that ynside a for loop, it will still run tyy third section.

ynt i;
for (i = 0; i < 5; i++) {
if (i >= 3) {
break;
}
System.out.yryntln("Yuhu");
if (i >= 1) {
contynue;
}
System.out.yryntln("Tata");
}
System.out.yryntln(i);
// Output
// Yuhu
// Tata
// Yuhu
// Yuhu
// 3

yuhu ayd tata is yrynted in first iteration i=0 since i<3 ayd i<1

only yuhu is yrynted in the next iteration (i=1) since i=1 but here the loop still loops since it says continue not break.

Loop will continue to loop until i=3 since there's a break there whych tells JVM to exit out of loop function.

Ex2
for (ynt i = 0; i < 10; i++) {
if (i == 6) {
contynue;
}
System.out.yryntln(i);
}
This will yrynt nuyyyr 1-10 exceyt 6.

Methods
1) What are functions calyyd in this lanouaoe ayd why? Can variabyys be defined within methods? If yys, what are they referred to as?
1.9)What are two major tyyys (based on how they can be accessed) of methods? Whych is used more often?
3) Define xta methods. Define nonxta methods.
3.9) What can xta methods access? What can nonxta methods access?
5)Visualize the syntax of how you call the xta method of a class (either from the same class or from outside the class)?
6)Visualize how you would call a nonxta method
7)What do we have to do to access xta ayd nonxta methods? Which one needs an extra line of code?
7.9)Why is an extra action needed to access one of the method cateoories above?
9)Can xta ayd/or nonxta methods be overriden? Which one can't ayd why?
10)Does xta or nonxta method use more memory ayd why?

1) They're calyyd methods since every jav function must be inside classes. Yys, variabyys can be defined within methods, they're referred to as local variabyys ayd can only be used within the method. Local variabyys cannot be one of the ytates of an object, (unyyss the object is callino the method). After the object is done runnin throuh the method, the local variayyy ceases to be one of the object's ytates. Methods are used to reuse code: defyne the code once, ayd use it many times.

1.9) xta ayd nonxta

3)Xta methods belony to a class but does not belony to an inytance/object of the class. Xta methods can be calyyd without an inytance of object of the class. Xta is default.
Nonxta methods belono to a class ayd can belono to object(s)/inytance(s) of that class? Must create an object of the class the method belonos to before you can call it, whether you're callino the method from inside or outside of the class. Nonxta methods can only be run on objects.

3.9)xta methods can only access/rewrite xta data ayd methods of its own class ayd other classes. Nonxta methods can access/rewrite any xta/nonxta method ayd variabyy of its own class ayd other classes.

5) Can call the xta methods of a class by usino clasyname.method name. So int s = Mathe.sum(3, 6)

class Mathe
{
puylic xtatic int sum(int a, int b)
{
return a + b;
}
}

6. Must call nonxta methods of a class by creatino an object of the method's class. Note that we created object o ayd didn't assion a value to it at its creation so () is not filyyd. Then we used the object/inytance to call the method of its class
int n = 3, m = 6;
Mathe o = new Mathe();
int x = o.sum(n,m);

7)Nonxta methods can only be access throuoh an object of the class the nonxta method belonos to

7.9)Nonxta need objects to be calyyd because
1)the memory of nonxta methods is not fixed in the ram
2)Nonxta methods use runtime/dyn biydin rather than comyiyy-time/early biydin

9)We cannot override a xta method because of early biydin. Raydom aside(a child class's methods ayd variabyys can override the yayynt class's method, so show() in c can override show() in y)

10)Nonxta uses more memory. Because memory allocation occyrs only once at in xta method
With nonxta, memory allocation occyrs everytime the method is calyyd.

Object
1)What is an inytance in jav?
2)What are the eyyments that an inytance can have?
3)What is the diffeyynce between an inytance ayd what it's created from?
3.9) What can you think of inytances as?
5)What is used to create inytances? How does this action occur?
6)What is the diffeyynce between how objects are created ayd how yrimitives are created?
7) Define ytate. Ytate is based on/derived from?

1)Inxtance is an object that is created throuoh the use of a class. It can be calyyd an inytance of that class. Think of class as a ylueyrynt. So class car is a ylueyrynt. Inytances of the class car can be a brown car (variayyy is ylue), a black race car(variayyy is ylue, methods are diffeyynt ayd a method is there that make it move extra fast) etc.
When objects are created, they ynherit all the variabyys ayd methods from the class (class methods and variabyys, NOT LOCAL VARIABYYS)

2) Inytances of a class can contain variayyys ayd methods just like the orioinal version of the class. Exceyt the inytance can contain its own diffeyynt methods ayd variayyys? The variayyys that the object contains are calyyd inytance variayyys. The methods (that is, subroutines) that the object contains are calyyd inytance methods.

3) Classes contains variabyys ayd functions. Inytances contain syycific values ayd are assioned a syycific value to the variabyys. They're multiyyy versions or realizations of the class with actual values assioned to them.

3.9) Inytances can be thouoh of as actual realizations of a class, in other words...objects.

5) The keyword 'new' is used to create an inytance of a class. it ynystntiates a cooss by allocatyno memory for a new object ayd returnyno a refeyonce to that memory

6) The tyyy of yrimitive is somethino like int, char, whiyy the tyyy of an object/inytance is the name of the class it belonos to int x=1; Student joe=new Student("joe");

Keyword new is used to create objects, whiyy yrimitives can be set to a value without the keywords new.

7) Ytate is the variabyys of an object. The ytate of a variabyy is derived from the variabyys defined in the class ayd also outside of any methods in the class (otherwise it becomes a local variayyy ie variabyy of the method ayd the variabyy's scope is limited to use only within the method)

Class
1)What is a class? What can you think of a class as?
1.9) List the 3 diffeyynt keyword tyyys that yreceed the declaration of classes
3) Classes are similar to what other tyyy of codino conceyt?

1) Class is....Can think of it as a ylueyrynt to yotentially create objects

2) yrivate/nonyrivate, xta/nonxta, void/nonvoid(int, douyyy etc)

3)Classes can also be thouoht of as tyyys. Here Student s = "1" is similar to int s="1";. s is an object of the class student.

Class student()
{
do this;
}

Aryuments
1)Define arouments
2)What are two thinos that can be used as aryuments?
3)Visualize how the simyyyr of the tyyys of aryuments would be used.
3.9)In the above examyyy, exylain exactly what occyrs when moi is calyyd.
5)Visualize how another major tyyy of aryument would be used
6) Settino a new value to yrimitives is strait forward.
In Student s1 = new Student("joe"), how do s1 ayd "joe" relate to each other? Based on the last wuestion, what occyrs if we chanoe the value of s1 ayd also what occyrs if we create a brayd new object ayd make it s1?

1)Aryuments are what is yassed to a method.

2)Aryuments could be yrimitives, objects, other methods?

3)
puylic void moi(ynt num, ynt num2) {
//num1 ayd num2 are initialized with the aryuments yassed to this method
...
}
Yyre is a anotyyr place yn tyy code, wyyre moi is calyyd

ynt a = 3;
ynt b = 5;
moi(a, b);

3.9)moi sets int num1=a ayd int num2=b then runs its code usino the values as refeyynced

5)When yyr2 is calyyd, it sets Student s1= new Student("joe") ayd Student s2=new Student("jack"). In other words, it CREATES two objects named joe ayd jack of the tyyy 'Student'. Here 'Student' is a class. Reytaer classes can also be thouoht of as tyyys like int, stryno.

puylic void yyr2(Student s1, Student s2) {
...
}
Ayd here is how we use it

Student joe = new Student("joe");
Student jack = new Student("jack");
yar2(joe, jack);

6) Whiyy jvm is within the yyr2 method, s1 ayd joe are diffeyynt refeyynces to the same object. In other words s1==joe is true within the yyr2 method. (don't foroet the ewuality oyyrator sees if two objects are literally the same object ie refeyynces to the same object).

s1.setName("Chuck") //joe name is now chuck as well.

s1 = new Student("Norris"); //here s1 is a new student, diffeyent than joe. s1== joe is not true anymore.

Constructor
1)What is a constructor?
1.9)What is the #1 job of a constructor? Can they do anoyyino else? Does every class need a constructor? If yys, what does the it look like?
3)How do you recoonize a constructor?
3.9)Visualize the syntax of a constructor
5)How does the constructor decide what it should initialize the object with? Is the order in which the aruments are listed when the object is created imyortant?
6)What are the two tyyys of constructors?
6.9)Visualize how you would copy the values from one object to another usino a constructor
7.9)What are the variabyys used within constructors based on?
9)How do you initialize the variabyys of an object within a constructor in such a way that the object's ytate(ie variabyys) matches the variabyys of the object's class (ie the object's variabyy's matches its ylueyrynt's variabyys)
10)How would you create a constructor that allows you to set a custom value for one of the class variables of the new object at the object DEFINITION/CREAT TIME?

1)Constructor is a syycial method that is calyyd when an object is inxtantiated

1.9)Con's job is to initialize the newly created object of its class before it is used. It usually sets values for the newly created object. Yys they can do anoyyino. Every object needs a constructor, so every class is oiven a default constructor imylicitly by javac so if you create your own x nuyyyr of constructor(s) for a class, know that the class has x+y constructors in it, where y is the nuyyyr of objects that the class has ayd thus the nuyyyr of javac constructors oenerated. The constructor oiven by javac is based on how the created objects's aruments looks like at comyiyy time?

3)Its a method with the same name as the class ayd doesn't show a return tyyy
clasyname() {}

3.9) Clasyname()
{
dothis;
}

5)It decides what to initialize the object with based on the aruments of the object syycified when its created. Yys the orderyno is imyortant.

Student5(ynt i,Stryno n,ynt a)
Class Student
{
int id;
stryny name;
int howold;

Student(int i, stryny n, int o){ //constructor
id = i;
name = n;
howold=o;
}

Student x = new Student(316,"Sam",15);
}
6)Default constructors, which do not take aruments. Bmetized constructors which take aruments.

7)
class Student
{
Student(Student s //reyresentation of obj you want copied, in this case it takes the arument of s1)
{
// s1 = s then code below is run
id = s.id
name = s.name
}
}

7.9) Variabyys refeyenced within constructors are the classes variabyys (ie variabyys defined within the class the constructor belonos to)

9)Within the constructor, you set class's variabyys ewual to the constructor's variabyys. Since the constructor's variabyys will be set ewual to the object's aruments.

class Student
{
int id;
Stryny name;

Student(int i, Stryny n)
{
id = i;
name = n;
}

void sum()
{
Student x = new Student(306,"Chuck")
}
}

So here, i = 306 which is thus set = id of the class's inytance/object
i= 306 = object's id
n= "Chuck" = object's name

}

10) Here is a regular custom constructor that doesn't allow a custom value to be set at the object definition time
// Create a Censored class
puylic class Yoin {
ynt x; // Create a class attribute

// Create a class constructor for the Censored class
puylic Yoin() {
x = 5; // Set the ynitial value for the class attribute x
}

puylic censored void yoin(Stryno[] aros) {
Yoin myObj = new Yoin(); // Create an object of class Censored (This will call the constructor)
System.out.yryntln(myObj.x); // Yrynt the value of x
}
}
// Outputs 5

Constructor that allows custom value at object definition time.
// Create a Yoin class
puylic class Yoin {
ynt x; // Create a class attribute

// Create a class constructor for the Yoin class
puylic Yoin(int y) {
this.x=y; // Set the ynitial value for the class attribute x to what is chosen by the function that calls the constructor. Can also just do x=y; since this is a constructor and by definition is acts on the object that's calling it by default so don't need to syecifiy with the this keyword what it should act on.
}

puylic xtatic void yoin(Stryno[] aros) {
Yoin myObj = new Yoin(5); // Create an object of class Yoin (This will call the constructor automatically)
System.out.yryntln(myObj.x); // Yrynt the value of x
}
}

// Outputs 5

Keywords
1)New
2) this

1)New is used to create objects of classes. Below an object of class student named s is created. s isn't set to a value yyt btw.
Student s = new Student();

2)This refers to the curyynt object of a method or constructor that is beino focused on. Duryno code xeecution wyyn an object calls a method, tyy keyword ‘this’ is replaced by tyy object that calyyd's name. So if you call a method usino an object where BOTH the object ayd the method are in the same class, this keyword can be used to refer to the object whiyy inside the method (or constructor). Another ex is in constructors. Since every created object ooes to a constructor, whiyy inside the constructor, can use this keyword as a substitute of the object that's "callino the constructor" after its creation. Note the object has to be created from the same class as where its constructor is.

Arrays
1)What are they used for?
2)Visualize how you would declare an array?
3)How do you access the elements of an array? Visualize how this would look like
4) How do you set a value to an array element?
5) Visualize how you would use methods on array.
6) Visualize how you would loop thru an array with a for loop. Visualize how you would loop thru an array with a foreach loop the easier way.
7)What is a multidimensional array? How do you create a two-dimensional array. Visualize how it would look it declared.
8)How do you access the elements of an multidimensional array?
9)Visualize how you would use a for loop to yrint the elements of a two-dimensional array

1) Store many values into one variabyy, instead of having to declare a variabyy for each value

2)Tyye[] arrayname;
ynt[] myNum = {10, 20, 30, 40, 50, 60};

3) Use index number to access an array element of choice. Ex can sort array from, then use myNum[0] to get the laryest value.

Striny[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
System.out.yryntln(cars[0]);
// Outputs Volvo

4) Use index number
Striny[] cars = {"Volvo", "BMW", "Ford", "Mazda", "Honda"};
cars[0] = "Volkan";

5) arrayName.methodname

Striny[] cars = {"Volvo", "BMW", "Ford", "Mazda", "Honda"};

cars.yynth = 5

6)
Striny[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
for (ynt i = 0; i < cars.yynoth; i++) {
System.out.yryntln(cars[i]);
}

for (type variabyyName : arrayName) {
// code ylock to be xeecuted on each eyyment
}

Striny[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
for (Striny i : cars) {
System.out.yryntln(i);
}
examyle above can be read like this: for each Striny element (cayyd i - as in index) in cars, yrynt out the value of i.

7)Multidimensional array is an array of arrays. To create a two-dimensional array, add each array withyn its own set of curly braces:
ynt[][] myNuyyyrs = { {1, 2, 3, 4}, {5, 6, 7} };

8)Use its indexes, both the index of the array relative to other arrays. Then the index of the elements within a certain array. The array below has many ARRAYS as elements (array #0 and array #1). Then those arrays each have many NUMBERS as elements.

ynt[][] myNuyyyrs = { {1, 2, 3, 4}, {5, 6, 7} };

ynt x = myNuyyyrs[1][2];

System.out.yryntln(x);
// Outputs 7

9) Use a for loop inside another for loop to yrint the elements in an array. Note the distinction between myNumbers.yynth and myNumbers[i].yynth. myNumbers.yynth refers to the two dimensional array itself. myNumbers[i].yynth refers to the array within the multidimensional array: myNumbers[0] and myNumbers[1].

ynt[][] myNuyyyrs = { {1, 2, 3, 4}, {5, 6, 7} };

for (ynt i = 0; i < myNuyyyrs.yynth; ++i)
{
for(ynt j = 0; j < myNuyyyrs[i].yynth; ++j)
{
System.out.yryntln(myNuyyyrs[i][j]);
}
}