Java
/
Basics
- 1 Basics 9
-
Classes
-
Objects
-
Arrays
-
Variables
-
Loops
-
Numbers
-
Strings
-
Exceptions
-
Regexp
- 2 OOP 9
-
Inheritance
-
Polymorphism
-
Static
-
Abstract
-
Interfaces
-
Constructors
-
Packages
-
Nested Classes
-
Final
- 3 Compiler 2
-
Sublime Text
-
Apache Ant
- 4 Collections 8
-
Lists
-
Comparable
-
Sets
-
Maps
-
Generics
-
Properties
-
Streams
-
Json
- 5 Threads 4
-
Create Thread
-
Sleep
-
Lock
-
Scheduler
- 6 Design patterns 4
-
Singleton
-
Observer
-
Strategy
-
Mediator
- 7 Swing 12
-
Frame
-
Panel
-
Listener
-
Combo Box
-
Label
-
Image
-
Menu
-
Table
-
Layout
-
Drawing
-
Timer
-
Designer
- 8 I/O 7
-
Streams IO
-
Socket
-
Watching Files
-
Mail
-
Logger
-
Clipboard
-
Encrypt
- 9 Effective 7
-
Constructors
-
Dependency Injection
-
Composition
-
Interfaces Default
-
Import Static
-
Enums
-
Lambdas
- 10 Junit 5
-
About Junit
-
Test Case
-
Suite Test
-
Annotations
-
Exceptions
- 11 Lambdas 7
-
Expressions
-
Functional Interfaces
-
Streams
-
Common Operations
-
Default Methods
-
Static Methods
-
Single Responsibility
- 12 JavaFX 6
-
Openjfx
-
Scene Builder
-
First App
-
Jar Archive
-
On Action
-
Change Listener
- 13 Maven 4
-
Demo
-
Spring Boot
-
Junit
-
Guava
- 14 Spring Boot 8
-
Quick start
-
Rest service
-
Consuming Rest
-
Templates
-
Security
-
Command Line
-
Scheduling Tasks
-
Ajax
/
Objects
➟
➟
Last update: 29-10-2021
Objects
p72 JVM allocates space for the reference variable.
/**
* To use an object you must declare a reference variable.
* JVM allocates space for the object.
*
* The reference variable is forever of type Dog!
* myDog = new Cat(); // will throw a type mismatch error
*/
package com.minte9.basics.objects;
public class Objects {
public static void main(String[] args) {
Dog myDog = new Dog();
myDog.size = 40;
myDog.bark();
}
}
class Dog {
int size;
String name;
void bark() {
System.out.println("Ham Ham"); // Ham Ham
}
}
class Cat {}
References
p77 A reference to an object can be overridden and the old reference is destroyed.
/**
* There are 3 reference variables and 2 objects
*
* After a overrites b, the b reference to object 2 is destroyed
* (eligible for Garbage Collection)
*/
package com.minte9.basics.objects;
public class References {
public static void main(String[] args) {
Book a = new Book("A");
Book b = new Book("B");
System.out.printf("%s %s \n", a, b); // A B
Book c = b; // refc / objB
System.out.printf("%s %s %s \n", a, b, c); // A B B
b = a; // refb / objA
System.out.printf("%s %s %s \n", a, b, c); // A A B
}
}
class Book {
String name;
public Book(String name) { // contructor
this.name = name;
}
public String toString() {
return name;
}
}
➥ Questions github Basics