[Go to site: main page, start]

0% found this document useful (0 votes)
27 views6 pages

Java Development Kit and Key Concepts

The document provides information on various Java concepts: - Arrays can store multiple values in a single variable. Common array types include String arrays and integer arrays. - Methods allow reusable blocks of code to be defined. Parameters pass data into methods and a return type returns a value. - Inheritance allows subclasses to inherit attributes and methods from parent classes, while polymorphism allows subclasses to perform tasks in different ways. - Collections provide data structures to store and manipulate groups of objects, with common examples being ArrayList, LinkedList, HashSet, and HashMap.

Uploaded by

Lazar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views6 pages

Java Development Kit and Key Concepts

The document provides information on various Java concepts: - Arrays can store multiple values in a single variable. Common array types include String arrays and integer arrays. - Methods allow reusable blocks of code to be defined. Parameters pass data into methods and a return type returns a value. - Inheritance allows subclasses to inherit attributes and methods from parent classes, while polymorphism allows subclasses to perform tasks in different ways. - Collections provide data structures to store and manipulate groups of objects, with common examples being ArrayList, LinkedList, HashSet, and HashMap.

Uploaded by

Lazar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

JDK - Java Development Kit (developer)

JVM - Java Virtual Machine platform component that execute programs (interpreter, end user)
JRE - Java RunTime Environment Is on disk part java that creates the JVM

JRE is part of JDK because the java development process requires JRE because
running java programs is part of the development process.

————Arrays—————

Arrays are used to store multiple values in a single variable, instead of declaring
separate variables for each value.

String[] Cars = {“Volvo”, ”BMW”, “Ford”, “Mazda”}; Array of strings

int[] myNum = {10, 20, 30, 40};

Length property to find out how many elements an array has

————ForEach in Java————

for(String i : cars) {
[Link](i);
}

Method is a block of code which only runs when it is called. You can pass data known
as parameters into a method.

Methods are also known as functions.

Information can be passed to methods as parameters. Parameters act as variables


inside the method.

Void indicates that method doesn’t return anything.

If You want a method to return value you need to set a primitive data type instead of
void.

————Overload and Override————


Overloading occurs when two or more methods in one class have the same name but
different parameters.

Overriding means having two methods with same name and parameters. One of the
methods is in parent class and the other is in the child class.

Overriding allows a child class to provide specific implementation of method that is


already exist in parent class.

Polymorphism applies to overriding not to overloading.

Classes and Object are main aspects of object-oriented programming.

Classes is a template for objects, and an object is an instance of class.

When individual object are created they inherit all the variables and methods from class.

Static method can be accessed without creating an object of class.

————Contructors in Java————

Contructors are used to initialize object when object is created.

Access modifier —> Meaning that it is used to set access level for classes, attributes,
methods and contractors.

Public accessible for all classes


Private code is only accessible within the declared class
Protected The code is accessible in the same package and subclasses.

Encapsulaton is to make sure that sensitive data is hidden from users. TO achieve this
you must:

Declare Class Variables/Attributes as Private


Provide public get and set methods to accesss and update the value of private variable.
Private variables inside class can be access if we provide get and set methods.
Get method returns variable value and set method sets the value.

Encapsulation, better control of class attributes and methods. Class attributes can be
made read only if only use get method or write only if we use set method. Increased
security of data.

Packages is used to group related classes.

————Inaritance————

In Java it is possible to inherit attributes and methods from one class to another.

subclass(child) - the class that inherits from another class


superlass(parent) - the class being inherited from

If you don’t want other classes to inherit from a class, use the final keyword.

———Polimorfizam———

Means many forms, and it accurs when we have many classes nah are related to each
other by inheritance.
Inheritance lets us inherit attributes and methods from another class. Polymorphism
uses those methods to perform different tasks.

Inner classes

That means that is possible to nested classes. The purpose of nested classes is to
group classes that belong together, which makes code more readable.

Abstract classes and methods

Data abstraction is the process of hiding certain details and showing only essential
information to the user.
Abstraction can be achieved with either abstract classes or interfaces.
Abstract class is a restricted class that cannot be used to create objects to access it you
must inherited from another class.

Abstract method can only be used in an abstract class and it does not have a body. The
body is provided by subclasses.

————Interface — — — —

Is another way to achieve abstraction in Java.

An interface is completely abstract class.

To access the interface methods the interface must be implemented by another class
with implements keyword.

Interface cannot contain contructor

Class can only inherit from one superclass, but you can implement more than one
interface.

—————Enums—————

Is a Special class that represents a group of constraints.

———————Collections in Java ————————

The collection in Java is a framework that provides an architecture to store and


manipulate the group of objects.

Java collections can achieve all the operation that you perform on data such as
searching, sorting, insertion, manipulation and deletion.

ArrayList, LinkedList, HashSet, LinkedHashSet, TreeSet

———ArrayList———

List<data-type> list1 = new ArrayList();


ArrayList can store the ordered collection of objects. It can have duplicated values. It
use dynamic array to store the duplicate element of different data types.

add() -> add method

Iterator itr = [Link]();

while([Link]()) {
[Link]([Link]());
}

———LinkedList————

It uses a doubly linked list internally to store the elements. It can store duplicate
elements, it maintains the insertion order. Manipulation is fast because no shifting is
required.

LinkedList<String> al = new LinkedList<String>();


[Link](“SomeText”);
[Link](“SomeText1”);
[Link](“SomeText2”);

Iterator<String> itr - [Link]();

whilde([Link]()) {
[Link]([Link]());
}

——————SET Interface—————

It represents the unordered set of elements which doesn’t allow us to store duplicate
items. We can store at most one null value in Set. Set is implemented by HasSet,
LinkedHashSet and TreeSet.

HashSet represents the collection that uses a hash table for storage. It contains a
unique items.
LinkedHashSet it extends the HashSet class and implements Set interface. It also
contains unique elements, but it maintains the insertion order and permits null elements.

TreeSet also contains unique elements. However the access and retrieval time of
TreeSet is quite fast. The elements of TreeSet stored in ascending order.

———————HashMap———————

HashMap contains values based on key, only unique keys, may have one null key and
multiple null values, maintains no order.

Differences between HashSet and HashMap is that HashSet contains only values.

Common questions

Powered by AI

Collections in Java handle data manipulation and storage by offering various data structures to manage objects. For instance, ArrayList uses a dynamic array to store ordered collections and can include duplicates, while LinkedList utilizes a doubly linked list to maintain insertion order efficiently without the need for data shifting during manipulation. HashMap stores values based on unique keys with possible null values, not maintaining any order. HashSet, which uses a hash table, emphasizes unique values without duplicates, whereas TreeSet orders its elements in ascending order, providing faster access and retrieval times .

The List interface in Java, exemplified by ArrayList and LinkedList, allows for ordered collections with duplicate elements, preserving insertion order, making them suitable for ordered data or when duplicates are necessary. In contrast, the Set interface, implemented by classes like HashSet and TreeSet, prohibits duplicates, focusing on unique item storage. HashSet doesn't maintain order, whereas TreeSet orders its elements, ideal for unique collections needing quick retrieval based on order .

Overloading occurs when multiple methods in a class have the same name but different parameters, allowing for different implementations. Overriding, on the other hand, involves a subclass providing a specific implementation for a method that is already defined in its parent class, with the same name and parameters. Polymorphism applies only to method overriding, allowing objects to be processed based on their actual subclass rather than their superclass reference, hence proving useful in multiple inheritance scenarios .

The final keyword in Java enforces constraints by preventing inheritance and value re-assignment, thereby promoting immutability and security. When applied to a class, final prevents it from being subclassed, thereby enforcing a firm class hierarchy. For methods, it ensures that a method cannot be overridden in a subclass, preserving method behavior. When used with variables, final ensures that the variable's value cannot change once initialized, promoting data consistency .

Access modifiers in Java such as public, private, and protected enhance encapsulation by controlling access levels of classes, attributes, and methods. Public allows access from any class, promoting broader interaction, while private restricts access within the defining class, supporting encapsulation by hiding data. Protected, accessible within the same package and subclasses, balances openness and restricted access, fitting intra-package and inheritance scenarios .

Inheritance in Java is implemented by allowing a class (subclass) to inherit fields and methods from another class (superclass), thereby enabling hierarchical class structures. This relationship establishes a class hierarchy where subclasses extend superclasses, inheriting their accessible methods and attributes, fostering code reuse and polymorphic behavior. The 'final' keyword can be used to prevent a class from being inherited, maintaining control over the hierarchy .

Nested classes in Java provide the advantage of grouping classes that are logically related, enhancing code organization and readability. They should be used when such a logical grouping is necessary, particularly when one class needs to closely associate with another to encapsulate its behavior more distinctly. This encapsulation can help maintain a clear structure and improve information hiding .

The Java Development Kit (JDK) integrates with the Java RunTime Environment (JRE) by containing it as a component part. The JRE provides the necessary libraries and environment for the JVM to execute Java programs. The JVM, as part of the JRE, is the platform component that interprets Java bytecode. Thus, the JDK, intended for development, requires the JRE to run Java programs that are part of the development process .

Abstract classes and interfaces both achieve abstraction but serve different roles. An abstract class can provide both complete and incomplete methods (with or without implementations), allowing subclasses to inherit and potentially override. In contrast, an interface is entirely abstract, meaning it provides no method implementations; instead, it allows different classes to implement multiple behaviors or capabilities. Unlike abstract classes, a class can implement multiple interfaces, thus offering more flexibility in terms of multiple inheritance .

Encapsulation in Java is significant because it hides sensitive data from the user by restricting access to certain components of an object and thus enhancing data security. This is achieved by declaring class variables as private and using public getter and setter methods to access and update these private variables. By controlling how and what data is accessed, encapsulation provides better control over the class attributes and can also make class attributes read-only or write-only, increasing data security .

You might also like