Java Core Introduction

Содержание

Слайд 2

Agenda Introduction to Java Platform. Java SDK Environment and Development Tools

Agenda

Introduction to Java Platform. Java SDK
Environment and Development Tools for Java

applications
Eclipse IDE Tips & Tricks
The Entry Point into the Program
Java Packages. Introduction
My first program
Слайд 3

Introduction to Java Platform James Gosling, Mike Sheridan, and Patrick Naughton

Introduction to Java Platform

James Gosling, Mike Sheridan, and Patrick Naughton initiated

the Java language project in June 1991.
The language was initially called Oak after an oak tree. Now, Java it is the name of a platform and language.
Java applications are typically compiled to bytecode (class file) that can run on any Java Virtual Machine (JVM) regardless of computer architecture.
The original and reference implementation Java compilers, virtual machines, and class libraries were developed by Sun from 1995 (May 23, 1995, Java 1.0).
With the advent of Java 2 (JDK 1.2, released initially as J2SE 1.2 in December 1998–1999), new versions had multiple configurations built for different types of platforms.
Слайд 4

Introduction to Java Platform Sun distinguishes between its Software Development Kit

Introduction to Java Platform

Sun distinguishes between its Software Development Kit (SDK)

and Runtime Environment (JRE) (a subset of the SDK); the primary distinction involves the JRE's lack of the compiler, utility programs, and header files.
Sun also distributes a superset of the JRE called the Java Development Kit (commonly known as the JDK), which includes development tools such as the Java compiler, Javadoc, Jar, and debugger.
The JDK forms an extended subset of a SDK. In the descriptions which accompany its recent releases for Java SE, EE, and ME, Sun acknowledges that under its terminology, the JDK forms the subset of the SDK which has the responsibility for the writing and running of Java programs.
Слайд 5

Introduction to Java Platform Specification Java 2 (JDK 1.2) – 1998/1999

Introduction to Java Platform

Specification Java 2 (JDK 1.2) – 1998/1999 (strictfp;

collection support; Swing; GUI; drag-and-drop; CORBA; Unicode; JIT compiler). Sun renamed new J2 versions as Java EE, Java ME, and Java SE.
Specification Java 5 (JDK 1.5) – September 2004 (enum type is class; generics mechanism, templates analog of C++; foreach; Autoboxing/Unboxing: for example, scalar and wrapper type int – Integer; Javadoc; etc.)
Слайд 6

Platform Components JDK = JRE + Development/debugging tools JRE = JVM

Platform Components

JDK = JRE + Development/debugging tools
JRE = JVM + Java

Packages Classes(like util, math, lang, awt,swing etc)+runtime libraries.
JVM = Java Virtual Machine
Слайд 7

Detailed Diagram of Java Components

Detailed Diagram of Java Components

Слайд 8

http://www.oracle.com/technetwork/java/javase/downloads/index.html Java JDK

http://www.oracle.com/technetwork/java/javase/downloads/index.html

Java JDK

Слайд 9

In System Variables enter the variable name as JAVA_HOME and the

In System Variables
enter the variable name as JAVA_HOME and the variable value

as the installation path for the Java Development Kit

Install Java

add to the variable Path values %JAVA_HOME% and %JAVA_HOME%\bin

Слайд 10

java -version Install Java

java -version

Install Java

Слайд 11

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

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

System.out.println("My first program");
}
}
To display information on the screen it’s used
System.out.println("Text1");
System.out.println("Text 1 " + "Text 2");

Java JDK. Entry Point

Слайд 12

Java JDK Example.java javac.exe Example.java Compile java.exe Example JVM Bytecode jar

Java JDK

Example.java

javac.exe Example.java

Compile

java.exe Example

JVM

Bytecode

jar cvfm Example.jar Manifest.mf Example.class

java -jar Example.jar

Java Archive

Example.jar

Manifest.mf

Example.class

Executing

Слайд 13

For Compile: javac Example.java Output file: Example.class For Running: java Example

For Compile:
javac Example.java
Output file: Example.class
For Running:
java Example
Exception in thread "main“
java.lang.NoClassDefFoundError: Example
java

-cp "Example.class;" Example
For Creating Java archive:
jar cvfm Example.jar Manifest.mf Example.class
java -jar Example.jar

Java JDK

Manifest.mf
Manifest-Version: 1.0
Created-By: 1.8.0_5 (Sun Microsystems Inc.)
Main-Class: Example

Слайд 14

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

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

for (int i=0; i System.out.println("Arg " + i + " is " + args[i]);
}
}
}
or
public class ShowArgs2 {
public static void main(String[ ] args) {
for (String arg: args) {
System.out.println("Command line arg: " + arg);
}
}
}

Program Entry Point

Слайд 15

Some types of data

Some types of data

Слайд 16

Online Java compiler http://www.tutorialspoint.com/compile_java_online.php https://ideone.com/ https://www.compilejava.net/ http://www.browxy.com/ https://www.jdoodle.com/online-java-compiler

Online Java compiler

http://www.tutorialspoint.com/compile_java_online.php
https://ideone.com/
https://www.compilejava.net/
http://www.browxy.com/
https://www.jdoodle.com/online-java-compiler

Слайд 17

NetBeans began in 1996 as Xelfi (word play on Delphi). In

NetBeans began in 1996 as Xelfi (word play on Delphi). In

1997 Roman Staněk (Charles University in Prague) formed a company around the project and produced commercial versions of the NetBeans IDE until it was bought by Sun Microsystems in 1999. Sun open-sourced the NetBeans IDE
IntelliJ IDEA is a commercial Java IDE by JetBrains. It is often simply referred to as 'IDEA' or 'IntelliJ'. A 30-day fully functional trial of the IntelliJ IDEA commercial edition for various platforms can be freely downloaded. Also available is an open source Community Edition. The first version of IntelliJ IDEA appeared in January 2001. Community Edition is open-source

Environment, Development Tools

Слайд 18

JCreator is a Java IDE created by Xinox Software. Its interface

JCreator is a Java IDE created by Xinox Software. Its interface

is similar to that of Microsoft's Visual Studio. JCreator has two editions: Lite Edition (LE) is freeware and Pro Edition (Pro, 30-days trial). JCreator is only available on the Windows Operating System.
Eclipse is a multi-language software development environment comprising an integrated development environment (IDE) and an extensible plug-in system. It is written primarily in Java and can be used to develop applications in Java and, by means of various plug-ins, other languages including C, C++, COBOL, Python, Perl, PHP, Scala, Scheme and Ruby (including Ruby on Rails framework)
http://www.eclipse.org/downloads/

Environment, Development Tools

Слайд 19

Eclipse

Eclipse

Слайд 20

Eclipse

Eclipse

Слайд 21

Java package is a mechanism for organizing Java classes into namespaces.

Java package is a mechanism for organizing Java classes into namespaces.
Programmers

also typically use packages to organize classes belonging to the same category or providing similar functionality.
A package provides a unique namespace for the types it contains.
Classes in the same package can access each other's package-access members.
package java.awt.event;

Packages

Слайд 22

imports all classes from the package import java.awt.event.*; imports only the

imports all classes from the package
import java.awt.event.*;
imports only the ActionEvent class

from the package
import java.awt.event.ActionEvent;
. . .
ActionEvent myEvent = new ActionEvent();
Classes can also be used directly without an import declaration
java.awt.event.ActionEvent myEvent =
new java.awt.event.ActionEvent();

Packages

Слайд 23

java.lang – basic language functionality and fundamental types java.util – collection

java.lang – basic language functionality and fundamental types
java.util – collection data

structure classes
java.io – file operations
java.math – multiprecision arithmetics
java.awt – basic hierarchy of packages for native GUI components
javax.swing – hierarchy of packages for platform-independent rich GUI components
The java.lang.* package is available without the use of an import statement.

Packages. Java

Слайд 24

Package names and type names usually differ. package Vector; public class

Package names and type names usually differ.
package Vector;
public class Mosquito {


int capacity;
}
//- - - - - - - - - - - - - - - - - - - -
package strange.example;
import java.util.Vector;
import Vector.Mosquito;
class Test {
public static void main(String[ ] args) {
System.out.println(new Vector().getClass());
System.out.println(new Mosquito().getClass());
}
}

Packages

Слайд 25

To input value during the run time you can use BufferedReader

To input value during the run time you can use
BufferedReader br

= new BufferedReader(
new InputStreamReader(System.in));
String text = br.readLine();
int age = Integer.parseInt(br.readLine());
double t = Double.parseDouble(br.readLine());
Or
Scanner sc = new Scanner(System.in);
name = sc.nextLine();

Input data

Слайд 26

package com.edu; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main

package com.edu;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void

main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in));
System.out.println("Hello. What is your name?");
String name = br.readLine();
System.out.println("How old are you?");
int age = Integer.parseInt(br.readLine());
System.out.println("Hello " + name);
System.out.println("You are " + age);
}
}

My first program

Слайд 27

Create Console Application project in Java. In method main() write code

Create Console Application project in Java.
In method main() write code for

solving next tasks:
Define integer variables a and b. Read values a and b from Console and calculate: a + b, a - b, a * b, a / b.
Output obtained results.
Output question “How are you?“. Define string variable answer. Read the value answer and output: “You are (answer)".

Tasks

Слайд 28

HomeWork (online course) Please register on UDEMY course "Java Tutorial for

HomeWork (online course)

Please register on UDEMY course "Java Tutorial for Complete

Beginners": https://www.udemy.com/java-tutorial/
Complete lessons 1-7:
Слайд 29

Install JDK and Eclipse. Create Java project. Create console application. In

Install JDK and Eclipse.
Create Java project.
Create console application. In method main()

write code for solving next tasks:
Flower bed is shaped like a circle. Calculate the perimeter and area by entering the radius. Output obtained results.
Define string variable name and integer value age. Output question "What is your name?" Read the value name and output next question: “Where are you live, (name)?". Read address and write whole information.
Phone calls from three different countries are с1, с2 and с3 standard units per minute. Talks continued t1, t2 and t3 minutes. How much computer will count for each call separately and all talk together? Input all source data from console, make calculations and output to the screen.

HomeWork