Java terms for Assessment 2

Ace your homework & exams now with Quizwiz!

Java String Methods

1- char charAt(int index), 2- boolean equals(Object obj), 3- boolean equalsIgnoreCase(String string), 4- int compareTo(String string), 5- String substring(int beginIndex), 6- String substring(int beginIndex, int endIndex), 7- Str, 8- ing concat(String str), 9- boolean contains(CharSequence s), 10- String toUpperCase(Locale locale), 11- String[] split(String regex, int limit), 12- String toLowerCase(Locale locale), 13- String trim(), 14- int length(), 15-boolean matches(String regex)

collections

A Collection is a group of individual objects represented as a single unit. Java provides Collection Framework which defines several classes and interfaces to represent a group of objects as a single unit. The Collection interface (java.util.Collection) and Map interface (java.util.Map) are the two main "root" interfaces of Java collection classes Advantages of Collection Framework: -Consistent API : The API has a basic set of interfaces like Collection, Set, List, or Map. All classes (ArrayList, LinkedList, Vector, etc) that implement these interfaces have some common set of methods. -Reduces programming effort: A programmer doesn't have to worry about the design of Collection, and he can focus on its best use in his program. -Increases program speed and quality: Increases performance by providing high-performance implementations of useful data structures and algorithms.

Java Collection Framework

A Java collection framework provides an architecture to store and manipulate a group of objects. A Java collection framework includes the following: -Interfaces -Classes -Algorithm Interfaces: Interface in Java refers to the abstract data types. They allow Java collections to be manipulated independently from the details of their representation. Also, they form a hierarchy in object-oriented programming languages. Classes: Classes in Java are the implementation of the collection interface. It basically refers to the data structures that are used again and again. Algorithm: Algorithm refers to the methods which are used to perform operations such as searching and sorting, on objects that implement collection interfaces. Algorithms are polymorphic in nature as the same method can be used to take many forms or you can say perform different implementations of the Java collection interface. The Java collection framework provides the developers access prepackaged data structures as well as algorithms to manipulate data.

Java Collection Framework

A Java collection framework provides an architecture to store and manipulate a group of objects. A Java collection framework includes the following: -Interfaces -Classes -Algorithm Interfaces: Interface in Java refers to the abstract data types. They allow Java collections to be manipulated independently from the details of their representation. Also, they form a hierarchy in object-oriented programming languages. Classes: Classes in Java are the implementation of the collection interface. It basically refers to the data structures that are used again and again. Algorithm: Algorithm refers to the methods which are used to perform operations such as searching and sorting, on objects that implement collection interfaces. Algorithms are polymorphic in nature as the same method can be used to take many forms or you can say perform different implementations of the Java collection interface. The Java collection framework provides the developers access to prepackaged data structures as well as algorithms to manipulate data.

simple for loop

A for loop is a control structure that allows us to repeat certain operations by incrementing and evaluating a loop counter. Before the first iteration, the loop counter gets initialized, then the condition evaluation is performed followed by the step definition (usually a simple incrementation).

logic error

A logic error is a mistake in a program's source code that results in incorrect or unexpected behavior. It is a type of runtime error that may simply produce the wrong output or may cause a program to crash while running. Logic errors are not always easy to recognize immediately. This is due to the fact that such errors, unlike that of syntax errors, are valid when considered in the language, but do not produce the intended behavior.

methods

A method is a set of code which is referred to by name and can be called (invoked) at any point in a program simply by utilizing the method's name. Think of a method as a subprogram that acts on data and often returns a value. Each method has its own name. When that name is encountered in a program, the execution of the program branches to the body of that method. When the method is finished, execution returns to the area of the program code from which it was called, and the program continues on to the next line of code.

reference data types

A reference type is a data type that's based on a class rather than on one of the primitive types that are built into the Java language./ Any instantiable class as well as arrays./ The class can be a class that's provided as part of the Java API class library or a class that you write yourself.

runtime errors

A runtime error is a program error that occurs while the program is running. The term is often used in contrast to other types of program errors, such as syntax errors and compile time errors. There are many different types of runtime errors. One example is a logic error, which produces the wrong output. For example, a miscalculation in the source code or a spreadsheet program may produce the wrong result when a user enters a formula into a cell. A program crash is the most noticeable type of runtime error, since the program unexpectedly quits while running. NOTE: Runtime errors are commonly called referred to as "bugs," and are often found during the debugging process, before the software is released. When runtime errors are found after a program has been distributed to the public, developers often release patches, or small updates, designed fix the errors.

switch statement (conditional)

A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case.

copying an array

Arrays in Java are Objects. If you try to treat them as variables... well you can(!) but what you are really copying is the reference!There are several ways to copy an array: -use the various copyOf and copyOfRange methods of the Arrays class - probably the simplest method -use System.arraycopy - useful when copying parts of an array -call its clone method, and do a cast - the simplest style, but only a shallow clone is performed -use a for loop - more than one line, and needs a loop index

immutable objects

An object is considered immutable if its state cannot change after it is constructed.

access modifiers

As the name suggests, access modifiers in Java help to restrict the scope of a class, constructor, variable , method or data member. There are four types of access modifiers available in java: 1- Default - No keyword required 2- Private 3- Public 4- Protected

checked and unchecked exceptions

In Java, there are two types of exceptions: 1) Checked: are the exceptions that are checked at compile time. If some code within a method throws a checked exception, then the method must either handle the exception or it must specify the exception using throws keyword. 2) Unchecked are the exceptions that are not checked at compiled time. In Java, exceptions under Error and RuntimeException classes are unchecked exceptions, everything else under throwable is checked.

basic syntax

It is very important to keep in mind the following points. Case Sensitivity − Java is case sensitive, which means identifier Hello and hello would have different meaning in Java. Class Names − For all class names the first letter should be in Upper Case. If several words are used to form a name of the class, each inner word's first letter should be in Upper Case. Example: class MyFirstJavaClass Method Names − All method names should start with a Lower Case letter (aka camel case). If several words are used to form the name of the method, then each inner word's first letter should be in Upper Case. Example: public void myMethodName() Program File Name − Name of the program file should exactly match the class name. When saving the file, you should save it using the class name (Remember Java is case sensitive) and append '.java' to the end of the name (if the file name and the class name do not match, your program will not compile). Example: Assume 'MyFirstJavaProgram' is the class name. Then the file should be saved as 'MyFirstJavaProgram.java' public static void main(String args[]) − Java program processing starts from the main() method which is a mandatory part of every Java program.

stacks

Java Collection framework provides a Stack class which models and implements Stack data structure. The class is based on the basic principle of last-in-first-out (LIFO). In addition to the basic push and pop operations, the class provides three more functions of empty, search and peek. The class can also be said to extend Vector and treats the class as a stack with the five mentioned functions. The class can also be referred to as the subclass of Vector.

arrays

Java arrays are objects that are dynamically created. An array object contains a number of elements. The elements contained in an array all have the same name and are referenced by using an index with a nonnegative integer value. If an array has n elements, then n is the length of the array. The elements of the array are referenced using integer indexes from 0 to n-1, inclusive. All the elements of an array have the same type, called the component type of the array. If the element type of an array is int, then the type of the array itself is written int[ ]. An array may have more than one dimension. The element type of an array may be any type, whether primitive or an object. A variable of array type holds a reference to an object. Declaring a variable of array type does not create an array object or allocate any space for array components. It creates only the variable itself, which can contain a reference to an array. You declare an array variable in the same way as you declare any scalar variable, but you insert a pair of square brackets. You can also declare an array variable by placing the square brackets after the identifier name, but the preferred format among Java programmers is to place the brackets following the variable type. Declaring an array does not set aside memory for the array. The array must be created (allocate the memory) later before it can be referenced (used) Syntax: Type name[ ]; or Type[ ] name; Example1 double grades[ ]; double[ ] grades; You create an array by allocating memory for it. The keyword new must be used to create an array. An integer contained within square brackets indicates the number of array elements being created. Array elements are initialized to zero for numerics, the value '\u0000' for characters and false for boolean. Elements of an array are numbered beginning with zero. To initialize the data in one-dimensional array, you just place the values between curly braces, one value after the other, separated by commas, beginning with the first value in the array. An initialized list can be used to instantiate an array object instead of using the new operator. The size of the array and its initial values are determined by the initialized list.

syntax error

Mistakes made by a programmer in implementing the syntax of the Java programming language. Syntax errors are a type of compiler error. This means they will be detected immediately when the programmer tries to convert his source code into a program. If the syntax of your code is incorrect, then in most cases the compiler can't use the code to create byte code for the JRE, i.o.w., a program will not compile until all syntax errors are corrected. This is opposed to runtime errors, which are not detected until the program is actually running.

parameters

Parameters are the variables that are listed as part of a method declaration. Each parameter must have a unique name and a defined data type. A parameter is the technical term for the value between the round brackets of your method headers.

sets

Set is an interface which extends Collection. It is an unordered collection of objects in which duplicate values cannot be stored. Basically, Set is implemented by HashSet, LinkedHashSet or TreeSet (sorted representation). Set has various methods to add, remove clear, size, etc. to enhance the usage of this interface

String literal

Strings can be created like this: Assigning a String literal to a String instance: String str1 = "Welcome"; String str2 = "Welcome";

lists

The Java.util.List is a child interface of Collection. It is an ordered collection of objects in which duplicate values can be stored. Since List preserves the insertion order, it allows positional access and insertion of elements. List Interface is implemented by ArrayList, LinkedList, Vector and Stack classes.

queues

The Queue interface is available in java.util package and extends the Collection interface. The queue collection is used to hold the elements about to be processed and provides various operations like the insertion, removal etc. It is an ordered list of objects with its use limited to insert elements at the end of the list and deleting elements from the start of list i.e. it follows the FIFO or the First-In-First-Out principle. Being an interface the queue needs a concrete class for the declaration and the most common classes are the PriorityQueue and LinkedList in Java. A few important characteristics of Queue are: The Queue is used to insert elements at the end of the queue and removes from the beginning of the queue. It follows FIFO (First-In-First-Out) concept. The Java Queue supports all methods of Collection interface including insertion, deletion etc. LinkedList, ArrayBlockingQueue and PriorityQueue are the most frequently used implementations. If any null operation is performed on BlockingQueues, NullPointerException is thrown. Methods in Queue: -add()- This method is used to add elements at the tail of queue. More specifically, at the last of linkedlist if it is used, or according to the priority in case of priority queue implementation. -peek()- This method is used to view the head of queue without removing it. It returns Null if the queue is empty. -element()- This method is similar to peek(). It throws NoSuchElementException when the queue is empty. -remove()- This method removes and returns the head of the queue. It throws -SuchElementException when the queue is impty. -poll()- This method removes and returns the head of the queue. It returns null if the queue is empty.

do-while loop

The do-while loop works just like the while loop except for the fact that the first condition evaluation happens after the first iteration of the loop: 1 do { 2 statement; 3 } while (Boolean-expression);

maps

The java.util.Map interface represents a mapping between a key and a value. The Map interface is NOT a subtype of the Collection interface. Therefore it behaves a bit differently from the rest of the collection types. - mapinterface A few characteristics of the Map Interface are: - A Map cannot contain duplicate keys and each key can map to at most one value. -Some implementations allow null key and null value like the HashMap and LinkedHashMap, but some do not like the TreeMap. -The order of a map depends on specific implementations, e.g TreeMap and LinkedHashMap have predictable order, while HashMap does not. -There are two interfaces for implementing Map in java: Map and SortedMap, and three classes: HashMap, TreeMap and LinkedHashMap.

return types

The return type (or result type) defines and constrains the data type of the value returned from a subroutine or method. You declare a method's return type in its method declaration. Within the body of the method, you use the return statement to return the value. Any method declared void doesn't return a value. It does not need to contain a return statement, but it may do so. In such a case, a return statement can be used to branch out of a control flow block and exit the method and is simply used like this: return; If you try to return a value from a method that is declared void, you will get a compiler error. Any method that is not declared void must contain a return statement with a corresponding return value, like this: return returnValue; The data type of the return value must match the method's declared return type. For ex., you can't return an integer value from a method declared to return a boolean.

while loop

The while loop is Java's most fundamental loop statement. It repeats a statement or a block of statements while its controlling Boolean-expression is true. The syntax of the while loop is: 1 while (Boolean-expression) 2 statement;

primitive data types

There are 8 types: boolean, byte, char, short, int, long, float, double

recursion

When a function calls itself. The "Hello, World" for recursion is the factorial function, which is defined for positive integers n by the equation n!=n×(n−1)×(n−2)×...×2×1 The quantity n! is easy to compute with a for loop, but an even easier method in Factorial.java is to use the following recursive function: public static long factorial(int n) { if (n == 1) return 1; return n * factorial(n-1); }

method invocation

When a method is invoked (called), a request is made to perform some action, such as setting a value, printing statements, returning an answer, etc. The code to invoke the method contains the name of the method to be executed and any needed data that the receiving method requires. The required data for a method are specified in the method's parameter list. Consider this method that we have already been using from Breezy; int number = Console.readInt("Enter a number"); //returns a value The method name is "readInt" which is defined in the class "Console". Since the method is defined in the class Console, the word Console becomes the calling object. This particular method returns an integer value which is assigned to an integer variable named number. You invoke (call) a method by writing down the calling object followed by a dot, then the name of the method, and finally a set of parentheses that may (or may not) have information for the method.

if-else statement (conditional)

allows us to select between two alternatives/ expression of type boolean that evaluates to true or false

if statement (conditional)

an if statement allows us to execute a certain part of code if a condition is satisfied (and do nothing otherwise)

enhanced for loop

the enhanced for which makes it easier to iterate over all elements in an array or a collection. The syntax of the enhanced for loop is: 1 for(Type item : items) 2 statement;


Related study sets

Health and Welfare Plans Strategic Planning and Design

View Set

Chapter 31: Caring for Clients with Disorders of the Hematopoietic System

View Set

Module 9 Reading Assignment - Cardiovascular Diseases

View Set

Chapter 14: Statute of Frauds and Equitable Exceptions

View Set

GEB 1011 Business Principles Chapter 6 Smartbook

View Set

NSG 245 Ch 40- Musculoskeletal Care Modalities

View Set