0% found this document useful (0 votes)
58 views

Java

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
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Java

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
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

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) {
System.out.println(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 = list.iterator();

while(its.hasNext()) {
System.out.println(itr.next());
}

———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>();


al.add(“SomeText”);
al.add(“SomeText1”);
al.add(“SomeText2”);

Iterator<String> itr - al.iterator();

whilde(itr.hasNext()) {
System.out.println(itr.next());
}

——————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.

You might also like