Week 7 - Java Memory & GIT - Java Memory Management, JDK, JRE, JVM, Compilation, DevOps, Command Line and GIT intro Flashcards

1
Q

A Java Development Kit (JDK) is used

A

used to create Java code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The Java code is then compiled into bytecode for a particular

A

Java Runtime Environment (JRE)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Since every machine can implement its own JREs and JVMs, Java source code does not have to be rewritten to be machine-specific. This is known as

A

Write Once, Run Anywhere (WORA)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

describe the terms stack

A

The stack is a region of memory that is used for storing local variables, function arguments, and return addresses during the execution of a program. The stack is a last-in, first-out (LIFO) data structure, which means that the most recently added item is the first one to be removed. The stack is managed automatically by the program’s runtime system, and memory is automatically allocated and deallocated as needed. Because the stack is limited in size, it is typically used for storing data that is of fixed size and is short-lived.

Stack Memory in Java is used for static memory allocation and the execution of a thread. It contains primitive values that are specific to a method and references to objects referred from the method that are in a heap.
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.
When the method finishes execution, its corresponding stack frame is flushed, the flow goes back to the calling method, and space becomes available for the next method.
Key Features of Stack Memory

It grows and shrinks as new methods are called and returned, respectively.
Variables inside the stack exist only as long as the method that created them is running.
It’s automatically allocated and deallocated when the method finishes execution.
If this memory is full, Java throws java.lang.StackOverFlowError.
Access to this memory is fast when compared to heap memory.
This memory is threadsafe, as each thread operates in its own stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe Heap space in java

A

The heap, on the other hand, is a region of memory that is used for storing data that is allocated dynamically during the execution of a program. The heap is managed explicitly by the program, which means that the program is responsible for allocating and deallocating memory as needed. Data stored on the heap can be of variable size and can persist for the lifetime of the program. Because the heap is not limited in size, it is typically used for storing data that is of variable size and is long-lived. However, because the program is responsible for managing the heap, it is also more prone to memory leaks and other errors if not managed properly.

Introduction
Heap space is used for the dynamic memory allocation of Java objects and JRE classes at runtime. New objects are always created in heap space, and the references to these objects are stored in stack memory.
These objects have global access and we can access them from anywhere in the application.
We can break this memory model down into smaller parts, called generations, which are:
Young Generation – this is where all new objects are allocated and aged. A minor Garbage collection occurs when this fills up.
Old or Tenured Generation – this is where long surviving objects are stored. When objects are stored in the Young Generation, a threshold for the object’s age is set, and when that threshold is reached, the object is moved to the old generation.
Permanent Generation – this consists of JVM metadata for the runtime classes and application methods.
Key Features of Java Heap Memory
Some other features of heap space include:
It’s accessed via complex memory management techniques that include the Young Generation, Old or Tenured Generation, and Permanent Generation.
If heap space is full, Java throws java.lang.OutOfMemoryError.
Access to this memory is comparatively slower than stack memory
This memory, in contrast to stack, isn’t automatically deallocated. It needs Garbage Collector to free up unused objects so as to keep the efficiency of the memory usage.
Unlike stack, a heap isn’t threadsafe and needs to be guarded by properly synchronizing the code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Access to stack memory can best be described as…?

A

LIFO; Last In First Out.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When a method is finished executing, which of the following does <b>not</b> happen with the stack?

The flow goes back to the calling method.
Its corresponding stack frame is flushed.
The memory allocated for the stack is lost until the machine is reset.
Space becomes available for the next method.

A

The memory allocated for the stack is lost until the machine is reset.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which of the following is <b>not</b> true about heap space?

Heap space is used for the dynamic memory allocation of Java objects and JRE classes at runtime.
New objects are always created in heap space.
References to objects in heap space are stored in stack memory.
Heap space uses static memory allocation.

A

Heap space uses static memory allocation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which is <b>not</b> a feature of heap memory?

If heap space is full, Java throws java.lang.OutOfMemoryError.
This memory, in contrast to stack, isn’t automatically deallocated.
Unlike stack, a heap isn’t threadsafe and needs to be guarded by properly synchronizing the code..
Access to this memory is faster compared to stack memory

A

Access to this memory is faster compared to stack memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Define and describe how garbage collection works.

A

Garbage collection is the process of removing objects from the heap which have no references to them.
Java abstracts the details away from the developer by allowing the JVM to handle memory management itself.
Garbage collection is run in the background by the JVM. There is no way we can explicitly force garbage collection to happen, but we can request garbage collection to be run through the use of one of the following:
System.gc()
Runtime.getRuntime().gc()
System.runFinalize()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Garbage collection can be forced by

A

It can never be forced.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Variable references are stored in the Stack. T/F?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the easiest way to immediately force Java garbage collection?

A

You cannot force Java garbage collection

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

A Java programming language developer must write memory management into their programs. T/F?

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Which is NOT a consideration when selecting an operating system to use for development?

Marketing of the final product
Speed
Platforms for the final product (local machine, cloud, etc)
Learning curve

A

Marketing of the final product

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

gitbash: ls

A

This command lists directory contents.
It lists files and directories.
Some versions may support color-coding. The names in blue represent the names of directories.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

$ ls -l | more

A

This command helps paginate the output so you can view page by page. Otherwise the listing scrolls down rapidly. You can always use ctrl + c to return to the command line.
Note: more is not supported in GitBash for Windows.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

$ ls –I

A

This command shows more details of the contents in the directory. It lists the following:

Permissions associated with the fileThe owner of the file
The group associated with the file
The size of the file
The timestamp
The name of the file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

cd

A

This changes the current directory. Note that it uses a forward slash.
$ cd /var/log

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

pwd

A

One way to identify the directory you are working in is the pwd command. It displays the current working directory path and is useful when directory changes are made frequently.

$ pwd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

$ mkdir myproject

A

The mkdir command makes a directory. The command is written as follows: mkdir [directory name]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

$ cat > newfilename

A

The cat command can be used to create, view, and concatenate files. The example below creates a new file called “newfilename”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

$ cat sourcefilename > destinationfilename

A

Another way to create a file using cat:
The cat example below will copy the file “sourcefilename” into the file “destinationfilename”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

$ touch filename

A

The touch command creates an empty file for editing later. The command below creates an empty file called “filename”. From there you can use a terminal-based editor like “vi” to edit the file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

$ echo “Some line” > file1.txt

A

The echo command prints the strings that are passed as arguments to the standard output, which can be redirected to a file. To create a new file run the echo command followed by the text you want to print and use the redirection operator > (as explained with cat above) to write the output to the file you want to create.
The command below will create the file “file.txt” containing the text “Some line”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

$ grep Aaron filename

A

The grep command can be used to search files and directories (and subdirectories) for a string. The example below searches the file “filename” for the string “Aaron”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

$ diff file1.txt file2.txt

A

The diffcommand compares two files line by line to find differences. The output will be the lines that are different.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

mv

A

The mv command moves a file or renames it. Some examples; inline comments denoted with //

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

$ mv file1 directory1

A

moves ‘file1’ to ‘directory1’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

$ mv file1 file2 file3 dir1

A

moves ‘file1’, ‘file2’, and ‘file3’ to ‘dir1’

31
Q

$ mv file1 file2

A

renames ‘file1’ with the new name ‘file2’. This can also be used to rename directories.

32
Q

$ mv -i file1 directory1

A

just as above, this will move ‘file1’ into ‘directory1’ but the -i flag will prompt the operator should the command result in overwriting an existing file

33
Q

$ mv -n file1 directory1

A

similar to the above, however the -n flag will not move ‘file1’ to ‘directory1’ if it causes an overwrite

34
Q

$ mv -u file1 directory1

A

The -u flag will only move ‘file1’ to ‘directory1’ if the source file is newer than the destination file

35
Q

$ mv -b file1 directory1

A

The -b flag will create a backup of any existing destination file overwritten by ‘file1’.

36
Q

cp

A

The cp command copies a file. Some examples; inline comments denoted with //

37
Q

$ cp second.txt third.txt

A

copies ‘second.txt’ into a file ‘third.txt’

38
Q

$ cp -i second.txt third.txt

A

-i stands for Interactive copying. With this option system first warns the user before overwriting the destination file

39
Q

$ cp -b second.txt third.txt

A

-b will create a backup of the destination file in the same folder

40
Q

$ cp -f second.txt third.txt

A

-f stands for force; if the system cannot open the destination file then the destination file is deleted first before the copying proceeds

41
Q

$ cp -r directory1 directory2

A

-r is for Recursive copying which is used for copying the contents of ‘directory1’, including all subdirectories, into ‘directory2’

42
Q

$ cp -p second.txt third.txt

A

-p stands for preserve. The command preserves some characteristics of ‘second.txt’ in the destination file ‘third.txt’ including times of last modification and access, ownership, and file permissions

43
Q

rm

A

The rm command deletes files/directories. Some examples; inline comments denoted with //

44
Q

$ rm file1

A

deletes ‘file1’ in the current working directory.

45
Q

$ rm -i file1

A

-i stands for interactive; this prompts the operator before deleting each file

46
Q

$ rm -f file1

A

-f forces deletion if a file is write protected. It will not remove a write-protected directory

47
Q

$ rm -r directory1

A

-r (recursive) will delete all files in ‘directory1’ and all subdirectories of ‘directory1’ and their contents

48
Q

what is git?

A

Git is a distributed version control system used for tracking changes in source code during software development. Git is designed to be fast and efficient, and it can handle projects of any size, from small personal projects to large enterprise software development.

With Git, developers can create a local repository on their computer to work on code changes and track those changes over time. They can then push those changes to a remote repository, which can be shared with other developers or integrated into a larger project. Git uses a branching and merging system that allows multiple developers to work on different features or parts of a project simultaneously, and then merge their changes together when they’re ready.

Git also provides features such as version history, blame (to see who made changes to specific lines of code), and diff (to see differences between different versions of a file). It is a command-line tool, but there are also many GUI clients available for those who prefer a visual interface.

49
Q

What is version control?

A

Version control, also known as source control, is the practice of tracking and managing changes to software code. Version control systems (VCS) are software tools that help software teams manage changes to source code over time. As development environments have accelerated, version control systems help software teams work faster and smarter.

Version control software keeps track of every modification to the code in a special kind of database. If a mistake is made, developers can turn back the clock and compare earlier versions of the code to help fix the mistake while minimizing disruption to all team members.

50
Q

Git has three main states in that your files can reside:

A

modified, staged, and committed:

51
Q

Modified

A

means that you have changed the file but have not committed it to your database yet

52
Q

Staged

A

means that you have marked a modified file in its current version to go into your next commit snapshot.

53
Q

Committed

A

means that the data is safely stored in your local database.

54
Q

What is Git Bash?

A

Git Bash is an application for Microsoft Windows environments which provides an emulation layer for a Git command line experience. Bash is an acronym for Bourne Again Shell. A shell is a terminal application used to interface with an operating system through written commands. Bash is a popular default shell on Linux and macOS. Git Bash is a package that installs Bash, some common bash utilities, and Git on a Windows operating system.

55
Q

The basic Git workflow goes something like this:

A

You modify files in your working directory.

You selectively stage just those changes you want to be part of your next commit, which adds only those changes to the staging area. (See “git add” in the diagram below)

You commit the changes, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory. (See “git commit” and “git push” in the diagram below)

56
Q

What is a Git Repository?

A

A Git repository tracks and saves the history of all changes made to the files in a Git project. It saves this data in a directory called .git, also known as the repository folder.

57
Q

Initialize a Repository
git

A

To initialize a Git repository in an existing directory, start by using the Git Bash terminal window to go to your project’s directory:

cd [directory path]
Where [directory path]: The path to your project directory.

58
Q

Once you navigate to the project directory, initialize a Git repository by using:

A

git init

59
Q

git clone [url] [directory]

A

Use the git clone command to clone an existing repository and copy it to your system:

60
Q

$ git add .

A

Use git add . in your bash to add all the files to the given folder.

61
Q

$ git status

A

Use git status in your bash to view all the files which are going to be staged to the first commit.

62
Q

git commit -m ‘your message”

A

You can create a commit message by git commit -m ‘your message’, which adds the change to the local repository.
git commit uses ‘-m’ as a flag for a message to set the commits with the content where the full description is included. It is recommended that you write in double-quotes an imperative sentence in 50 characters that describes what changed and why. For example, “Corrected println error in helloworld.java”

63
Q

git push

A

git push is used for pushing local content to GitHub.

64
Q

What is the git command for downloading files from a remote repository?

A

git pull

65
Q

What is the git command for integrating changes?

A

git merge

66
Q

git branch

A

list all current branches

67
Q

git branch branch_name

A

create new branch from current

68
Q

git checkout branch_name

A

checkout another branch

69
Q

git checkout -b branch_name

A

checkout branch and create it if branch doesnt already exist

70
Q

git merge branch_name

A

merge branch_name to the current branch you are in

71
Q

git add file_name

A

add specific file to staging

72
Q

git remote add origin url_to_remote_repo

A

connect remote repository origin to local repository

73
Q

git log

A

display all local commit IDs

74
Q

git clone remote_repo_url

A

retrieve code base from remote repository to your local machine for the first time