I read two books as follows:
- JAVA: A Beginner to Expert Guide to Learning the Basics of Java Programming
- https://www.amazon.co.jp/dp/4844330861 (Japanese)
This article shows some interested tips in these books.
π Hello World
Make hello.java
like as follows:
package forloops; |
After making, you can run the Java program.
$ javac hello.java |
π Features
- Encapsulation
- Polymorphism
- Inheritance
- Abstraction
πΌ PRIMARY FEATURES OF JAVA
- Simple
- Secure
- Portable
- Platform Independent
- Multi-threading
- Object Oriented
- Distributed
- Robust
πΈ Variable Type
- Integer Number
- log
- int
- short
- byte
- Decimal Number
- double
- float
- Boolean
- Char
- String
π½ Literal
- int : 30
- log : 3000000L
- double : 30.5
- float : 30.5F
- boolean : true
- char : βι β
- String : βJavaβ
π Method Overloading
Method overloading is the ability to create multiple methods of the same name
with different implementations.
class DisplayOverloading { |
π Method Signature
Method Signeture = (1) Method Name, (2) Argument Number, Type, Order
π³ Encapsulation
Access Modifiers for Member(Field, Method)
- Private : The member can be accessed within same class
- Package private : The member can be accessed within the same package
- Protected : The member can be accessed within same package or inherited class
- Public : The class can be accessed anywhere
Access Modifiers for Class
- Package private : The class can be accessed within the same package
- Public : The class can be accessed anywhere
π Inheritance
Constructor
Constructors use super to invoke the superclassβs constructor.
If a constructor uses super, it must use it in the first line;
otherwise, the compiler will complain. An example follows:
public class Parent { |
Is-a relationship
is-a
is a subsumption relationship between abstractions (e.g. types, classes),
where one class A is a subclass of another class B (and so B is a superclass of A).
Abstract Class / Method / Interface
- Abstract Method
- Abstract Class
- Interface = public abstract
π£ Java Standard API
Date
- You should use java.util.Date if you want to use Data information.
- Calendar class can convert Date instance by year, month, day, hour, minute, second.
- SimpleDateFormat class can convert Date instance to arranged String.
π€ Exception
π type
- Grammer Error
- Runtime Error
- Ligic Error
Fatal Error
- Fatal Error. It is impossible to recover from the error
- e.g. OutOfMemoryError, ClassFormatError
Exception(except RuntimeError)
- Child of java.lang.exception(except RuntimeError)
- You should plan how to recovery by the error in your code.
- e.g. IOException, ConnectException
RuntimeException
- You donβt have to consider a recovery plan by the error.
- e.g. NullPointerException, ArrayIndexOutOfBoundsException
Automatically run close() in try-catch
If a type has java.lang.AutoClosable interface, the API class automatically runs close()
in try-catch
sentence.
π Special Thanks
- Method Overloading in Java with examples
- Function overloading - Wikipedia, the free encyclopedia
- Understanding constructors - JavaWorld
π₯ Recommended VPS Service
VULTR provides high performance cloud compute environment for you.
Vultr has 15 data-centers strategically placed around the globe, you can use a VPS with 512 MB memory for just $ 2.5 / month ($ 0.004 / hour).
In addition, Vultr is up to 4 times faster than the competition, so please check it => Check Benchmark Results!!