Friday, June 9, 2017

Java CheatSheet

- class name same as filename.java
- To instantiate: classname myclass = new classname ();
- Constructor method has same name as class name.
- to call a class method within main(): instancename.method(parameters)
- Methods can be overloaded by giving same name and different set of parameters.
- 'main' can instantiate a class, as long as the compiled class is in the same directory.
- static method can be called without instantiating the class.
- Local variables: local to a method. Should be initialized.
- Instance Variables: declared at instance-level. Have default values. Visible to ALL methods in the class.
- Loops: while, for, do-while. break and continue. break: goes out of loop. continue: skips rest of the statements, and starts
next iteration.
- or ||, and &&
- Inheritance: one class (subclass) extends other class (super class). Means subclass inherits methods and variables of the
superclass
- Overriding: subclass overrides the superclass's method.
- Polymorphism:
Method overloading: compile-time polymorphism
Method overriding: runtime polymorphism

No comments:

Post a Comment

Unix/Linux Cheat Sheet

To compare files recursively, between 2 directories on Linux dir1=/home/...../dir1 dir2=/home/...../dir2 diff --brief --recursive -...