Java Core. Introduction презентация

Содержание

Слайд 2

Agenda

History
Feature of Java
JAVA Platform
Primitive vs Reference
Garbage Collection
Steps to create a Java application
Code convention
Javadoc

Слайд 3

History

James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project

in June 1991. The small team of sun engineers called Green Team.
Originally designed for small, embedded systems in electronic appliances like set-top boxes.
Firstly, it was called "Greentalk" by James Gosling, and file extension was .gt.
After that, it was called Oak and was developed as a part of the Green project.
In 1995, Oak was renamed as "Java" because it was already a trademark by Oak Technologies. Java is an island of Indonesia where first coffee was produced (called java coffee).

James Gosling (born May 19, 1955) is a Canadian computer scientist, best known as the founder and lead designer behind the Java programming language.

Слайд 4

History

Слайд 5

Feature of Java

April 2009

Слайд 6

Feature of Java

Object Oriented − In Java, everything is an Object. Java can

be easily extended since it is based on the Object model.
Platform Independent − Unlike many other programming languages including C and C++, when Java is compiled, it is not compiled into platform specific machine, rather into platform independent byte code. This byte code is distributed over the web and interpreted by the Virtual Machine (JVM) on whichever platform it is being run on.

Слайд 7

Feature of Java

Secure
Java program always runs in Java runtime environment with almost

null interaction with system OS, hence it is more secure.
Classloader adds security by separating the package for the classes of the local file system from those that are imported from network sources.
Bytecode Verifier checks the code fragments for illegal code that can violate access right to objects.
Security Manager determines what resources a class can access such as reading and writing to the local disk.

Слайд 8

Feature of Java

High-performance
Java uses Just-In-Time compilers.
Garbage collector, collect the unused memory space

and improve the performance of the application.
It has no pointers so that using this language we can develop an application very easily.
It support multithreading, because of this time consuming process can be reduced to executing the program.
Dynamic − Java is considered to be more dynamic than C or C++ since it is designed to adapt to an evolving environment. Java programs can carry extensive amount of run-time information that can be used to verify and resolve accesses to objects on run-time.
Distributed − Java is designed for the distributed environment of the internet.
Robust − One of the major advantages of Java over C++ is that it prevents memory leaks. Java manages memory on its own and does garbage collection automatically. Bad memory management in C++ is a big source of errors in programs.

Слайд 9

Feature of Java

Слайд 10

JAVA Platform

jar, war

java, javaw

JDK − Java Development Kit
JRE − Java Run-time Environment


javac − Java Compiler
javap − Java Class File Disassembler
java − java (console) application executor
javaw − java (windowed) application executor

JVM − Java Virtual Machine
JIT − Just In Time Compiler

jar − Java ARchive
war − Web application ARchive

Слайд 11

Java Virtual Machine

JVM

Class Loader

Execution Engine

Native Method Libraries

Native Method Interface

Слайд 12

JVM

JVM Classloader Hierarchy

Слайд 13

Stack and Heap

Stack − This memory is used for execution of a thread.

Stack memory only contains local primitive variables and reference variables. Stack memory is very fast but less in size compare to heap.
Heap − Whenever we create any object, it’s always created in the Heap and reference variable of object in the stack. Any object created in the heap has global access and can be referenced from anywhere of the application.
Instance variables and objects live on the heap.
Local variables live on the stack.

Слайд 14

Primitive vs Reference

class Person { private String c;
public Person() { } public

Person(String s) { c = s; } public void change(String s) { c = s; } }

Слайд 15

Primitive vs Reference

public class Start { public static void main(String args[]) { int

a = 3; int b = a; b = 25; String str1 = "Hello"; String str2 = "Hello"; String str3 = new String("Hello"); String str4 = str3; str4 = "bye-bye"; int[] array = {1, 2, 3}; c[1] = 11; Person person1 = new Person("1"); Person person2 = new Person("2"); Person person3 = person1; Person person4 = person2; person4.change(“2-b"); } }

Stack

Heap

String Pool

"Hello"

"Hello"

"bye-bye"

Instance
"1"

Instance
“2-b"

Слайд 16

Heap

Primitive vs Reference

Stack

String Pool

Instance
"1"

Instance
"2"

public static void main(String args[]) { int a = 3;

Person person1 = new Person("1");
Person person2 = new Person("2");
funcFoo(a, person1, person2); } public static void funcFoo(int value,
Person personA, Person personB) {
}

When a primitive is passed into a method, only a copy of the primitive is passed. The called method does not have access to the original primitive value and therefore cannot change it. The called method can change the copied value.
When an object is passed into a method, the called method can change the contents of the object passed to it but not the address of the object.

Слайд 17

Heap

Primitive vs Reference

Stack

String Pool

Instance
"A"

Instance
"2"

public static void main(String args[]) { int a = 3;

Person person1 = new Person("1");
Person person2 = new Person("2");
funcFoo(a, person1, person2); } public static void funcFoo(int value,
Person personA, Person personB) {
value = 45; personA.change("A");
Person personB = new Person("B"); }

Instance
"B"

Слайд 18

Garbage Collection

Garbage Collector is the program running in the background that looks into

all the objects in the memory and find out objects that are not referenced by any part of the program.
All these unreferenced objects are deleted and space is reclaimed for allocation to other objects.

GC works in two simple steps:
Mark – it is where the garbage collector identifies which pieces of memory are in use and which are not.
Sweep – this step removes objects identified during the «mark» phase.

Слайд 19

Garbage Collection

Ways to make an object eligible for GC:
Nullifying the reference variable
Re-assigning the

reference variable
Object created inside method
Island of Isolation

Слайд 20

Garbage Collection

Garbage Collector Strategies:
Serial Garbage Collector- S GC
Parallel Garbage Collector- P GC (default

in Java 7, 8)
CMS Garbage Collector- CMS GC
G1 Garbage Collector- G1 GC (default in Java 9, 10)
The Z Garbage Collector- ZGC (default in Java 11)

Слайд 21

Steps to create a Java application

1. Code development
2. Compiling source code into bytecode
3.

Run the program in the JVM

Bytecode is a machine-independent low-level language of the Java virtual machine.

1

2

3

Слайд 22

JAVA_HOME & JRE_HOME

JAVA_HOME 
if you installed the JDK
or
JRE_HOME 
if you installed the

JRE  

Слайд 24

javac + java

Слайд 25

Java Archive

JAR

Manifest-Version: 1.0
Main-Class: Start
Created-By: 10.0.2 (Oracle Corporation)

Start.java

Start.class

Bytecode

javac.exe Start.java

Compile

java.exe -cp . Start

jar cvfm Start.jar

Manifest.mf *.class

java -jar Start.jar

Manifest.mf

Start.jar

Manifest.mf

Start.class

Execute

Слайд 27

JAR

LIVE DEMO

Слайд 28

Integrated Development Environment

IntelliJ IDEA

Слайд 29

Integrated Development Environment

Eclipse

Слайд 30

Java Frameworks

Google
Web
Toolkit

Слайд 31

The main method

public class Start { public static void main(String[] args) { System.out.println("Hello");

} }

The method must be marked as a public method.
The method must be marked as a static method.
The name of the method must be main.
The return type of this method must be void.
The method must accept a method argument of a String array or a variable argument (varargs) of type String.

Слайд 32

The main method

public static void main(String[] args)
public static void main(String args[])
public

static void main(String... args)
public static void main(String[] HelloWorld)
static public void main(String[] args)

Various possible options for the main method:

Слайд 33

The main method

public class Start { public static void main(String args) { System.out.println("Hello

2"); }
public static void main(String args[]) { System.out.println("Hello 1"); }
public static void main(int number) { System.out.println("Hello 3"); } }

Слайд 34

Code convention

Слайд 36

Maven project

LIVE DEMO

Имя файла: Java-Core.-Introduction.pptx
Количество просмотров: 77
Количество скачиваний: 0