NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

transient = field should not be serialized!

AccessModifier
default -> only package
protected -> package & subclasses

Non-AccesModifier
static - final - abstract vs
syncronized -> Same lock
volatile -> cache bagimsiz, main memoryde butun threadler ayni goruyor

Exception -> Checked + Unchecked
checked -> compiler checks so must be hanled with throws or try catch (Class not found , file not found)
unchecked -> Runtime Exceptions (Arithmetic, null pointer vs)

try-with resources -> try(FileReader f = new FileReader()) -> Autoclosable inteerfaceini implement etmeli filereader gibi. bu da resource i blocktan sonra kapatir!


Inner Class -> normalde class modifier private olamaz, so if we need private class that must be inner class. Security icin, ve ya private memberlara ulasmak icin class in icine inner baska bir class koyabiliriz.
Method Local Inner-> Methodun icine class orada instansiate et vs.
Anonymous Inner Class-> declare&instansiate at the same time, when you need to overrite interface method


Inheritance : one class acquires other class' properties
-> when child is created, copy of contents of parent is created within.
Ref variable can hold subclass
Par p = new Child(); // but you can access only parent methods

Covariant Return Type :
class Par{ class Child{ @Override
Par doMethod(){ Child doMethod(){ . sout("now it is a child method"); }}
sout("this is par method"); }}

Both methods have different return type but it is method overriding!!!!!


OVERRIDE: Static ve final olmayan methodlar override edilebilir.
- Arg list same
- return type same or covariant
- access level cannot be lower!!

VIRTUAL METHOD!
Animal ani = new Mammal();
ani.move();
COmpile time just knows reference type so if move() exists in Animal class it builds!
RunTime realizes the object type so it move() if Mammal class!

POLYMORPHISM
ABILITY OF OBJECT TAKE ON MANY FORMS
Ref type can only be one, it is the only way to access objects.
ref type determines methods that can invoke on object
can be interface or class;
Deer d = new Deer();
Animal a = d;
Vegetarian v = d;
d , a ,v ref variable that refer to same object in the heap.

ABSTRACTION:
- deal with ideas rather than events.
- hiding implementation details from user
- abstract class ve interface ile mumkun

Abstract Class : class with abstract keyword
- may or may not include abstract methods. if includes any, then class has to be abstract class.
- cannot be instansiated; to use, you have to extend it and give implementations to abstract methods.
- an abstract child do not give implementations to abstract methods

Encapsulation: fieldlar private you can manipulate and reach them by getter and setters
- It is a mechanism for wrapping data methods&variables acting as unit
- class can be made read/write only and have total control on fields.
- class fieldi degistirince butun kullananlar degistrmek zorunda kalmaz. ve kurallar koyabilirsin fieldlar icin set ve get icin.

Interface: Ref type, collection of abstract methods.
- now itmay contain constants , default methods, static methods
- implement eden class abstract olmadigi surece butun methodlar override edilmeli.
- cannot instansiate, onlyby anonymous inner class olarak instansiate (o da zaten class)
- no constuctors, instance fields.
- methods are implicitly public & abstract
- interface can extend multiple classes!!!

tagging interface : bos interface ama classlari ttagliyorsun, eventlistener gibi, for jvm to know !

INSTANCE INITILIAZER BLOCK: direk assigndan farkli olarak loop operations yapablirisin
this block is invoked within constuctor after super();
Multiple constructor da code repetirion yapmamak icin kullanabilirsin bu blocku!
- there are 3 places you can perform operations ( methods, constructors, blocks)


DATA STRUCTURES
COLLECTIONS
different type of objects to work in similar manner (interoperability)
- interface, implmentations, algorithms

Linkedlist -> get-> O(n/4) . add -> O(1)
ArrayList ->RANDOM READ ACCESS get -> O(1) add -> O(1) ama resize olurken O(n)
HASHSET -> hash table storage but just keys, and hased
set.add("mert");

Algorithms : list iterator: bi directional
comparator: compare i override et ve sort vs herseyi yapabilirsin

GENERICS: It would be nice if we create single sort method, that can sort integer string any array
-generics enable programmer to specify single method declaration
- Compile time type safety List<String> e integer ekleyemeyiz compile time da daha error verir.


Bound Type Parameter: when you wanna restrict
<E extends Number> gibi or wildcard <? extends Number>

GENERIC CLASSES: parametrized classes
class Box<T> { . Box<Integer> Box<String> yapabilirsin
this.list.add(t)}

SERIALIZATION: Methods for objecto be represented as bytes.
class must implement serializable. field serialize olmasin dersen TRANSIENT modifier kullanabilirsin..



MULTITHREADING: Since thread share a common memory area, multi process yerine daha kllanislive lightweightler, cost of communication is low

Thread Scheduler: JVM decides which thread should run
- preemptive: highest priority executes
- timescling: task executes pre defined time then re enter ready pool.

new ThreadMert().run() ---> no context switching so like regular method is called
to make it thread, you need to start();;

JOIN:
t1.start()
t1.join()
t2.start();
t3.start();
t1 in isinin bitmesi bekler t2 ve t3!!!!

DAEMON THREAD: Service Provider. when all the user thread dies, jvm terminates daemon automatically.
- it provides service to user threads.
- low priority. ve basladiktan sonra threadi setdeamon() yapamazsin. start() dan once yapmalisin.

JAVA THREAD POOL : Thread havuzu job icin bekleyen, by service provider a thread from pool is assigned to task then enter to pool again.
- better performance, no need to create new.
- used in servlet and jsp create a pool to process to request.

THREAD GROUP: way to group thread in single object. we can suspend resume interrupt group of threads by single method call!
ThreadGroup tg = new ();
Thread t1 = new Thread(tg, new MyRunnable(), "name");
Thread t2 = new Thread(tg, new MyRunnable(), "name2");


SHUTDOWN HOOK-> clean up rersource or save the state when jvm is down!!!!
- if you want to do before jvm finishes.
RunTime r = Runtime.getRuntime;
r.addShutDownHook(myRunnable)

CALL STACK:
Each thread run in a separate call stack.
is a LIFO data structure containing:
- the adress of which execution will resume
- Local variables
- parameters of each call

GARBAGE COLLECtion -> garbage = unreferenced object
destroy unused objects.
reclaiing the runtime unused memory automatically

How can object be unreferenced?:




















     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.