|
Simple modeling
|
An accurate representation of the real world by grouping objects with their properties and actions
|
|
Robustness
|
Easy maintenance and bug detection. Strong typing which results in more robust code (predictable behavior of your code)
|
|
Scalability
|
Adding functionality comes down to establishing new connections with other objects and methods.
|
|
Reusability
|
Available features allowing code reusability. (inheritance)
|
|
Class
|
A blueprint of an object: its properties, behavior and how it interacts with the exterior world.
|
|
Attributes & methods
|
The attributes are the properties of an object while the methods represents its dynamic behavior inside of your program. These attributes and methods define how the object should be accessed, its internal behavior and how it interacts other objects
|
|
Objects
|
An instance of a class. (the class is the type definition and the object is the variable) => all instances of a class share the same fields but have distinct data inside.
In addition to its state (properties) and behavior (methods) an object has an identity which distincts it from other objects (alias/ memory address ...) |
|
Abstraction
|
The selection of only useful information about an object for a particular application.
|
|
Encapsulation
|
Is the ability to control the access to the object's properties and methods, render them either visible (public) or hidden (visible only to internal functions).
|
|
Polymorphisme
|
The definition of different executions of a methode for different inputs and for different objects
|
|
Heritage
|
A description of a general\specific relationship between classes. In shorts a subclass has all the properties/ actions of its super class + its own ones + its redefined ones
|
|
Composition, Agregation
|
The creation of a class/object as a collection of other objects
|
|
JAVA platform = JVM + API JAVA
|
|
JVM : execution environment for JAVA apps.
Allows code to be machine independant as it executes inside of a virtual machine which abstracts the specefics of input\output, hardware configuration, and different OSs. JVM has its own native language : byte code (juts like a real computer has its own instruction set) The JVM interprets byte code and manages memeory for the programs automatically by its Garbage collector |
|
JAVA API : libraries that abstracts diverse functionalities.
|
public class test{{{nl}} public static void main(String ar[]){{{nl}} // code{{nl}} }{{nl}}}
type [] name=new type[size] or type name[] = new type[size]array_name[i]=new type(constructor attributes)type array_name[]={val1,val2,val3};String s="sample text";
String s=new String("sample text")s.equals(s2);returns 1 is s=s2 and 0 otherwises3=s1.concat(s2); <=> s3=s1+s2; to concatenate strings|
INPUT
|
in the header of the class file :
import java.util.Scanner;in the method: Scanner sc = new Scanner(System.in);int i = sc.nextInt(); |
|
OUTPUT
|
for single variables:
System.out.println(single variable);for multiple variables: System.out.println(var1+" "+var2+...);the idea is to convert variables to strings and concatenate them |
**//The garbage collector deallocates memory of unreferenced objects**
//example
cl obj1=new cl();
System.gc();
**//the GC does nothing here since obj 1 is still referenced**
cl=null;
System.gc();
**//the GC deallocates the memory previously allocated for obj1 since it's no longer referenced{{nl}}//This makes the life of a programmer (for example when freeing an array of objects : a single command instead of a loop**
|
Static attributes are initialized as follows: ints, floats -> 0, bools -> false, references -> null
|
|
static methods have access only to static methods and attributes of a class (obviously).They can't have use the "this" reference since it doesn't make any sense.
|
Class_name.static_atrribute_nameClass_name.static_method_name() |
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.