Section 1

Preview this deck

What is Loop?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (17)

Section 1

(17 cards)

What is Loop?

Front

Loops can execute a block of code number of times until a certain condition is met.

Back

Set and HashSet

Front

1. HashSet is part of Java collections. 2. HashSet stores unique values: 3. Set is the interface and HashSet is a class 4. HashSet is implements Set interface 5. In Set object we can store only unique values

Back

MAP AND HASHMAP

Front

MAP : INTERFACE(WE CANNOT CREATE THE OBJECT OF THE INTERFACE) THAT IS WHY WE HAVE HASHMAP: CLASS THAT IMPLEMENTS INTERFACE MAP

Back

How to use "While Loop"

Front

While loop does the exactly same thing what "if statement" does, but instead of running the code block once, they jump back to the point where it began the code and repeats the whole process again.

Back

Definition of for loop

Front

Definition of for loop In Java, there are two forms of for loops. The first form is "traditional" form and the second is "for-each" form. Syntax The general form of traditional for loop statement. for (initialization; condition; iteration) { //body of for loop } Initialization - The initialization of the loop controlling variable of for loop is executed only once, during the first iteration of the loop. Here, the loop controlling variable is initialized, sometimes if the loop variable is not used again anywhere in the program and is only used as the controlling variable of the loop, then it is both declared and initialized in the 'for' loop. Condition - The condition of the 'for' loop is executed each time the loop is iterated. Increment and iteration- The iteration statement is an expression that increment or decrements the loop controlling variable.

Back

three jump statements

Front

Java supports three jump statements 'break' 'continue' and 'return'

Back

continue statement

Front

1. the continue statement helps in jumping from the current loop iteration to the next loop 2. Task: It terminates only the current iteration of the loop 3. Control after break/continue : 'continue' resumes the control of the program to the next iteration of that loop enclosing 'continue'. 4. Causes : It causes early execution of the next iteration. 5. Continuation: 'continue' do not stops the continuation of loop, it only stops the current iteration. 6. Other uses: 'continue' can not be executed with 'switch' and 'labels'.

Back

What is While Loop?

Front

While Loop is used to repeat a block of code. Instead of running the code block once, It executes the code block multiple times until a certain condition is met.

Back

HASHMAP VS HASHTABLE

Front

1. HashMap and Hashtable store key/value pairs in a hash table. 2. When using a Hashtable or HashMap, we specify an object that is used as a key, and the value that you want linked to that key. 3. The key is then hashed, and the resulting hash code is used as the index at which the value is stored within the table.

Back

MAP PROPERTIES

Front

1. They contain values based on key 2. They are not ordered 3. "KEY" should be unique 4. "VALUE" can be duplicate

Back

What is For Loop?

Front

For loop is used to iterate over elements of a sequence. It is often used when you have a piece of code which you want to repeat "n" number of time.

Back

Following are few key points to note about ArrayList in Java -

Front

1. An ArrayList is a re-sizable array, also called a dynamic array. It grows its size to accommodate new elements and shrinks the size when the elements are removed. 2. ArrayList internally uses an array to store the elements. Just like arrays, It allows you to retrieve the elements by their index. 3. Java ArrayList allows duplicate and null values. 4. Java ArrayList is an ordered collection. It maintains the insertion order of the elements. 5. You cannot create an ArrayList of primitive types like int, char etc. You need to use boxed types like Integer, Character, Boolean etc. 6. Java ArrayList is not synchronized. If multiple threads try to modify an ArrayList at the same time, then the final outcome will be non-deterministic. You must explicitly synchronize access to an ArrayList if multiple threads are gonna modify it.

Back

String and StringBuffer object

Front

1. using StringBuffer class; 2. StringBuffer is mutable 3. StringBuffer we have reserve function 4. String is immutable 5. No reverse function is available in String

Back

ArrayList

Front

ArrayList 1.ArrayList is part of collection framework in Java. 2.ArrayList has a set of methods to access elements and modify them. 3.ArrayList : Dynamically sized arrays in Java that implement List interface. ArrayList<Type> arrL = new ArrayList<Type>(); Here Type is the type of elements in ArrayList to be created 4. One need not to mention the size of Arraylist while creating its object. Even if we specify some initial capacity, we can add more elements. 5. However, ArrayList only supports object entries, not the primitive data types. Note: When we do arraylist.add(1); : it converts the primitive int data type into an Integer object.

Back

Break statement

Front

1. The break statement is primarily used as the exit statement, which helps in escaping from the current block or loop 2. Task : It terminates the execution of remaining iteration of the loop. 3. Control after break/continue : 'break' resumes the control of the program to the end of loop enclosing that 'break'. 4. Causes : It causes early termination of loop. 5. Continuation: 'break' stops the continuation of loop. 6. Other uses: 'break' can be used with 'switch', 'label'.

Back

Array

Front

Array 1. An array is basic functionality provided by Java. 2. Array members are accessed using [] 3. Array: Simple fixed sized arrays that we create in Java, like below int arr[] = new int[10] 4. Array is a fixed size data structure while ArrayList is not. 5. Array can contain both primitive data types as well as objects of a class depending on the definition of the array.

Back

Difference Between break and continue

Front

Both "break" and "continue" are the 'jump' statements, that transfer control of the program to another part of the program. The main difference between break and continue is that break is used for immediate termination of loop. On the other hand, 'continue' terminate the current iteration and resumes the control to the next iteration of the loop.

Back