JAVA
June 19, 2013
Alexandru Burghelea, aburghelea@rosedu.org
Overview
- What is Java
- "HELLO, World!"
- Programming styles
- Fitting in
- Instance vs Class
- Access control
- Clarifications
- Code
What is Java
"Java is a programming language and computing platform first released by Sun Microsystems in 1995. There are lots of applications and websites that will not work unless you have Java installed, and more are created every day. Java is fast, secure, realiable. From laptops to datacenters, game consoles to scientific supercomputers, cell phones to the Internet, Java is everywhere!"
by java.com
More about JAVA
- created by James Gosling
- currently develop by Oracle
- it is easy to use (ask any dummy)
- secure (the language , not the plugin)
- reliable (thanks to OOP)
- cross-platform (thanks to the JVM)
- great IDE support (Intellij IDEA, Netbeans, Eclipse)
- shares the JVM with other languages (Groovy)
First Program
Do not write code before you set up your environment
package osss;
/**
* @author aburghelea
* @since 6/8/13 - 12:41 PM
*/
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
LETS DO IT
Type it
and
Don't know how to run it eh?
I'll show you!
Programing Paradigms
-
Imperative
- Procedural
- Functional
- Object Oriented
Imperative
- the state is in global variables
- direct assignment
- list of commands to be executed in order
- the philosophy is : "Apply rules in this order"
- Ex:
- C
- C++
- JAVA
- Python
ProcedURAL
- derived from structured programming (style of imperative programmign)
- local variables
- goto statements (not really)
- modularization
- Ex:
- C
- C++
- Lisp
- NOT Java (why do you thing that).
OBJECT ORIENTED
- Objects
- Methods
- Global variable ???
- Message passing
- Data abstraction
- Inheritance
- Etc
- Ex:
- C++
- C#
- JAVA
Functional
- NO state
- NO mutable data
- Lambda caculus
- Threats computation as the evaluation of mathematical functions
- Ex:
- Haskell
- Groovy
- Scala
I thank Groovy, Radu thanks Scala.
Fitting in
Java is object-oriented. What does that mean? Unlike languages, such as FORTRAN, which focus on giving the computer imperative "Do this/Do that" commands, object-oriented languages focus on data. Of course, object-oriented programs still tell the computer what to do. They start, however, by organizing the data, and the commands come later.
by dummies.com
ReaLLY FITTING IN
- It has classes (remember Hello, World ?)
- Everything is a Object
- Objects communicate by sending messages
-
Inheritance at it's best
- Works with abstraction
- Knows polymorphism
- Does encapsulation
Rememer the last four, they are the major principles of OOP
Class vs Instance
- There is no JAVA program where code exists outside of:
class Name { }
- A class is a blueprint for an instance.
-
class = blueprint for a house
- instance = specific house
- The class is "the code"
- The instance is the runtime representation of a class
Everything is an object
- State
- Behavior
Inheritance
- Reuse exiting code
- Super class (parent)
- Sub class (child)
- Keywords: "this", "super"
Abstraction
- Expose an interface
- Hide implementation
- Ex: A you want to use a list. You want to add, remove, iterate elements. Is it really important how the list is implemented?
Things you can't really explain in slides
- this
- super
- constructor
- static vs instance
Polymorphism
- Poly = many:
- polygon = many-sided, polystyrene = many styrenes (a), polyglot = many languages, and so on.
- Morph = change or form:
- morphology = study of biological form, Morpheus = the Greek god of dreams able to take any form.
Polymorphism in Java
- Behave in different ways based on the context
-
Reuse existing code
- Method overloading
- Method overriding
- NO operator overloading
Encapsulation
- Bundle data and methods together (as long as they are related)
- Do (for the love of God) alter the state (variables/properties) directly from the outside.
Access control
Visibility for each access level
- public: class, package, subclass, world
- protected: class, package, subclass
- no modifier: class, package
- private: class
LET'S TRY IT
JAVA
By iceman
JAVA
Java presentation for Rosedu Open Source Summer School
- 1,608