Java Basic PART 1
why should you learn java
Java is easy to learn
java is object oriented
java has rich API
powerful developement tools
GREAT COLLECTION OF OPEN SOURCE LIBRARIES
Wonderful community support
Java is FREE
Excellent documentation support - Javadocs
Java is Platform Independent
write once run anywhere
Java is Everywhere
Desktop, mobile, card, and so Java programmers,
organizations
Introduction
Developed By : James Gosling
Owner : Sun Microsystems
Released in : 1995
Stable Release : Java Standard Edition 7 (1.7.0)
OS : Cross Platform (Multi Platform)
Extensions : .java, .class, .jar
JAVA Platform
JAVA Platform It is Platform Independent. It compiles Java language code in Java bytecode , not in Machine code. A major benefit of using bytecode is porting.
Virtual machine
ByteCode
Automatic Memory Management
JAVA Syntax
Commenting Methods
//
/* */
/**
*@author yuri...
*/
A Simple JAVA Program
class Hello { public static void main(String args []) { System.out.println (“Hello"+ "World”);
} }
Some abbreviations
JDK : JAVA Development Kit
JVM : JAVA Virtual Machine
JRE : JAVA Runtime Environment
javac : JAVA Compiler
JVM : JAVA Virtual Machine
KVM : Kilobyte Virtual Machine
CVM : Card Virtual Machine
DVM : Delwik Virtual Machine
Points to be remembered
Java programs need to be compiled only once.
When a class is defined as public, class name and file name must be same.
”;” can be put anywhere before a new statement.
Java does not support operator overloading.
Operator “+” is by default overloaded in JAVA.
Objectives
ClassObjects
Identifiers
Methods
Encapsulation
inheritance
polymorphism
Constructors
Class
Template,
State and behaviour of object at run time, Abstract class ,Final class
Interface
A 100% abstract class,
A contact for what a implementing class can do.
Behavioural purposes
Class can implement multiple interfaces
Variables
Primitives, Reference, Local variables Arrays, Final variables ,Transient
Methods
static
abstract
final
Encapsulation
Keep data protected
Keep services open
Setters and getters method
Inheritance
Re-usability
Sometimes we have no implementation
Is-a vs has-a relationship
Polymorphism
Overloading
Overridding
Constructors
Need?
Default constructor
Constructor overloading
Constructor calls in inheritance tree
operators
postfix expr++ expr--
unary ++expr --expr +expr -expr ~ !
multiplicative * / %
additive + -
equality == !=
relational < > <= >= instanceof
More operators
shift << >> >>>
bitwise AND &
bitwise exclusive OR ^
bitwise inclusive OR |
logical AND &&
logical OR ||
ternary ? :
assignment = += -= *= /= %= &= ^= |= <<= >>= >>>=
.equals()
VS
==
exemple
String user1 = "YuriLz";
String user2 = "YuriLz";
String user3 = "Yuritta";
String user4 = new
String("YuriLz");
String user5 = new String();
String user6 = new String();
user5 = "YuriLz";
user6 += "YuriLz";
OUTSTREAM
System.out.println( (user1==user2)? "Equal" : "Not Equal" );
System.out.println( (user3==user2)? "Equal" : "Not Equal" );
System.out.println( (user1==user2)? "Equal" : "Not Equal" );
System.out.println( (user4==user2)? "Equal" : "Not Equal" );
System.out.println( (user5==user2)? "Equal" : "Not Equal" );
System.out.println( (user5==user6)? "Equal" : "Not Equal" );
System.out.println( (user5.equals(user2))? "Equal" : "Not Equal" );
System.out.println( (user5.equals(user3))? "Equal" : "Not Equal" );
(user1==user2)? "Equal" : "Not Equal" );
(user3==user2)? "Equal" : "Not Equal" );
(user4==user2)? "Equal" : "Not Equal" );
(user5==user2)? "Equal" : "Not Equal" );
(user5==user6)? "Equal" : "Not Equal" );
(user5.equals(user2))? "Equal"
: "Not Equal" );
(user5.equals(user3))? "Equal"
: "Not Equal" );
OUPUT
~$ javac StringsExemple.java
~$ java StringsExemple
Equal Not Equal Not Equal Equal Not Equal Equal Not Equal
THANKS!
JAVA BASIC
By Yuri Laaziz
JAVA BASIC
JAVA BASIC I, last update mai 2014
- 1,112