Java

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

There are ________ datatypes/primitives in Java

8

Parameterized Constructor

A Java constructor can also accept one or more parameters. Such constructors are known as parameterized constructors (constructor with parameters).

Linked List

A Linked List is a linear collection of data elements whose order is not given by their physical placement in memory (the elements are not stored in contiguous locations). Instead, each element points to the next. It is a data structure consisting of a collection of nodes which together represent a sequence. In its most basic form, each node contains: data, and a reference (in other words, a link) to the next node in the sequence.

Why is a String Immutable?

A String is immutable in Java, an immutable object is an object whose content cannot be changed after it is created. When we try to concatenate two Java strings, a new String object is created in the string pool. This can be demonstrated by comparing HashCode for String object after every concat operation.

StringBuilder

The StringBuilder class is used for storing the mutable (changeable) sequence which means we can update the elements of the StringBuilder class without creating a new StringBuilder sequence in memory. We can create an empty String using this class as well.

This

The ________ keyword refers to the current object in a method or constructor. The most common use of the ________ keyword is to eliminate the confusion between class attributes and parameters with the same name (because a class attribute is shadowed by a method or constructor parameter).

Runtime Errors

A runtime error in Java is an application error that occurs during the execution of a program. A runtime error occurs when a program is syntactically correct but contains an issue that is only detected during program execution. (i.e, StringIndexOutOfBoundsException, NullPointerException, and etc.)

What's the difference between StringBuilder and StringBuffer?

A String is immutable whereas StringBuffer and StringBuilder are mutable classes. StringBuffer is thread-safe and synchronized whereas StringBuilder is not. That's why StringBuilder is faster than StringBuffer. Since String is immutable in Java, whenever we do String manipulation like concatenation, substring, etc. it generates a new String and discards the older String for garbage collection. These are heavy operations and generate a lot of garbage in heap. So Java has provided StringBuffer and StringBuilder classes that should be used for String manipulation. StringBuffer and StringBuilder are mutable objects in Java. They provide append(), insert(), delete(), and substring() methods for String manipulation. StringBuffer was the only choice for String manipulation until Java 1.4. But, it has one disadvantage that all of its public methods are synchronized. StringBuffer provides Thread safety but at a performance cost. In most of the scenarios, we don't use String in a multithreaded environment. So Java 1.5 introduced a new class StringBuilder, which is similar to StringBuffer except for thread-safety and synchronization. StringBuffer has some extra methods such as substring, length, capacity, trimToSize, etc. However, these are not required since you have all these present in String too. That's why these methods were never implemented in the StringBuilder class. StringBuffer was introduced in Java 1.0 whereas StringBuilder class was introduced in Java 1.5 after looking at shortcomings of StringBuffer. If you are in a single-threaded environment or don't care about thread safety, you should use StringBuilder. Otherwise, use StringBuffer for thread-safe operations.

Stack

A _____________ is a linear data structure and abstract data type that contains only one point of entry hence why data can only be added, removed, sorted and processed in a last in, first out basis otherwise known as LIFO. You can think of a ________ as a __________ of pancakes, the last pancake to be eaten will be the first pancake.

Set

A ________________ is a Collection that cannot contain duplicate elements. It models the mathematical set abstraction. The _________________ interface contains only methods inherited from Collection and adds the restriction that duplicate elements are prohibited.

Framework

A ________________ is a structure that you can build software on. It serves as a foundation, so you're not starting entirely from scratch.

Method

A behavior or set of behavior(s) defined in a class. The purpose for creating a method is to prevent duplication and promote maintenance.

Difference Between Compile Time Errors and Runtime Errors

A compile-time error generally refers to the errors that correspond to the semantics or syntax. A runtime error refers to the error that we encounter during the code execution during runtime. We can easily fix a compile-time error during the development of code. A compiler cannot identify a runtime error.

Constructor

A constructor in Java is a special method that is used to initialize objects.

Data Structure

A data structure is defined as a manner in which data is stored or organized in memory. They're either linear or non-linear, simple or complex. If you want to store data one on top of the other, you'll probably use a Stack, in a linear fashion, you'll probably use an Array, ArrayList, or Linked List, in a Hierarchical manner, you'll probably use a Tree or Graph.

Boolean

A data type that can only store true and false values, it is 1 bit, no bytes.

Byte

A data type that can store whole numbers from -128 and 127, a byte's size is 1. It allocates 1 byte in memory and it's 8-bits.

Double

A data type that can stores fractional numbers ranging 15 decimal digits, it is 8-bytes or 64-bits.

Char

A data type that is used to store a single character, single quotes are used for characters, e.g., 'A', 'c'. They're also accompanied by an ASCII character. A char is 2 bytes or 16-bits.

Generic Classes

A generic class is implemented exactly like a non-generic class. The only difference is that it contains a type parameter section. There can be more than one type of parameter, separated by a comma. The classes, which accept one or more parameters, ​are known as parameterized classes or parameterized types.

Library

A library is a collection of prewritten code that users can use to optimize tasks to promote reusability. In Java, library files are abbreviated as .jar files also known as Java Archive Files.

Literal

A literal is a constant value that we assign to the variable, it can be numeric, a boolean, character, or String.

Method Signature

A method signature consists of it's access modifier, whether it is static or non-static, it's return type or void, it's name and parameters considered in the order left to right.

Nested Loops

A nested loop is when a loop has another loop in it's body. The original loop is called the outer loop and it's counterpart is called the inner loop. A common use case is when you're trying to compare one element in a list to every element in that list. Nested loops can be implemented using a while and for loop.

Package

A package refers to a namespace hierarchy of files, that allows for code organization by storing source code and related files in a directory like structure for management and maintenance purposes.

What's the difference between a parameter and argument?

A parameter is a variable in a method definition. When a method is called, the arguments are the data you pass into the method's parameters. The general consensus seems to be that it's completely acceptable to use these terms interchangeably in a team environment.

Parameter(s)

A parameter is a variable used to define a particular value during a function definition. Whenever we define a function we introduce our compiler with some variables that are being used in the running of that function. These variables are often termed as Parameters.

Abstraction

Abstraction is a process where you show only "relevant" data and "hide" unnecessary details of an object from the user. It allows you to focus on what the object does instead of how it does it.

Aggregation

Aggregation is a term which is used to refer one way relationship between two objects. For example, Student class can have reference of Address class but vice versa does not make sense. In Java, aggregation represents HAS-A relationship, which means when a class contains reference of another class known to have aggregation. The HAS-A relationship is based on usage, rather than inheritance. In other words, class A has-a relationship with class B, if class A has a reference to an instance of class B.

What's the difference between an Interface and Abstract Class?

An Abstract class can have abstract and non-abstract methods. Interface can have only abstract methods. Since Java 8, it can have default and static methods also. Abstract class doesn't support multiple inheritance. Interface supports multiple inheritance. Abstract class can have final, non-final, static and non-static variables. Interface has only static and final variables.

Interface

An Interface is a template for a class. You can think of it as a contract between itself and the implementation (i.e., class).

Argument(s)

An argument is a value passed to a function when the function is called. Whenever any function is called during the execution of the program there are some values passed with the function. These values are called arguments. An argument when passed with a function replaces with those variables which were used during the function definition and the function is then executed with these values.

Enumerate

An enumeration (enum for short) in Java is a special data type (A class type) which contains a set of predefined constants. You'll usually use an enum when dealing with values that aren't required to change, like days of the week, seasons of the year, colors, and so on. To create an enum, we use the enum keyword, similar to how you'd create a class using the class keyword. Here's an example: enum Colors { RED, BLUE, YELLOW, GREEN }

Object

An object is an instance of a class. From one class we can create many instances. Each object has an identity, a behavior and a state. The state is stored in fields (variables), while methods (functions) display the object's behavior. The methods and fields may be accessed using dot notation. Objects are created at runtime from templates, which are also known as classes.

ArrayList

ArrayList is a resizable array and it's used to store dynamically sized collection of elements. Contrary to Arrays that are fixed in size, an ArrayList grows it's size automatically when new elements are added to it.

Array

Arrays are used to store multiple values of the same type in a single variable, instead of declaring separate variables for each value. An array is a fixed data structure because we need to establish it's size at declaration/creation.

Datatype/Primitive

As the name suggests, data types specify the type of data that can be stored inside variables in Java. Java is a statically-typed language. This means that all variables must be declared before they can be used.

What are the eight Java Datatypes?

Byte, Short, Int, Long, Char, Boolean, Double, Float

Catch

Catches exceptions generated by try statements.

Is the naming convention for a class

Class names should be camel cased, noun, start with a capital letter. Also, each word in the name should also start with a capital letter (e.g. LinkedList). Some examples are shown below: ArrayList LinkedList String TopSong GearBox Main

Composition

Composition describes a class that references one or more objects of other classes as a field.

Continue

Continues to the next iteration of a loop.

Class

Defines a class.

Access Modifier

Defines the access type of the method i.e. from where it can be accessed in your application.

Encapsulation

Encapsulation refers to the bundling of fields and methods inside a single class. This design principle promotes consolidation and enables data hiding, a feature that promote secure access to fields by keeping them private and utilizing setter and getters for modification.

What is the naming convention for a variable?

For variables, the Java naming convention is to always start with a lowercase letter and then capitalize the first letter of every subsequent word. Variables in Java are not allowed to contain white space, so variables made from compound words are to be written with a lower camel case syntax.

Generic Methods

Generic methods takes a parameter and returns some value after performing a task. It is exactly like a normal function, however, a generic method has type parameters that are cited by actual type. This allows the generic method to be used in a more general way. The compiler takes care of the type of safety which enables programmers to code easily since they do not have to perform long, individual type castings.

toString

If you want to represent any object as a string, toString() method comes into existence. The toString() method returns the String representation of the object. If you print any object, Java compiler internally invokes the toString() method on the object. So overriding the toString() method, returns the desired output, it can be the state of an object etc. depending on your implementation.

Association

Illustrates an object to object relationship. Association can be one-to-one, one-to-many, many-to-one, many-to-many. In Object-Oriented programming, an Object communicates to another object to use functionality and services provided by that object. Composition and Aggregation are the two forms of association.

Scope

In Java, ____________ defines where a certain variable, keyword and/or method is accessible in a program. Variables, keyword, and methods can be defined as having one of three types of ________________

List

In Java, a _____________ interface is an ordered collection of objects in which duplicate values can be stored. Since a ___________ preserves the insertion order, it allows positional access and insertion of elements. The ___________ interface is implemented by the following classes: ArrayList, LinkedList

Casting

In Java, type casting is a method or process that converts a data type into another data type in both ways manually and automatically. The automatic conversion is done by the compiler and manual conversion performed by the programmer.

Big O notation

In computer science, big O notation refers to algorithmic complexity and is used to classify algorithms according to how their run time or space requirements grow as the input size grows.

What is an API

In layman's terms, an API is an agreement between two people stating: "If you give me this instruction, I will perform this action, or return this information." Essentially, an application programing interface serves as an intermediary to allow applications or software to communicate, more specially, to utilize one another's services and functionalities.

Inheritance

Inheritance refers to the creation of a class from an existing class. The created class is known as a subclass, child or derived class and the existing class is known as a superclass, parent or base class.

Inner Class

Inner classing refers to a class being declared or established inside another class. In Java, it is also possible to nest classes (a class within a class). The purpose of nested classes is to group classes that belong together, which makes your code more readable and maintainable. To access the inner class, create an object of the outer class, and then create an object of the inner class

What operations are performed on a data structure?

Insertion, Deletion, Traversal, Searching, Sorting, and Access.

Is the naming convention for an Interface

Interfaces are capitalized like class names (CamelCased). Consider what objects implementing the interface will become of what they will be able to do. Some examples are shown below: List Comparable Serializable

Method body

It is the block of code, enclosed between braces, that you need to execute to perform your intended operations.

Iterator vs Foreach In Java

Iterator is an interface provided by the collections framework or API to traverse a collection and for sequential access of items in the collection while the for-each loop is meant for traversing items in a collection.

Generics

Java Generics is a solution designed to reinforce the type safety that Java was designed to have. Generics allow types to be parameterized onto methods and classes and introduces a new layer of abstraction for formal parameters.

StringBuffer

Java StringBuffer class is used to create mutable (modifiable) String objects. The StringBuffer class in Java is the same as String class except it is mutable i.e. it can be changed. We can create an empty String using this class as well.

Final

Java final keyword is a non-access specifier that is used to restrict a class, variable, and method. If we initialize a variable with the final keyword, then we cannot modify its value. If we declare a method as final, then it cannot be overridden by any subclasses. And, if we declare a class as final, we restrict the other classes to inherit or extend it. In other words, the final classes can not be inherited by other classes. This was a brief introduction to a final keyword in Java. Now we will discuss the implementation of the final keyword with a variable, method, and class in Java. We will discuss the following topics in detail: 1. final variable2. final class3. final method

Garbage Collector

Java garbage collection is the process by which Java programs perform automatic memory management. Java programs compile to bytecode that can be run on a Java Virtual Machine, or JVM for short. When Java programs run on the JVM, objects are created on the heap, which is a portion of memory dedicated to the program. Eventually, some objects will no longer be needed. The garbage collector finds these unused objects and deletes them to free up memory.

What is the difference between a library, an API, and a framework?

Library is a collection of all classes and methods stored for re-usability. Every library has API. API is sum of all exposed functions/methods in a library that you can call. A framework is a big library that provides many services instead of specific ones, like most libraries do.The control flow in a framework is already there, and there are a bunch of predefined white spots that we should fill out with our code.

Logical Error

Logic errors occur when there is a fault in the logic or structure of the problem. Logic errors do not usually cause a program to crash. However, logic errors can cause a program to produce unexpected results. In computer programming, a logic error is a bug in a program that causes it to operate incorrectly, but not to terminate abnormally (or crash).

Case

Marks a block of code in switch statements.

What types of constructors exist in Java?

No-Arg Constructor, Parameterized Constructor, Default Constructor

No-Arg Constructor

Similar to methods, a Java constructor may or may not have any parameters (arguments). If a constructor does not accept any parameters, it is known as a no-argument constructor.

Instantiation

Simple meaning of instantiate is creating an object from class or creating an object. An example is shown below: ClassName obj = new ClassName();

Default

Specifies the default block of code in a switch statement.

Comparable

The Comparable interface is used to compare an object of the same class with an instance of that class, it provides ordering of data for objects of the user-defined class.

Map

The Java __________ interface, java.util.______ represents a mapping between a key and a value. More specifically, a Java __________ can store pairs of keys and values. Each key is linked to a specific value. Once stored in a __________, you can later look up the value using just the key. Let's consider an example for a better understanding where you will see how you can add elements by using the _________ interface in java.

Collections

The Java collections framework provides a set of interfaces and classes to implement various data structures and algorithms.

Queue

The ___________ interface is present in java.util package and extends the Collection interface is used to hold the elements about to be processed in FIFO(First In First Out) order. It is an ordered list of objects with its use limited to inserting elements at the end of the list and deleting elements from the start of the list, (i.e.), it follows the FIFO or the First-In-First-Out principle.

Extend

The extends keyword is used to perform inheritance in Java.

Subscript

The first subscript is always zero and the last subscript's value is. (length - 1), where length designates the number of elements within the Array/String. (which is set when the array is declared).

New

The new keyword in Java instantiates a class by allocating it a memory for the object while the reference points to the area (i.e., address) of memory where the object resides. All this happens at the runtime.

Void

The void keyword specifies that a method should not have a return value.

Reference Type

There are primitive and non-primitive datatypes. Reference types are non-primitive datatypes. In other words, a variable of class type is called a reference data type. It contains the address (or reference) of dynamically created objects. When you print a reference you'll receive an address, this address is where the object exists in memory (i.e., Heap).

What's the difference between a method and a function in Java?

There's a subtle difference between the two terms, a function has no association to a class whereas a method does, the difference is so subtle that developer often use them synonymously.

Compile Time Errors

These errors occur when we violate the rules present in a syntax. The compile-time error indicates something that we need to fix before compiling the code. A compiler can easily detect these errors. It is the reason why we call them compile-time errors.

Is the naming convention for a method

They are mixedCase, they often verbs because they represent functions performed or the result returned. Some examples include: size() getName() addPlayer()

Type Safety

Type safety means that the compiler will validate types while compiling, and throw an error if you try to assign the wrong type to a variable.

Else

Used in conditional statements.

Do

Used together with while to create a do-while loop.

Default Constructor

When the Java compiler doesn't detect a custom constructor, it automatically creates and resorts to the default constructor during the execution of the program. The default constructor is the pair of parenthesis at instantiation. An example is shown below: Example anExample = new Example ();

Break

When the control flow reaches the "break" keyword it terminates the execution, in other words, breaks out of the execution.

Method Overriding

When the method's signature are the same in the superclass and the child class, it's called __________________.

Method Overloading

When two or more methods in the same class have the same name but different parameters, it's called _______________.

Static

________________ means that the variable or method marked as such is available at the class level. In other words, you don't need to create an instance of the class to access it. When you declare a variable or a method as _____________, it belongs to the class, rather than a specific instance. This means that only one instance of a static member exists, even if you create multiple objects of the class, or if you don't create any.

Unboxing

______________________ is the automatic conversion that the Java compiler makes between the object wrapper classes and their corresponding primitive types

Class level scope (instance variables)

________________________ any variable declared within a class is accessible by all methods in that class. Depending on its access modifier (ie. public or private), it can sometimes be accessed outside the class.

Block scope (loop variables)

_________________________ any variable declared in a for loop condition is not accessible after the loop, unless you defined it beforehand.

Method level scope (local variables)

_________________________ any variable declared within a method, arguments included, is NOT accessible outside that method.

Exception Handling

_____________________________prevents the program from crashing if an error occurs. We don't want the program to unexpectedly crash on the user. Instead, error handling can be used to notify the user of why the error occurred and gracefully exit the process that caused it.

Autoboxing

is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes.

Code block

is used for grouping of two or more statements. The code in Java always starts with curly braces and ends with close curly braces


Kaugnay na mga set ng pag-aaral

Accounting for Long-Term Liabilities and Bonds Payable

View Set

PFIN 7 Chapter 7 Using Consumer Loans

View Set

revolutions and nationalism quiz 3/4

View Set

ACIS 2116 Managerial Accounting - Exam 2 Study Guide

View Set