You are on page 1of 12

A computer program (also a software program, or just a program) is a sequence of instructions written to perform a specified task for a computer.

System (from Latin systma, in turn from Greek systma, "whole compounded of several parts or members, system", literary "composition"[1]) : is a set of interacting or interdependent components forming an integrated whole. Is a logic or interdependent logic which can exist as unique, independent from other elements A system is a set of elements and relationships which are different from relationships of the set or its elements to other elements or sets. Subsystem: A subsystem is a set of elements, which is a system itself, and a component of a larger system. Class is a construct that is used as a blueprint to create instances of itself referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable these class instances to have state and behavior Construct : an image, idea, or theory, especially a complex one formed from a number of simpler elements. a complex idea resulting from a synthesis of simpler ideas Access Specifiers define the restriction level for visibility of a class/method/variable. (public, private, protected) Access Modifiers define the behavior of a class/method/variable. They modify the way a class/method/variable can be used. (final, static, transient, volatile, synchronized etc.,) An entity is something that has a distinct, separate existence, although it need not be a material existence An identifier is a unique expression that identifies an entity. identifiers are tokens (also called symbols) which name language entities In Java identifier is simply a name given to a package, class, interface, method, variable etc Keywords: a keyword is a reserved word which identifies a syntactic form Keyword type Primitive types : A primitive type is predefined by the Java language Keywords Boolean Type boolean integer Type byte, short , int, long Character type Char

Floating Type double, float Access modifiers Java allows you to control access to classes, methods, and fields via access specifiers to achieve encapsulation Special modifiers Control flow OOP specific public, private, protected, default (no specifier)

abstract, final, native, static, strictfp, synchronized, transient, volatile if, else, do, while, switch, case, default, for, break, continue class, extends, implements, import, instanceof, interface, new, package, super, this catch, finally, try, throw, throws return, void const, goto

Exception handling Method specific Unused *

const and goto are not used in Java however they are reserved as keywords.

true and false are Boolean Literals; null is a reference Literal, an instance of a name-less class used as definition of nothing. They cannot be used as identifiers.

Tips

an empty source file will compile without error if a .java file does not contain a public class or interface it can have any name a single-type import will take precedence over an import-on-demand import-on-demand types do not increase the size of the compiled code ie only the types actually used are added to the code while import-on-demand adds no overhead to the compiled code, they can slow down the speed of the compile a constructor body can include a return statement providing no value is returned any method can throw a Runtime or Error exception without declaring it in the throws clause methods having the same name and parameter types do not have the same signature unless the parameter types are listed in the same order main() can be declared final main() is inherited and can be overridden if not declared as final args[0] references first command line argument after the application name ( arrays in Java are zero-based) main() can be declared public static void ... or static public void ... the variable name does not have to be args; can be anything as long as the type is String[] variables can have the same name as a method or a class only field variables are automatically initialized to their types default value; local variables must be explicitly initialized arrays are initialized to the default value of their type when they are created, not declared, even if they are local variables array index operator [] has highest level of precedence integer variables can be used as array dimension values postfix/prefix operators have the highest level of precedence

remember that when the postfix operator is used in an expression, the current value of the variable is used a class may be assigned to an Interface type if the class implements the interface or one of it's sub-interfaces you cannot cast a primitive type to an object reference, or vice versa you cannot cast a boolean type to another primitive type String operations whose result does not alter the original string (ie calling toUpperCase() on a String that is already in uppercase) return the original string reference; otherwise they return a reference to a new String Strings are immutable; the original String value can never be changed all the primitive type wrapper classes override the Object.equals() method to compare the value of the objects; the default Object.equals() method checks if the variables reference the same object you do not have to have a default statement in a switch() block the default statement in a switch() blcok can appear anywhere in the construct, does not have to be last all sections of the for() loop are optional finalize() can only be executed once on any object

Traps

code with package or import declarations given in wrong order more than one package declaration file with more than one public class or interface declaration filename.java does not match name of public class declared in the file single-type imports for two classes in different packages but with the same simple name single-type import with the same simple name as a class defined in the source file attempting to import a package vs a type ie import java.util vs import java.util.* class attempting to extend more than one other class

class declared both final and abstract an interface method declared as native or synchronized an interface method declared as static subclass with default constructor when the superclass does not have a no-args constructor or it's no-arg constructor has a throws clause constructor declared with a return type an abstract method also declared private, native, final, synchronized, or strictfp an abstract method declared in a non-abstract class a native or abstract method with a method body method returning a type which is not convertible to the declared return type a void method returning a value a static method referencing this or super main() declared other than according to the standard convention local (automatic) variables declared with a modifier other than final identifiers names beginning with a number or # sign main listed as a possible keyword capitalized words listed as possible keywords; particularly wrapper classes Integer, Boolean, etc C/C++ keywords listed as possible Java keywords an empty string vs null as the default value for a String object incorrect array declaration statements, particularly: arrayType [#] varName; incorrect array initialization statements, particularly: arrayType[] varName = new arrayType[2]; varName = { value, value, value }; negative values for array index long value for array index array declaration used as an array creation statement

variables of primitive type handled as Objects using the char literals \u000A or \u000D in comments or Strings String literal "c" assigned to char type using == operator to compare values of two different string reference variables variables requiring narrowing conversion being passed to methods without using a cast assigning a typed byte or short variable to a char variable floating point operation throwing an ArithmeticException Bitwise operator precdence is: & ^ | assigning subclasses with the same parent to each other assigning a parent class to a subclass without a cast result of an integer operation on byte or short types being assigned to a byte or short without an explicit cast a non-boolean value used for operand1 in a ternary expression using == to compare the contents of two different String objects using a new value based on a short-circuit operation that was never evaluated code that results in a primitive value being changed in a method (can't happen) code that results in an unchanged object value when it was changed in a method failing to cast a value to match a method parameter type ie assuming narrowing conversion on a method call a non-boolean value used in a loop or if( ) statement using the assignment operator '=' vs '==' in an loop or if() statement using an expression vs a value promotable to int in a switch() block switch() blocks with duplicate case values switch() blocks with incorrectly 'typed' case statements

switch() blocks with missing break statements (unintentionally causing code to fall through to next case) attempting to access a variable declared in the initialization outside of the forloop for()loop with incorrect initialization expression for()loop with a non-boolean expression a question that targets a specific object for garbage collection (can't be done) a question that presumes to force the gc to run (can only suggest it run)

Object-oriented programming (OOP) is a programming paradigm (fundamental style of computer programming) using "objects" data structures consisting of data fields and methods together with their interactions to design applications and computer programs. Paradigm Core, Fundamental distinct concepts. One that serves as Fundamental model

Structured

o o

Modular Object-oriented

By separation of concerns:

Aspect-oriented Role-oriented Subject-oriented

Class-based Prototype-based

Recursive

A class is a construct(complex entity formed by finite number of simple entities) that is used as a blueprint to create instances of itself referred to as class instances, class objects, instance objects or simply objects. Is a blue print used to create objects Is a software template that defines the methods and data to be included in a particular kind of Object Contains state and behavior

Class Diagram is pictorial representation of a class. It is a part of UML diagram. An object is a self-contained entity that contains attributes (data) and behaviors (methods) State is achieved by attributes, behavior achieved by operations Abstraction: is a process of exposing the relevant attributes and behavior of a system and hiding the rest so as to reduce the complexity of working with a system. The process of exposing the relevant details and hiding the irrelevant details is called Abstraction. A simplified description or specification of a system that emphasizes some of systems details or properties while suppressing others

Focuses upon essential characteristics of an object, relative to the perspective of an user Achieved by using access specifiers Access Modifiers - private, protected, public and default

Non-access Modifiers - final, abstract, transient, synchronized, native, strictfp and static

Every member you declare has an access control, whether you explicity type one or not. Members accessed with using the dot operator (.) must belong to the same class, the this keyword is used to reference the currently executing object. Member Access Modifiers When the member is declared protected it means that only the following can access the member

class that declared the member any subclasses any class thats in the same package can access it any class

Public Access

When the member is declared protected it means that only the following can access the member Protected Access

class that declared the member any subclasses any class thats in the same package can access it

When the member has no modifier it has default access only the following can access the member Default Access

class that declared the member any subclasses

When the member is declared protected it means that only the following can access the member. Methods that are declared private are implicity Private Access final.

class that declared the member

Member non-Access Modifers Final Abstract When used this means that the member (method or variable) cannot be overridden. A variable in a interface is implicity marked as final. An abstract method is a method that has been declared but not

implemented, in other words the method contains no functional code. The abstract method must be implemented in either the sub-class or any other subclass that has extend it. Transient This modifier can only be applied to variables, you are telling JVM to skip this variable when you attempt to serialize the object declaring it. When used this means that the method can be accessed by only one thread at a time. It can only be applied to methods. Indicates that a method is implemented in a platform-dependent language such as C. Indicates that strict floating-point will be adhered too. The best way i can describe a static variable or method is that one copy of the static member is contained in memory that allows all instances to access this copy, an example of this is like having a single counter variable that all classes can update. There is a rule that states that a static method of a class can't access a nonstatic member or variable of its own class. Static methods are also declared final implicity. You can Make Static: Methods, Variables and Top-Level nested Classes You cannot make static: Constructors, Classes, Interfaces, Inner Classes, Inner Class Methods/Variables, Local variables There is also no this reference when using static, also all static variables and methods are loaded first in order of appearance, you may find a simple static block of code to initialize variables or execute code. Quick lookup table to show the access to members permitted by each modifier
Modifier public protected no modifier (default) private Class Y Y Y Y Package Y Y Y N Subclass Y Y N N World Y N N N

Synchronized

Native Strictfp

Static

Abstraction, information hiding, and encapsulation are very different, but highlyrelated, concepts.

Encapsulation: is the process of compartmentalizing or encapsulating the elements of an abstraction that constitute its structure and behavior. Encapsulation serves to separate the contractual interface of an abstraction and its implementation. Abstraction focuses on observable external behavior of an object whereas encapsulation focuses upon implementation that gives rise to this behavior. Encapsulation is achieved through information hiding. Information hiding: is the process of hiding all the attributes and behavior of an object that do not contribute to essential characteristics. Structure of object and implementation of its methods are hidden In other words: abstraction = the object externally; encapsulation (achieved through information hiding) = the object internally Polymorphism: is the characteristic of being able to assign a different meaning or usage to an entity in different contexts - specifically, to allow an entity such as a variable, a function, or an object to have more than one form. There are several different kinds of polymorphism. Polymorphism means one entity with multiple forms Function overloading, overriding, operator overloading(C++) Inheritance: it is a process which enables reuse of attributes and behavior of an entity by inheriting. Inheritance enables programmers to define an "is-a" relationship between a class and a more specialized version of that class.

JAVAs Architecture

the program in source files written in the Java programming language, compile the source to Java class files, and run the class files on a Java virtual machine. by accessing system resources by calling methods in the classes that implement the Java Application Programming Interface, or Java API. The Java virtual machine is an abstract computer. A Java virtual machine's main job is to load class files and execute the bytecodes they contain. the Java virtual machine contains a class loader, which loads class files from both the program and the Java API. The bytecodes are executed in an execution engine.

You might also like