Presentation is loading. Please wait.

Presentation is loading. Please wait.

[INA470] Java Programming Youn-Hee Han

Similar presentations


Presentation on theme: "[INA470] Java Programming Youn-Hee Han"— Presentation transcript:

1 [INA470] Java Programming Youn-Hee Han http://link.kut.ac.kr
01. 자바 소개 [INA470] Java Programming Youn-Hee Han

2 JAVA is Fun!!! duke Thinking in Java

3 1. 프로그램이란 무엇인가? Computer programs (also software programs, or just programs) are instructions for a computer. You tell a computer what to do through programs. Without programs, a computer is an empty machine. Computers do not understand human languages, so you need to use computer languages to communicate with them. Programs are written using programming languages. 1. 컴퓨터가 범용성을 가질 수 있는 근본 이유는? 2. 왜 MP3 Player는 컴퓨터에 비하여 덜 범용적인가?

4 2. 프로그래밍 언어 Q) 컴퓨터가 이해할 수 있는 언어는 어떤 것인가?
컴퓨터가 알아듣는 언어는 한가지이다. 즉 0과 1로 구성되어 있는 “ ”과 같은 기계어이다. Machine language is a set of primitive instructions built into every computer. The instructions are in the form of binary code, so you have to enter binary codes for various instructions. Program with native machine language is a tedious process. Moreover the programs are highly difficult to read and modify. For example, to add two numbers, you might write an instruction in binary like this:

5 2. 프로그래밍 언어 Q) 그렇다면 인간이 기계어를 사용하면 어떤가?
기계어를 사용할 수는 있으나 이진수로 프로그램을 작성하여야 하기 때문에 아주 불편하다. 프로그래밍 언어는 자연어와 기계어 중간쯤에 위치 컴파일러가 프로그래밍 언어를 기계어로 통역 자바는 프로그래밍 언어의 일종

6 2. 프로그래밍 언어 [프로그래밍 언어의 분류] 기계어(machine language)
어셈블리어(assembly language) 고급 언어(high-level language): 자바, C++, C 기계어 어셈블리어 고급언어 컴퓨터 인간

7 2. 프로그래밍 언어 Assembly languages were developed to make programming easy. Since the computer cannot understand assembly language, however, a program called assembler is used to convert assembly language programs into machine code. For example, to add two numbers, you might write an instruction in assembly code like this: ADDF3 R1, R2, R3

8 3. 자바의 기초 개념 [자바란?] 패러다임(Paradigm) 등장 누가 설계하였나? 가장 최근 버전 설계 원칙
객체 지향 프로그래밍(Object-oriented) 구조적 프로그래밍(structured) 절차적 프로그래밍(imperative) 등장 1995 누가 설계하였나? Sun Microsystems, James Gosling 가장 최근 버전 Java Standard Edition 6 (1.6.0_14)  Java Standard Edition 7 설계 원칙 Static, strong, safe, nominative, manifest

9 3. 자바의 기초 개념 [JVM (Java Virtual Machine, 자바 가상 기계)]
자바는 다양한 컴퓨터에서 동일한 모습으로 실행이 가능하다. 왜 그럴까? 바로 자바 가상 기계 때문이죠

10 3. 자바의 기초 개념 [Byte Code (바이트 코드)]
자바 컴파일러는 특정한 컴퓨터가 아닌 JVM을 위한 코드인 Byte Code (바이트 코드)를 생성한다.

11 3. 자바의 기초 개념 [자바 플랫폼] 플랫폼(platform)이란 프로그램이 실행되는 하드웨어나 소프트웨어 환경이다.
API (Application Programming Interface)란 많은 유용한 기능을 제공하는 라이브러리들의 모임이다.

12 4. 자바의 역사 1991년에 Sun에서는 제임스 고슬링(James Gosling)를 비롯한 Green 연구팀에서는 가정용 전자 제품에 사용할 수 있는 작은 컴퓨터 언어를 설계 각종 전자 제품은 많은 종류의 CPU로 만들어지기 때문에 특정한 CPU에 의존하게 되는 단점이 있어서 일종의 가상 기계 (Virtual Machine) 개념을 고안 Green 프로젝트를 위한 더 나은 가상 기계 및 언어를 직접 만들게 되는데 이것이 바로 자바. Java라는 단어를 고안하기 전의 언어 이름은 Oak. 그러나 이미 Oak라는 프로그래밍 언어가 있다는 사실을 발견 Green 프로젝트는 Time Warner의 주문형 비디오 시스템을 개발하다가 Time Warner가 경쟁사인 실리콘 그래픽스 사를 선택하는 바람에 결국 실패 1993년, 그래픽 기반의 월드 와이드 웹(world wide web)이 발표되고 자바의 개발자들은 곧 이러한 웹 기반의 응용 프로그램에는 자바와 같은 기계 중립적인 언어가 이상적이라는 것을 발견 (참고: 애플릿 - Applet)

13 4. 자바의 역사 James Gosling Hot Java Early History Website:
The first Java-enabled Web browser Early History Website: James and Duke

14 4. 자바의 역사 [자바의 버전] Java 1.4 부터는 JCP (Java Community Process)라는 단체가 자바 언어의 스펙을 만드는 작업을 담당

15 5. 자바의 특징 Write Once, Run Everywhere!

16 5. 자바의 특징 단순하지만 강력하다. 꼭 필요로 하는 기능만을 포함시키고 복잡하고 많이 쓰이지 않는 기능은 삭제
포인터 연산, 연산자 오버로딩, 다중 상속 등의 복잡한 기능을 삭제 자동 메모리 관리 기능, 멀티 스레드, 방대한 라이브러리 제공 객체 지향적이다. 객체 지향은 지난 30년간의 연구를 통하여 그 가치를 입증한, 프로그램을 설계하는 방법론 기본 데이터 타입을 제외한 거의 모든 것이 객체로 표현 분산 환경 지원 네트워크상에서 동작되는 것을 기본으로 설계 쉽게 네트워크 관련 프로그램을 개발

17 5. 자바의 특징 견고하다. 오류를 만들 수 있는 원인들을 제거
(예) 포인터 개념을 삭제하였으며 컴파일시에 강력하게 데이터 타입을 검사 안전하다. 바이러스, 파일의 삭제나 수정, 데이터 파괴 작업이나 컴퓨터 오류 연산 등을 방지하면서 실행되도록 설계되었다. 컴퓨터 구조에 중립적이다. & 이식성(Portability)이 있다. 컴퓨터 구조에 중립적인 바이트 코드로 번역 이러한 바이트 코드 특성 때문에 인터넷에 연결된 서로 다른 기종의 컴퓨터에서도 자바는 실행될 수 있다. 모든 플랫폼에서 동일한 실행 결과를 생성

18 5. 자바의 특징 동적이다(Dynamic). 라이브러리들은 실행 파일에 영향을 끼치지 않고 자유롭게 새로운 기능들을 추가할 수 있다. 자바는 실행되기 직전에 라이브러리를 동적으로 링크하므로 실행할 때 변경된 라이브러리가 자동적으로 참조된다. 고성능이다. JVM 위에서 바이트 코드를 해석하면서 수행하기 때문에 실행 속도가 다른 언어에 비해 느린편임. JIT (Just-in-time) 컴파일러 도입 자바 코드를 기계어 레벨로 변환하는 개념 JIT의 도입으로 기존의 다른 언어와 비슷한 실행 속도를 보임

19 5. 자바의 특징 멀티스레딩 지원 자바는 언어 수준에서 멀티스레딩(multithreading)을 지원
멀티스레딩이란 많은 작업을 동시에 실행할 수 있음을 의미 동적이다(Dynamic). 라이브러리들은 실행 파일에 영향을 끼치지 않고 자유롭게 새로운 기능들을 추가할 수 있다. 자바는 실행되기 직전에 라이브러리를 동적으로 링크하므로 실행할 때 변경된 라이브러리가 자동적으로 참조된다. 기타 장점 비교적 배우기 쉽고 특히 C언어를 이미 학습하였다면 더욱 쉽다. 자바 웹 스타트(Java Web Start) 소프트웨어를 사용하면 제작된 응용 프로그램을 한 번의 마우스 클릭으로 실행

20 6. 자바의 에디션 Java SE(Standard Edition) Java EE(Enterprise Edition)
Java ME(Micro Edition)

21 6. 자바의 에디션 [Java SE] Java SE는 데스크탑과 서버에서 자바 애플리케이션을 개발하고 실행할 수 있게 해주며 임베디드 환경(embedded environment)과 실시간 환경(real-Time environments)도 지원

22 6. 자바의 에디션 [Java EE] Java EE는 기업용 애플리케이션을 개발하는 데 필요한 여러 가지 도구 및 라이브러리들을 모아 놓은 것 응용 서버, 웹서버, J2EE API, 엔터프라이즈 자바 빈즈(JavaBeans) 지원, 자바 서블릿 API 와 JSP 등을 포함

23 6. 자바의 에디션 [Java ME] Java ME는 핸드폰, PDA, TV 셉톱박스, 프린터와 같은 모바일 기기나 다른 엠베디드 장치들에서 실행되는 애플리케이션을 위한 강인하고 유연한 환경을 제공

24 7. 자바로 만들 수 있는 것 자바 애플리케이션(Java application) 자바 애플릿(Java applet)
독립적으로 실행될 수 있는 일반 응용 프로그램 자바 애플릿(Java applet) 웹 브라우저 안에서 실행되는 작은 프로그램이다.

25 7. 자바로 만들 수 있는 것 자바 서블릿(Java servlet)
웹서버에서 동작하는 서버 모듈로서 클라이언트의 요구를 받아서 그에 대한 처리를 한 후에, 실행 결과를 HTML 문서 형태로 클라이언트 컴퓨터로 전송

26 7. 자바로 만들 수 있는 것 JSP (Java Server Page)
HTML안에 자바 코드를 넣으면 웹페이지를 사용자와 상호작용하도록 만들 수 있다. JSP는 서버에서 실행되고 결과를 사용자에게 보여준다. JSP는 서블릿으로 변환되며 컴파일을 거쳐서 바이트 코드가 만들어진다. 이 바이트 코드가 수행된 결과를 브라우저로 보낸다.

27 7. 자바로 만들 수 있는 것 자바 빈즈(Java Beans)

28 [Appendix] Compiler & Interpreter

29 Machine Language Machine language – A language understood by computers
When programs run, machine language is used Machine languages are almost impossible for humans to understand Every operating system (OS) has its own machine language Windows Linux Macintosh Hardware Machine Language High Level Language C++ Java VB .NET

30 High Level Languages High Level Language - A programming language that is understandable by people This enables a programmer to write programs High level languages must be translated into machine language before running on a computer Hardware Machine Language High Level Language C++ Java VB .NET

31 Compilers and Interpreters
There are two main ways to change programs written in a high level language to machine language: Use a compiler Use an interpreter Source Code – Code written in a programming language by a developer.

32 Compilers Compiler – A program that transforms code from one format to another High Level Language Machine Language Source code Windows compiler Windows code Windows Linux compiler Linux code Linux Macintosh compiler Macintosh code Macintosh

33 Compilers Advantages Disadvantages Programs run faster
Platform dependent - Programs only work on a specific operating system. Windows Linux Macintosh Compiling a large program may take a long time

34 Interpreters Interpreter – a program that translates a high-level language into a low-level one, but it does it at the moment the program is run. 기계에서 수행되는 Interpreter 소프트웨어에서 고급언어를 해석하여 곧바로 수행시키는 방식 Usually, interpreters translate and execute source code. 인터프리터는 프로그램을 한 문장씩 기계어로 번역하여 수행하는 소프트웨어 Machine Language Code for Windows, Linux and Macintosh High Level Language Source Code Interpreter Windows, Linux and Macintosh

35 Interpreters Advantages Disadvantages
There is no lengthy "compile time“ As soon as you have written a program, you can run it. more "portable", which means that the program will run on a greater variety of machines Disadvantages The interpreter program must be installed on the computer that the program will run on Slower execution You should only use services available on all platforms. Example: Windows has a cool sound library, but you can’t use it because it won’t run on Macintosh

36 How Does Java Work? Java uses a compiler and interpreter!
You can compile the program once and run it on each platform with an interpreter Java Interpreter Source code Windows Windows Java Compiler Linux Macintosh Byte Code Linux Macintosh

37 How to Create a Java Program
You write Java code using an editor javac MyProg.java java MyProg Java code: MyProg.java Bytecode: MyProg.class Text Editor Output You save the file with a .java extension You run the Java compiler 'javac' You execute the bytecode with the command 'java' This creates a file of bytecode with a .class extension

38 Use the Java Compiler to Create Byte Code
Source code is compiled by a Java compiler to byte code. Byte Code A file that can run on any computer that has a Java Interpreter Filename extension: .class Compiler program: javac.exe Java Compiler Javac.exe Source Code void main () … ??this$0?!... Byte Code .java .class

39 Use the Java Compiler to Create Byte Code
Important Details Javac.exe <filename>.java Ex: Javac HelloWorld.java A .class file is made for every class in the file. Common Errors Unable to find the Compiler - Something is wrong with your Java setup. Windows can’t find the Java compiler. Is your access to Javac.exe and Java.exe setup properly? Invalid Flag – One of the inputs are wrong. Did you include the .java extension? Are you using the right file?

40 Run the Byte Code Using the Java Interpreter
Java Virtual Machine (JVM) – A program which interprets Java programs that have been compiled into byte-code and usually stored in a ".class" file. Interpreter performs actions Creates windows Prints Etc. Interpreter program: java.exe Byte Code Java Interpreter Java.exe ??this$0?!... .class

41 Run the Byte Code Using the Java Interpreter
Important Details Java.exe <class name> Ex: Java HelloWorld The class name must have the correct case! Common Errors NoClassDefFoundError – The class can’t be found. Is your class in the correct directory? Are you using the correct case?


Download ppt "[INA470] Java Programming Youn-Hee Han"

Similar presentations


Ads by Google