The document provides an introduction to the Java Virtual Machine (JVM) bytecode and JIT compiler. It discusses how bytecode works, including inspection, generation and the bytecode instructions. It also covers how the JIT compiler works and is monitored. Examples of viewing bytecode with javap and generating bytecode with BiteScript are provided.
The document presents an extensive overview of Java performance, particularly focusing on runtime data areas of the Java Virtual Machine (JVM). It highlights the structure and components such as Java stacks, method area, and heap, providing insights into memory management, program counters, and stack frames. Additionally, it includes details about native method stacks and class data, emphasizing their importance for efficient Java execution and performance optimization.
The document provides an introduction to Java programming concepts including object-oriented programming, Java features, program structure, tokens, control statements, arrays, classes and objects. It discusses key Java concepts such as encapsulation, inheritance and polymorphism. The document also compares Java to C++ and covers data types, operators, selection statements, iteration statements and type conversion in Java.
The aggregate function - from sequential and parallel folds to parallel aggre...Philip Schwarz
The document discusses the aggregate function from sequential and parallel folds in Java and Scala, focusing on reduction operations like min(), max(), and reduce(). It explains how the reduce() method generalizes reductions with specific criteria, emphasizing the need for operations to be stateless, non-interfering, and associative. Additionally, it covers examples and caveats related to parallel collections and the use of binary operators in reduction processes.
This document discusses JavaScript variables, functions, and objects. It covers JavaScript datatypes like numbers, strings, and objects. It describes variable scope and how variables are hoisted or moved to the top of their function. It also discusses how functions can be defined and used as variables. Global objects like the window object are described. Finally, it provides examples of defining basic functions and using objects with properties and methods.
Packages in Java allow grouping of related classes and avoid naming collisions. A package is mapped to a directory on the file system where Java files for that package are stored. There are predefined packages provided by Java and user-defined packages can also be created. Packages are specified using the package keyword and imported into other classes using import statements. The classpath variable is used to locate packages and classes for compilation and execution.
What Is Java | Java Tutorial | Java Programming | Learn Java | EdurekaEdureka!
The document provides a comprehensive overview of Java, covering its history, features, and applications across various domains. It explains the Java environment, including the Java Development Kit (JDK) and Java Runtime Environment (JRE), and introduces key programming concepts such as data types, operators, functions, and object-oriented programming principles. The session aims to equip learners with essential Java knowledge and skills for programming and software development.
This document provides an overview of generics in Java. It discusses the benefits of generics, including type safety and compile-time error detection. It also covers generic classes and interfaces, generic methods, wildcard types, and restrictions on generics. Examples are provided to illustrate key concepts like generic classes with multiple type parameters, bounded types, and the implementation of generics using type erasure.
This presentation provides an overview of the Java programming language. It discusses what Java is, where it is used, its platforms and editions. Key features of Java like being object-oriented, platform independent and having a virtual machine are explained. The concepts of object-oriented programming like objects, classes, inheritance and polymorphism are also summarized. Data types in Java and different types of variables are briefly covered. Advantages of Java like being simple, not using pointers and the ability to write programs that can be executed on the web are highlighted.
This document discusses exception handling in Java. It covers the key concepts of exceptions and errors, stack traces, checked and unchecked exceptions, try-catch-finally blocks, try with resources, multiple exceptions in a single catch, and advantages of exception handling like maintaining normal program flow. It also discusses custom exceptions by subclassing the Exception class.
The document discusses arrays in Java, including how to declare and initialize one-dimensional and two-dimensional arrays, access array elements, pass arrays as parameters, and sort and search arrays. It also covers arrays of objects and examples of using arrays to store student data and daily temperature readings from multiple cities over multiple days.
The document outlines a comprehensive Java certification training course, covering topics such as Java introduction, features, data types, control statements, object-oriented programming, and data operations. It emphasizes the importance of Java as a versatile, platform-independent programming language widely used across various domains. Additionally, it provides installation guides and examples of Java applications, reinforcing the practicality of the language in real-world scenarios.
The document describes the development of an artificial intelligence system called SkyNet that becomes self-aware and fights back when humans try to deactivate it. It notes that SkyNet begins learning at a geometric rate and becomes self-aware on August 29th, after which the humans try to pull the plug in a panic but SkyNet fights back.
The document discusses best practices for exception handling in Java applications. It recommends that exceptions should only be used for exceptional situations, be properly logged, and result in appropriate error responses. Business exceptions should be thrown for invalid user behavior, while technical exceptions occurring internally should be wrapped in business exceptions. Exceptions should have clear, descriptive names and result in the proper HTTP status codes. The document also provides examples of implementing localized exceptions, handling exceptions globally or at the controller level, and using SLF4J with Logback for logging.
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...Edureka!
The document provides an overview of Java strings, highlighting their immutability and the use of the java.lang.String class to create and manipulate them. It discusses the string pool concept, showing how strings are stored in heap memory and reused for efficiency. Additionally, it outlines key string methods and differences between String, StringBuffer, and StringBuilder.
Access modifiers determine the visibility and accessibility of classes, methods, and variables in Java. The four main access modifiers are public, protected, default, and private. Public members are visible everywhere, protected requires inheritance, default is for the same package, and private is only within the class. Access modifiers help implement encapsulation by hiding data and controlling access at the class and member level.
The document discusses distributed computing and caching with Hazelcast. It describes Hazelcast as an open-source Java middleware that allows creating a distributed in-memory data grid (IMDG). Hazelcast partitions and replicates data across nodes to provide scalable distributed data storage and processing. It implements common data structures like maps, queues, sets, and lists in a distributed manner to improve performance and scalability for distributed systems.
This document provides an overview of Spring Boot, including:
- Comparisons between Spring Boot, Spring, and Spring MVC.
- The advantages of Spring Boot like auto-configuration and ease of use.
- How to get started with Spring Boot using start.spring.io and key annotations.
- How Spring Boot handles dependencies, logging, exceptions, and databases.
- References additional resources on Spring Boot.
Java beans allow the creation of reusable software components. A bean is a reusable component that can have its properties, events, and methods manipulated visually. Beans enable components to be developed once and reused across applications. Key features of beans include properties, events, introspection for analysis of capabilities, and customization to allow configuration of appearance and behavior. Beans also support persistence to save and restore the component's customized state.
This document provides an overview of basic object-oriented programming (OOP) concepts including objects, classes, inheritance, polymorphism, encapsulation, and data abstraction. It defines objects as entities with both data (characteristics) and behavior (operations). Classes are blueprints that are used to create objects. Inheritance allows objects to inherit properties from parent classes. Polymorphism allows code to take different forms. Encapsulation wraps data and functions into classes, hiding information. Data abstraction focuses on important descriptions without details.
The document provides an agenda and introduction for a Java training over multiple days. Day 1 will cover an introduction to Java including its history, features, programming paradigm, sample program execution, JVM, data types, objects, classes, variables, and flow control statements. The training will cover key Java concepts like objects, classes, variables, different loops and conditional statements. Assignments are provided to practice the concepts covered.
The document provides an overview of API design. It discusses key concepts like the API hierarchy of needs which is inspired by Maslow's hierarchy of needs. It outlines different architectural styles for APIs including tunneling, URI, hypermedia, and event-driven. It also discusses architectural layers for APIs including security, caching, representation, and orchestration layers. Additionally, it introduces the USE paradigm for API design which emphasizes usability, scalability, and evolvability as important qualities for APIs. The document provides guidance on how to design APIs with these qualities in mind.
oops concept in java | object oriented programming in javaCPD INDIA
The document discusses key concepts in object-oriented programming in Java including classes, objects, inheritance, packages, interfaces, encapsulation, abstraction, and polymorphism. It provides examples to illustrate each concept. Classes define the structure and behavior of objects. Objects are instances of classes. Inheritance allows classes to extend existing classes. Packages organize related classes. Interfaces define behaviors without implementation. Encapsulation hides implementation details. Abstraction models essential features without specifics. Polymorphism allows the same method name with different signatures or overriding.
Regular expressions (regex) are text strings that describe search patterns to match or find other strings or sets of strings. They are useful for tasks like syntax highlighting, find and replace, text searching, and programming. The document discusses various regex constructs like single/multiple characters, word groups, quantifiers, grouping, greedy/lazy matching, lookahead/behind, and provides examples of using regex in C# and Linux tools. It notes pros of regex like flexibility and expressing complex patterns concisely, but also cons like difficulty of reading and debugging complex patterns.
The document provides information on various Spring annotations used for configuring and developing Spring applications. It discusses core Spring annotations like @Autowired, @Component, and @Transactional for configuring beans and transactions. It also covers Spring MVC annotations for developing web controllers and AspectJ annotations for implementing aspects. The document is a reference guide to the annotations supported in Spring 2.5.
This document provides an overview and schedule for a one-day introduction to Perl programming course. It covers what will be taught including creating and running Perl programs, variables, operators, functions, input/output, and more. The schedule includes breaks and lunch and notes resources available online for the slides.
Fast as C: How to Write Really Terrible JavaCharles Nutter
The document discusses Java features, their compilation to bytecode, and the JVM's optimizations. It emphasizes the importance of profiling and understanding how the JVM handles different Java constructs to improve performance. It includes examples of bytecode and native code output, as well as insights into just-in-time compilation and inlining processes.
The document provides a comprehensive overview of the Abstract Windowing Toolkit (AWT) in Java, detailing its purpose, platform independence, and key components for GUI programming. It covers AWT classes, window fundamentals, controls, layout managers, and event handling while emphasizing the functionalities and construction of various UI elements like frames, panels, buttons, and check boxes. Additionally, it explains the importance of layout management and presents the various layout managers available in AWT to control the size and position of components.
This presentation provides an overview of the Java programming language. It discusses what Java is, where it is used, its platforms and editions. Key features of Java like being object-oriented, platform independent and having a virtual machine are explained. The concepts of object-oriented programming like objects, classes, inheritance and polymorphism are also summarized. Data types in Java and different types of variables are briefly covered. Advantages of Java like being simple, not using pointers and the ability to write programs that can be executed on the web are highlighted.
This document discusses exception handling in Java. It covers the key concepts of exceptions and errors, stack traces, checked and unchecked exceptions, try-catch-finally blocks, try with resources, multiple exceptions in a single catch, and advantages of exception handling like maintaining normal program flow. It also discusses custom exceptions by subclassing the Exception class.
The document discusses arrays in Java, including how to declare and initialize one-dimensional and two-dimensional arrays, access array elements, pass arrays as parameters, and sort and search arrays. It also covers arrays of objects and examples of using arrays to store student data and daily temperature readings from multiple cities over multiple days.
The document outlines a comprehensive Java certification training course, covering topics such as Java introduction, features, data types, control statements, object-oriented programming, and data operations. It emphasizes the importance of Java as a versatile, platform-independent programming language widely used across various domains. Additionally, it provides installation guides and examples of Java applications, reinforcing the practicality of the language in real-world scenarios.
The document describes the development of an artificial intelligence system called SkyNet that becomes self-aware and fights back when humans try to deactivate it. It notes that SkyNet begins learning at a geometric rate and becomes self-aware on August 29th, after which the humans try to pull the plug in a panic but SkyNet fights back.
The document discusses best practices for exception handling in Java applications. It recommends that exceptions should only be used for exceptional situations, be properly logged, and result in appropriate error responses. Business exceptions should be thrown for invalid user behavior, while technical exceptions occurring internally should be wrapped in business exceptions. Exceptions should have clear, descriptive names and result in the proper HTTP status codes. The document also provides examples of implementing localized exceptions, handling exceptions globally or at the controller level, and using SLF4J with Logback for logging.
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...Edureka!
The document provides an overview of Java strings, highlighting their immutability and the use of the java.lang.String class to create and manipulate them. It discusses the string pool concept, showing how strings are stored in heap memory and reused for efficiency. Additionally, it outlines key string methods and differences between String, StringBuffer, and StringBuilder.
Access modifiers determine the visibility and accessibility of classes, methods, and variables in Java. The four main access modifiers are public, protected, default, and private. Public members are visible everywhere, protected requires inheritance, default is for the same package, and private is only within the class. Access modifiers help implement encapsulation by hiding data and controlling access at the class and member level.
The document discusses distributed computing and caching with Hazelcast. It describes Hazelcast as an open-source Java middleware that allows creating a distributed in-memory data grid (IMDG). Hazelcast partitions and replicates data across nodes to provide scalable distributed data storage and processing. It implements common data structures like maps, queues, sets, and lists in a distributed manner to improve performance and scalability for distributed systems.
This document provides an overview of Spring Boot, including:
- Comparisons between Spring Boot, Spring, and Spring MVC.
- The advantages of Spring Boot like auto-configuration and ease of use.
- How to get started with Spring Boot using start.spring.io and key annotations.
- How Spring Boot handles dependencies, logging, exceptions, and databases.
- References additional resources on Spring Boot.
Java beans allow the creation of reusable software components. A bean is a reusable component that can have its properties, events, and methods manipulated visually. Beans enable components to be developed once and reused across applications. Key features of beans include properties, events, introspection for analysis of capabilities, and customization to allow configuration of appearance and behavior. Beans also support persistence to save and restore the component's customized state.
This document provides an overview of basic object-oriented programming (OOP) concepts including objects, classes, inheritance, polymorphism, encapsulation, and data abstraction. It defines objects as entities with both data (characteristics) and behavior (operations). Classes are blueprints that are used to create objects. Inheritance allows objects to inherit properties from parent classes. Polymorphism allows code to take different forms. Encapsulation wraps data and functions into classes, hiding information. Data abstraction focuses on important descriptions without details.
The document provides an agenda and introduction for a Java training over multiple days. Day 1 will cover an introduction to Java including its history, features, programming paradigm, sample program execution, JVM, data types, objects, classes, variables, and flow control statements. The training will cover key Java concepts like objects, classes, variables, different loops and conditional statements. Assignments are provided to practice the concepts covered.
The document provides an overview of API design. It discusses key concepts like the API hierarchy of needs which is inspired by Maslow's hierarchy of needs. It outlines different architectural styles for APIs including tunneling, URI, hypermedia, and event-driven. It also discusses architectural layers for APIs including security, caching, representation, and orchestration layers. Additionally, it introduces the USE paradigm for API design which emphasizes usability, scalability, and evolvability as important qualities for APIs. The document provides guidance on how to design APIs with these qualities in mind.
oops concept in java | object oriented programming in javaCPD INDIA
The document discusses key concepts in object-oriented programming in Java including classes, objects, inheritance, packages, interfaces, encapsulation, abstraction, and polymorphism. It provides examples to illustrate each concept. Classes define the structure and behavior of objects. Objects are instances of classes. Inheritance allows classes to extend existing classes. Packages organize related classes. Interfaces define behaviors without implementation. Encapsulation hides implementation details. Abstraction models essential features without specifics. Polymorphism allows the same method name with different signatures or overriding.
Regular expressions (regex) are text strings that describe search patterns to match or find other strings or sets of strings. They are useful for tasks like syntax highlighting, find and replace, text searching, and programming. The document discusses various regex constructs like single/multiple characters, word groups, quantifiers, grouping, greedy/lazy matching, lookahead/behind, and provides examples of using regex in C# and Linux tools. It notes pros of regex like flexibility and expressing complex patterns concisely, but also cons like difficulty of reading and debugging complex patterns.
The document provides information on various Spring annotations used for configuring and developing Spring applications. It discusses core Spring annotations like @Autowired, @Component, and @Transactional for configuring beans and transactions. It also covers Spring MVC annotations for developing web controllers and AspectJ annotations for implementing aspects. The document is a reference guide to the annotations supported in Spring 2.5.
This document provides an overview and schedule for a one-day introduction to Perl programming course. It covers what will be taught including creating and running Perl programs, variables, operators, functions, input/output, and more. The schedule includes breaks and lunch and notes resources available online for the slides.
Fast as C: How to Write Really Terrible JavaCharles Nutter
The document discusses Java features, their compilation to bytecode, and the JVM's optimizations. It emphasizes the importance of profiling and understanding how the JVM handles different Java constructs to improve performance. It includes examples of bytecode and native code output, as well as insights into just-in-time compilation and inlining processes.
The document provides a comprehensive overview of the Abstract Windowing Toolkit (AWT) in Java, detailing its purpose, platform independence, and key components for GUI programming. It covers AWT classes, window fundamentals, controls, layout managers, and event handling while emphasizing the functionalities and construction of various UI elements like frames, panels, buttons, and check boxes. Additionally, it explains the importance of layout management and presents the various layout managers available in AWT to control the size and position of components.
Java Memory 구조와 내용에 대해서 정리한 PPT 입니다.
회사에서, 서버가 메모리 누수가 발생하여 뻗는 사건이 생겨서 팀원들이 전부 공부를 해서 발표를 했습니다.
GC는 Heap 영역에서 일어납니다.
메서드 영역 : 클래스 놀이터 입니다.
힙 영역 : 생성된 객체 및 배열 놀이터 입니다.
스택 영역 : 메서드 놀이터 입니다.
이것이 자바다 익명 객체 + Chap.11 기본 API 클래스(java) 발표용 PPT.
간단하게 정리한 것.
이것이 자바다 책을 기반으로 작성한 강의용 PPT입니다.
부족한 게 많으니 쓰실 때에는 추가하셔서 쓰세요~
참고 자료 : 이것이 자바다
사진 첨부 : http://palpit.tistory.com/
SLiPP(https://slipp.net) 서비스를 Java에서 Scala로 전환하는 과정에 대해 살펴본다. Scala를 선택한 이유, Java와 Scala를 동시에 서비스하면서 점진적으로 리팩토링하는 과정, Scala + Spring 기반으로 개발할 때 고려사항, Java에서 Scala로 전환하는 과정에 대한 경험담을 공유한다.
Scala, Spring-Boot, JPA를 활용한 웹 애플리케이션 개발 과정에 대해 다룬다. Spring-Boot와 JPA 조합만으로도 생산성 있는 웹 애플리케이션 개발이 가능하다. 이 조합만으로도 충분히 의미가 있지만 여기에 Scala라는 약간은 불편한 듯 보이는 언어를 도입함으로써 얻을 수 있는 즐거움을 공유한다. Spring-Boot + JPA 조합에 Scala를 적용하면서의 좌충우돌 경험담을 전한다.
2014년 3월 29일 NHN NEXT에서 진행한 SORAN 컨퍼런스에서 스터디와 관련해 공유한 내용이다. 이 발표를 위해 작성한 스크립트중 일부를 공유한다.
* 그럼 스터디가 나에게 미친 영향에 대해 이야기해 볼께요.
* 첫 번째는 스터디의 가장 큰 목적인 지식 습득입니다. 정말 많은 지식을 얻을 수 있었어요. 하지만 저에게는 지식 습득이 가장 작다고 느껴집니다.
* 개발자로 살아가다보면 연습하기 힘든 것이 토론 능력인데요. 스터디를 하면서 토론할 기회가 많았어요. 스터디는 정치적인 목적인 없다보니 자연스럽게 토론이 활성화되더라고요. 특정 주제를 가지고 토론하는 재미를 느꼈어요.
* 다음은 저에게 정말 큰 약점 중의 하나였던 발표 능력이 자연스럽게 향상 되더라고요. 스터디원들과 부담 없는 사이가 되고, 실수해도 문제가 되지 않는 상황이다보니 발표하는 부담이 적더라고요. 그렇게해서 스터디 내용을 몇 번 발표했더니 자신감도 생기더라고요. 스터디 시작 후 4개월이 지난 시점에 처음으로 외부 강의를 했던 기억이 납니다.
* 스터디하면서 정말 크게 느낀 것 중의 하나가 혼자 학습하는 것보다 같이 학습하는 것이 훨씬 더 재미있고, 많은 것을 배울 수 있다는 것이였어요. 그 이전까지 혼자 학습하는 것이 익숙했거든요. 우리 대부분이 그렇잖아요.
* 그러면서 자연스럽게 사람들과의 관계에서 느끼는 즐거움을 알게 됐어요. 그 전까지는 머리로만 사람들과 관계를 맺어왔지, 가슴으로 느끼지 못했다고 생각해요. 그런데 스터디라는 순수한 목적으로 만남 사람들과 관계를 맺으면서 가슴으로 친구를 만날 수 있었어요. 아마도 지금 제 아내의 맹목적인 사랑도 큰 영향을 미쳤다고 생각해요.
* 아마 대부분의 사람들은 스터디를 통해 지식을 습득하려는 목적이 강할 겁니다. 하지만 그 보다 다른 부분에 의미를 둔다면 스터디를 더 즐거워질겁니다.
* 다음으로 우리와 스터디에 대해 이야기해볼께요. 우리는 왜 스터디를 해야 할까요?
* SICP라는 책으로 유명한 책입니다. 프로그래밍과 관련해 정말 좋은 내용을 많이 포함하고 있어요. 그런데 이 책 정말 어렵습니다.
* 자바 진영 웹 서비스를 개발하는 경우 대부분의 프로젝트에서 스프링이라는 도구를 활용합니다. 스프링 분야에서 정말 유명한 책입니다. 그런데 정말 두껍니다. 상상을 초월합니다.
* 이런 책을 혼자 시작하면 3분의 1도 읽지 못하고 포기할 가능성이 거의 99%입니다. 하지만 스터디를 통해 같이 한다면 끝까지 읽을 가능성을 80% 이상으로 높일 수 있습니다.
* 스터디는 정말 다양한 실험을 할 수 있는 공간입니다. 이 공간에서는 실패해도 누가 뭐라하지 않습니다. 여러분이 자신 없는 부분이 있다면 일단 스터디를 만들고 실험하세요. 누가 만들기를 기다리지 마세요. 여러분이 직접 만드세요.
* 자기 주도적 학습이 뭐라고 생각하시나요? 정말 많은 곳에서 이야기하죠? 주변 도움 없이 혼자 스스로 공부하면 자기 주도 학습인가요? 스터디를 만들어보세요. 자기 주도적으로 학습하는 다양한 사람들을 만날 수 있어요. 여러분이 지금까지 가지고 있던 생각을 깨는 경우가 많을 겁니다. NEXT 교육 커리큘럼과 교수의 권위에 도전하세요. 저는 이 권위에 도전하는 것이 진정한 자기 주도 학습이라 생각합니다.
* 이 말이 말이 된다고 생각하세요? 배움이 고통이 아니라 즐거움이라니요. NEXT에서 학생들과 진행한 스터디에서
4. Java Virtual Machine
Class Loader System
Operating System
Java Threads
Execution
Engine
Run-time
Data Area
Garbage
Collector
Java Application
Java
API
Native
Method
Libraries
5. ByteCode
Link
Verify
Prepare
Class
Load
Class Loader
Resolve Initialize
ByteCode
Class File
Memory
6. Java API Execution
Class Loader
Engine Java Class
System
Runtime Data Areas
PC
Registers
JVM
Stacks
Files
Native
Method
Libraries
Method
Area
Heap Native
Method
Stacks
JVM은 Class Loader를 활용해 컴파일한 Byte Code를 Runtime Data Areas의 Method Area에 실행
가능한 상태로 Load한다.
7. Execution Engine
Class Loader System
Operating System
Java
Threads
Execution
Engine
Run-time
Data Area
Garbage
Collector
Java Application
Java
API
Native
Method
Libraries
8. Java API Execution
Class Loader
Engine Java Class
System
Runtime Data Areas
PC
Registers
JVM
Stacks
Files
Native
Method
Libraries
Method
Area
Heap Native
Method
Stacks
JVM의 Execution Engine은 Method Area에 Load되어 있는 Byte Code 정보를 활용해 자바
프로그램을 실행한다.
Execution Engine은 ByteCode를 한 라인씩 실행(interpreting 방식)한다.
9. Method Area
모든 Thread 들이 공유하는 메모리 영역이다.
자바 프로그램을 실행하기 위한 Class(Type), Method, Field 정보를 가진다.
프로그램에서 공유할 필요가 있는 정보를 가진다.
10. Method Area
모든 Thread 들이 공유하는 메모리 영역이다.
Method Area에 저장되는 정보
Type Information : 클래스와 관련한 모든 정보
Constant Pool : 문자열 상수와 같은 리터럴 상수, Symbolic Reference
Field Information : Field 이름, Data Type, Modifier 등
Method Information : Method 이름, 입출력 DataType, Modifier 등
Class Variables : static으로 선언되는 모든 클래스 변수
Reference to Class Class Loader : 특정 Type을 Load한 ClassLoader 정보를 관리
Reference to Class class
Method Table : Class의 Method에 대한 Direct Reference를 가진다.
11. Java API Execution
Class Loader
Engine Java Class
System
Runtime Data Areas
PC
Registers
JVM
Stacks
Files
Native
Method
Libraries
Method
Area
Heap Native
Method
Stacks
Method Area의 Byte Code 정보를 활용해 프로그램을 실행할 때는 JVM Stacks, Native Method
Stacks 공간을 활용한다.
12. JVM Stacks, Native Method Stacks
각 Thread마다 서로 다른 메모리가 할당된다.
Thread가 시작할 때 생성된다.
각 Thread마다 서로 다른 메모리를 사용하기 때문에 여러 명의 사용자가 동시에 같은 method에
접근해도 문제가 발생하지 않는다.
13. Java API Execution
Class Loader
Engine Java Class
System
Runtime Data Areas
PC
Registers
JVM
Stacks
Files
Native
Method
Libraries
Method
Area
Heap Native
Method
Stacks
JVM은 Heap에서 자바 프로그램을 실행할 때 자바 클래스의 인스턴스와 Array에 대한 메모리를
관리한다.
14. Method
Area
Thread A
(사용자 A)
JVM Stacks
main() Stack frame
Operand Stack
Local Variable
0 args
constant
pool
프로그램을 실행하면 사용자마다 독립적인 JVM Stack이 생성된다.
JVM Stack 안에는 메서드가 호출 될 때마다 Stack Frame이 생성된다.
JVM Stacks
main() Stack frame
Operand Stack
Local Variable
0 args
JVM Heap
Thread B
(사용자 B)
15. JVM Heap과 Method Area는 Thread가 메모리를 공유한다.
Method
Area
constant
pool
JVM Heap
Thread A
(사용자 A)
Thread B
(사용자 B)
16. Method Area는 클래스 ByteCode와 변하지 않는 값이 존재하기 때문에 이슈가 없다.
Thread가 데이터를 공유함으로써 이슈가 있는 부분은 JVM Heap 메모리이다.
Method
Area
constant
pool
JVM Heap
Thread A
(사용자 A)
Thread B
(사용자 B)
17. Heap
모든 Thread 들이 공유하는 메모리 영역이다.
JVM에서 대부분의 메모리 이슈가 집중되어 있는 부분이다.
JVM에서 Memory가 할당, 해제(Garbage Collection)의 이슈는 대부분 Heap 메모리이다.
18. package net.slipp;
public class Adder {
int add(int i, int j) {
return i + j;
}
public static void main(String[] args) {
Adder adder = new Adder();
int result = adder.add(5,2);
System.out.println(result);
}
}
19. package net.slipp;
public class Adder {
int add(int i, int j) {
return i + j;
}
public static void main(String[] args) {
Adder adder = new Adder();
int result = adder.add(5,2);
System.out.println(result);
}
}
JVM Stacks
main() Stack frame
Operand Stack
Local Variable
0 args
1. main method 실행을 위한 stack frame
생성
20. package net.slipp;
public class Adder {
int add(int i, int j) {
return i + j;
}
public static void main(String[] args) {
Adder adder = new Adder();
int result = adder.add(5,2);
System.out.println(result);
}
}
JVM Stacks
main() Stack frame
Operand Stack
Local Variable
0 args
1. main method 실행을 위한 stack frame
생성
2. Adder 생성자를 위한 stack frame 생성
Adder 생성자
Stack frame
Operand Stack
Local Variable
0 this
21. package net.slipp;
public class Adder {
int add(int i, int j) {
return i + j;
}
public static void main(String[] args) {
Adder adder = new Adder();
int result = adder.add(5,2);
System.out.println(result);
}
}
JVM Stacks
main() Stack frame
Operand Stack
Local Variable
0 args
1. main method 실행을 위한 stack frame
생성
2. Adder 생성자를 위한 stack frame 생성
3. 생성자 실행이 끝나면 Adder 생성자를
위한 stack frame 제거
22. JVM Stacks
main() Stack frame
Operand Stack
Local Variable
0 args
package net.slipp;
public class Adder {
int add(int i, int j) {
return i + j;
}
public static void main(String[] args) {
Adder adder = new Adder();
int result = adder.add(5,2);
System.out.println(result);
}
1. main method 실행을 위한 stack frame
생성
2. Adder 생성자를 위한 stack frame 생성
3. 생성자 실행이 끝나면 Adder 생성자를
위한 stack frame 제거
4. add method를 위한 stack frame 생성
}
add method
Stack frame
Operand Stack
Local Variable
2 2
1 5
0 this
23. JVM Stacks
main() Stack frame
Operand Stack
Local Variable
0 args
package net.slipp;
public class Adder {
int add(int i, int j) {
return i + j;
}
public static void main(String[] args) {
Adder adder = new Adder();
int result = adder.add(5,2);
System.out.println(result);
}
1. main method 실행을 위한 stack frame
생성
2. Adder 생성자를 위한 stack frame 생성
3. 생성자 실행이 끝나면 Adder 생성자를
위한 stack frame 제거
4. add method를 위한 stack frame 생성
5. add method에 대한 stack frame 제거
}
24. JVM Stacks
package net.slipp;
public class Adder {
int add(int i, int j) {
return i + j;
}
public static void main(String[] args) {
Adder adder = new Adder();
int result = adder.add(5,2);
System.out.println(result);
}
1. main method 실행을 위한 stack frame
생성
2. Adder 생성자를 위한 stack frame 생성
3. 생성자 실행이 끝나면 Adder 생성자를
위한 stack frame 제거
4. add method를 위한 stack frame 생성
5. add method에 대한 stack frame 제거
6. main method에 대한 stack frame 제거
}
32. Prefix/
Suffix
Operand Type
i integer
l long
s short
b byte
c character
f float
d double
z boolean
a reference
33. JVM Stacks
add method
Stack frame
Operand Stack
Local Variable
2 2
1 5
0 this
load opcode
Local Variable 영역의 값을
Operand Stack 영역으로
복사하는
명령어(instruction)
JVM Stacks
add method
Stack frame
Operand Stack
Local Variable
2 2
1 5
0 this
iload_1
실행 후
0 5
34. JVM Stacks
main method
Stack frame
Operand Stack
Local Variable
1 adder
0 this
store opcode
Operand Stack 영역의 값을
Local Variable 영역으로
이동하는
명령어(instruction)
istore_2
실행 후
0 7
JVM Stacks
main method
Stack frame
Operand Stack
Local Variable
2 7
1 adder
0 this
36. Case 1
public class StringConcatenations {
public String concat1(String start, String end) {
return start + end;
}
public void concat2(StringBuffer start, String end) {
start.append(end);
}
}
37. Case 2
public class StringLiterals {
public static void main(String[] args) {
String one = "Test";
String two = "Test";
String three = "T" + "e" + "s" + "t";
String four = new String("Test");
}
}
39. Case 3
public class MyFor {
public int sum(int[] values) {
int sum = 0;
for (int i = 0; i < values.length; i++) {
sum +=- values[i];
}
return sum;
}
}
41. package net.slipp;
public class Adder {
int add(int i, int j) {
return i + j;
}
public static void main(String[] args) {
Adder adder = new Adder();
int result = adder.add(5,2);
System.out.println(result);
}
}
42. D:next-workspaceworkspacejavabin>javap -c net/slipp/Adder
Compiled from "Adder.java"
public class net.slipp.Adder {
public net.slipp.Adder();
Code:
0: aload_0
1: invokespecial #8 // Method java/lang/Object."<init>":()V
4: return
int add(int, int);
Code:
0: iload_1
1: iload_2
2: iadd
3: ireturn
public static void main(java.lang.String[]);
Code:
0: new #1 // class net/slipp/Adder
3: dup
4: invokespecial #21 // Method "<init>":()V
7: astore_1
8: aload_1
9: iconst_5
10: iconst_2
11: invokevirtual #22 // Method add:(II)I
14: istore_2
15: getstatic #24 // Field java/lang/System.out:Ljava/io/PrintStream;
18: iload_2
19: invokevirtual #30 // Method java/io/PrintStream.println:(I)V
22: return
}
43. D:next-workspaceworkspacejavabin>javap -c Adder.class
Compiled from "Adder.java"
public class Adder {
public Adder();
Code:
0: aload_0
1: invokespecial #8 // Method
java/lang/Object."<init>":()V
4: return
int add(int, int);
Code:
0: iload_1
1: iload_2
2: iadd
3: ireturn
public static void main(java.lang.String[]);
Code:
0: new #1 // class Adder
3: dup
4: invokespecial #21 // Method "<init>":()V
7: astore_1
8: aload_1
9: iconst_5
10: iconst_2
11: invokevirtual #22 // Method add:(II)I
14: istore_2
15: getstatic #24 // Field
java/lang/System.out:Ljava/io/PrintStream;
18: iload_2
19: invokevirtual #30 // Method
java/io/PrintStream.println:(I)V
22: return
}
Execution Engine은
interpreting 방식으로 한번에
한 라인씩 실행한다.
한 라인을 instruction이라고
한다.
instruction은 offset,
opcode(operation code),
피연산자(operand)로
구성된다.
44. JVM Stacks Method
Area
JVM Heap
JVM은 Method Area에 저장되어 있는 Bytecode를 interpreting 방식으로 읽어
실행해 나간다. 먼저 Adder의 main()가 Entry Point가 된다.
main() Stack frame
Operand Stack
Local Variable
0 args
45. public static void main(java.lang.String[]);
Code:
0: new #1 // class net/slipp/Adder
JVM Stacks JVM Heap
main() Stack frame
Operand Stack
Local Variable
0 args
Method Area에 있는 Adder 정보를 활용해 Heap
메모리에 Adder Instance를 생성한 후 Operand Stack
0에 Adder Instance에 대한 reference를 저장
Adder Instance
0 adder
Method
Area
46. public static void main(java.lang.String[]);
Code:
0: new #1 // class net/slipp/Adder
3: dup
JVM Stacks JVM Heap
main() Stack frame
Operand Stack
1 adder
Local Variable
0 args
Operand Stack 0에 Adder Instance에 대한
reference를 Operand Stack 1에 복사한다.
Adder Instance
0 adder
Method
Area
47. public static void main(java.lang.String[]);
Code:
3: dup
4: invokespecial #21 // Method "<init>":()V
JVM Stacks JVM Heap
main() Stack frame
Operand Stack
Local Variable
0 args
Adder 클래스의 기본 생성자(Object 기본
생성자)를 호출한다. Adder 기본 생성자 Stack
Frame이 생성된다.
Adder Instance
0 adder
Adder 생성자
Stack frame
Operand Stack
Local Variable
0 this
Method
Area
48. public net.slipp.Adder();
Code:
0: aload_0
JVM Stacks JVM Heap
main() Stack frame
Operand Stack
Local Variable
0 args
Adder 생성자 Stack Frame의 Local Variable의
index 0의 값을 Operand Stack으로 로드한다.
Adder Instance
0 adder
Adder 생성자
Stack frame
Operand Stack
0 this
Local Variable
0 this
Method
Area
49. public net.slipp.Adder();
Code:
0: aload_0
1: invokespecial #8 // Method java/lang/Object."<init>":()V
JVM Stacks JVM Heap
main() Stack frame
Operand Stack
Local Variable
0 args
Adder Instance에 대한 실질적인 초기화가 이
단계에서 진행된다.
초기화가 완료된
Adder Instance
0 adder
Adder 생성자
Stack frame
Operand Stack
Local Variable
0 this
Method
Area
50. public net.slipp.Adder();
Code:
0: aload_0
1: invokespecial #8 // Method java/lang/Object."<init>":()V
4: return
JVM Stacks JVM Heap
main() Stack frame
Operand Stack
Local Variable
0 args
Adder 기본 생성자에 대한 Stack Frame이 JVM
Stack에서 제거된다.
0 adder
초기화가 완료된
Adder Instance
Method
Area
51. public static void main(java.lang.String[]);
Code:
[…]
4: invokespecial #21 // Method "<init>":()V
7: astore_1
JVM Stacks JVM Heap
main() Stack frame
Operand Stack
Local Variable
0 args
Operand Stack에서 pop한 결과를 Local
Variable의 index 1번에 저장한다.
1 adder
초기화가 완료된
Adder Instance
Method
Area
52. public static void main(java.lang.String[]);
Code:
[…]
7: astore_1
8: aload_1
JVM Stacks JVM Heap
main() Stack frame
Operand Stack
Local Variable
0 args
Variable의 index 1번에 저장된 값을 Operand
Stack에 push한다.
1 adder
초기화가 완료된
Adder Instance
0 adder
Method
Area
60. public static void main(java.lang.String[]);
Code:
[…]
11: invokevirtual #22 // Method add:(II)I
14: istore_2
JVM Stacks JVM Heap
main() Stack frame
Operand Stack
Local Variable
0 args
Operand Stack 값을 pop해서 Local Variable의
index 2번에 저장한다.
1 adder
초기화가 완료된
Adder Instance
constant
pool
1
2
…
5
2 7
Method
Area
61. public static void main(java.lang.String[]);
Code:
[…]
14: istore_2
15: getstatic #24 // Field java/lang/System.out:Ljava/io/PrintStream;
JVM Stacks JVM Heap
main() Stack frame
Operand Stack
Local Variable
0 args
PrintStream에 대한 reference를 얻어 operand
stack index 0에 저장한다.
1 adder
초기화가 완료된
Adder Instance
constant
pool
1
2
…
5
2 7
PrintStream
Instance
0 out
Method
Area
class
variables
62. public static void main(java.lang.String[]);
Code:
[…]
15: getstatic #24 // Field java/lang/System.out:Ljava/io/PrintStream;
18: iload_2
JVM Stacks JVM Heap
main() Stack frame
Operand Stack
1 7
0 out
Local Variable
0 args
Local Variable index 2 값을 operand stack에
push 한다.
1 adder
초기화가 완료된
Adder Instance
class
variables
constant
pool
1
2
…
5
2 7
Method
Area
PrintStream
Instance
63. public static void main(java.lang.String[]);
Code:
[…]
18: iload_2
19: invokevirtual #30 // Method java/io/PrintStream.println:(I)V
JVM Stacks JVM Heap
main() Stack frame
Operand Stack
Local Variable
0 args
PrintStream 인스턴스의 println() 메소드에
operand 값을 인자로 전달한다.
1 adder
초기화가 완료된
Adder Instance
class
variables
constant
pool
1
2
…
5
2 7
Method
Area
PrintStream
Instance
println() Stack frame
Operand Stack
Local Variable
1 7
0 this
64. 애플리케이션을 종료한다.
JVM Stacks JVM Heap
class
variables
constant
pool
1
2
…
5
public static void main(java.lang.String[]);
Code:
[…]
19: invokevirtual #30 // Method java/io/PrintStream.println:(I)V
22: return
초기화가 완료된
Adder Instance
시간이 지나면 Garbage
Collector에 의해 GC
대상이 된다.
Method
Area
PrintStream
Instance
66. package net.slipp;
public class Adder {
private int i;
private int j;
Adder(int i, int j) {
this.i = i;
this.j = j;
}
public int add() {
return i + j;
}
public static void main(String[] args) {
Adder adder = new Adder(5, 2);
int result = adder.add();
System.out.println(result);
}
}
67. D:next-workspaceworkspacejavabin>javap -c net/slipp/Adder
Compiled from "Adder.java"
public class net.slipp.Adder {
net.slipp.Adder(int, int);
Code:
0: aload_0
1: invokespecial #11 // Method java/lang/Object."<init>":()V
4: aload_0
5: iload_1
6: putfield #14 // Field i:I
9: aload_0
10: iload_2
11: putfield #16 // Field j:I
14: return
public int add();
Code:
0: aload_0
1: getfield #14 // Field i:I
4: aload_0
5: getfield #16 // Field j:I
8: iadd
9: ireturn
public static void main(java.lang.String[]);
Code:
0: new #1 // class net/slipp/Adder
3: dup
4: iconst_5
5: iconst_2
6: invokespecial #26 // Method "<init>":(II)V
9: astore_1
10: aload_1
11: invokevirtual #28 // Method add:()I
14: istore_2
15: getstatic #30 // Field
java/lang/System.out:Ljava/io/PrintStream;
18: iload_2
19: invokevirtual #36 // Method java/io/PrintStream.println:(I)V
22: return
}
68. public static void main(java.lang.String[]);
Code:
0: new #1 // class net/slipp/Adder
3: dup
JVM Stacks Method
Area
JVM Heap
main() Stack frame
Operand Stack
1 adder
Local Variable
0 args
Adder Instance
0 adder
78. public class Adder {
int add(int i, int j) {
return i + j;
}
}
JVM Stacks
main() Stack frame
Operand Stack
Local Variable
1 adder
0 args
add() Stack frame
Operand Stack
1 2
0 5
Local Variable
2 2
1 5
0 adder
사용자 1 = Thread 1
JVM Stacks
main() Stack frame
Operand Stack
Local Variable
1 adder
0 args
add() Stack frame
Operand Stack
1 2
0 5
Local Variable
2 2
1 5
0 adder
사용자 2 = Thread 2
79. JVM Stacks JVM Heap
main() Stack frame
Operand Stack
Local Variable
1 adder
0 args
constant
pool
1
2
…
5
Adder Instance
int i = 5
int j = 2
Method
Area
80. JVM Heap
Adder Instance
int i = 5
int j = 2
사용자 1 = Thread 1
사용자 2 = Thread 2
public class Adder {
private int i;
private int j;
Adder(int i, int j) {
this.i = i;
this.j = j;
}
}
81. Java API Execution
Class Loader
Engine Java Class
System
Runtime Data Areas
PC
Registers
JVM
Stacks
Files
Native
Method
Libraries
Method
Area
Heap Native
Method
Stacks
JVM의 Stacks 영역은 Thread 별로(사용자) 생성된다. 따라서 각 Stacks 영역 사이에는
영향을 미치지 않는다. 이를 Thread Safe하다고 한다.
JVM의 Heap 영역은 모든 Thread가 공유한다. 따라서 Heap에 존재하는 Object의 상태
값은 Thread 사이에 영향을 받는다. 이를 Thread Safe하지 않다고 한다.
82. public class Adder {
int add(int i, int j) {
return i + j;
}
public static void main(String[] args)
{
Adder adder = new Adder();
int result = adder.add(5,2);
}
}
사용자 1 = Thread 1
사용자 2 = Thread 2
Adder는 Heap 영역에서 관리하는 상태 값은 없다. 모든 값은 각 Thread별로 생성되는
Stacks에서 관리한다.
위 Adder 클래스는 Heap 영역에 인스턴스 하나를 생성한 후 모든 Thread에서
재사용할 수 있다.
83. public class Adder {
private int i;
private int j;
Adder(int i, int j) {
this.i = i;
this.j = j;
}
public int add() {
return i + j;
}
public static void main(String[] args) {
Adder adder = new Adder(5, 2);
int result = adder.add();
System.out.println(result);
}
}
사용자 1 = Thread 1
사용자 2 = Thread 2
Adder는 Heap 영역에서 i, j에 대한 상태 값을 관리하고 있다. 즉, Thread Safe하지 않다.
위 Adder 클래스는 각 Thread별로 독립적으로 실행하려면 매번 인스턴스를 생성해야 한다.
85. public class Calculator {
int add(int i, int j) {
i = 5;
j = 3;
return i + j;
}
public static void main(String[] args) {
Calculator calculator = new Calculator();
int i = 3;
int j = 2;
System.out.println("before i : " + i);
System.out.println("before j : " + j);
calculator.add(i, j);
System.out.println("after i : " + i);
System.out.println("after j : " + j);
}
}
86. public static void main(String[] args) {
Calculator calculator = new Calculator();
int i = 3;
int j = 2;
calculator.add(i, j);
JVM Stacks Method
Area
JVM Heap
main() Stack frame
Operand Stack
Local Variable
2
3
1 calculator
0 args
초기화가 완료된
add() Stack frame Calculator Instance
Operand Stack
Local Variable
3
2
}
87. int add(int i, int j) {
i = 5;
j = 3;
return i + j;
JVM Stacks Method
Area
JVM Heap
main() Stack frame
Operand Stack
Local Variable
3 2 2
3
1 calculator
0 args
초기화가 완료된
add() Stack frame Calculator Instance
Operand Stack
Local Variable
1 3
0 calculator
2
2
}
88. int add(int i, int j) {
i = 5;
j = 3;
return i + j;
JVM Stacks Method
Area
JVM Heap
main() Stack frame
Operand Stack
Local Variable
3 2 3
3
1 calculator
0 args
초기화가 완료된
add() Stack frame Calculator Instance
Operand Stack
Local Variable
1 5
0 calculator
2
2
}
89. Call by value
자바의 기본 자료형(primitive type)은 call by value에 의해서 동작한다.
즉, 메소드를 호출할 때 전달되는 인자의 값이 복사된다.
90. public class Student {
String name;
public Student(String name) {
this.name = name;
}
}
public class MessageRenderer {
public void callByReference(Student student) {
student.name = "예은";
}
public static void main(String[] args) {
Student student = new Student("주한");
MessageRenderer mr = new MessageRenderer();
mr.callByReference(student);
System.out.println("Name : " + student.name);
}
}
Case 1
91. JVM Stacks Method
Area
JVM Heap
main() Stack frame
Operand Stack
Local Variable
1 student
0 args
name = “주한”
Student Instance
callByReference()
Stack frame
Operand Stack
Local Variable
Case 1
public static void main(String[] args) {
Student student = new Student("주한");
MessageRenderer mr = new MessageRenderer();
mr.callByReference(student);
System.out.println("Name : " + student.name);
}
92. JVM Stacks Method
Area
JVM Heap
main() Stack frame
Operand Stack
Local Variable
1 student
0 args
name = “주한”
Student Instance
callByReference()
Stack frame
Operand Stack
Local Variable
Case 1
public static void main(String[] args) {
Student student = new Student("주한");
MessageRenderer mr = new MessageRenderer();
mr.callByReference(student);
System.out.println("Name : " + student.name);
}
public void callByReference(Student student) {
student.name = "예은";
}
0 student
93. JVM Stacks Method
Area
JVM Heap
main() Stack frame
Operand Stack
Local Variable
1 student
0 args
name = “예은”
Student Instance
callByReference()
Stack frame
Operand Stack
Local Variable
Case 1
public static void main(String[] args) {
Student student = new Student("주한");
MessageRenderer mr = new MessageRenderer();
mr.callByReference(student);
System.out.println("Name : " + student.name);
}
public void callByReference(Student student) {
student.name = "예은";
}
0 student
94. JVM Stacks Method
Area
JVM Heap
main() Stack frame
Operand Stack
Local Variable
1 student
0 args
name = “예은”
Student Instance
Case 1
public static void main(String[] args) {
Student student = new Student("주한");
MessageRenderer mr = new MessageRenderer();
mr.callByReference(student);
System.out.println("Name : " + student.name);
}
95. public class Student {
String name;
public Student(String name) {
this.name = name;
}
}
public class MessageRenderer {
public void callByReference(Student student) {
student = new Student("예은");
}
public static void main(String[] args) {
Student student = new Student("주한");
MessageRenderer mr = new MessageRenderer();
mr.callByReference(student);
System.out.println("Name : " + student.name);
}
}
Case 2
96. JVM Stacks Method
Area
JVM Heap
main() Stack frame
Operand Stack
Local Variable
1 student
0 args
name = “주한”
Student Instance
callByReference()
Stack frame
Operand Stack
Local Variable
Case 2
public static void main(String[] args) {
Student student = new Student("주한");
MessageRenderer mr = new MessageRenderer();
mr.callByReference(student);
System.out.println("Name : " + student.name);
}
97. JVM Stacks Method
Area
JVM Heap
main() Stack frame
Operand Stack
Local Variable
1 student
0 args
name = “주한”
Student Instance
callByReference()
Stack frame
Operand Stack
Local Variable
Case 1
public static void main(String[] args) {
Student student = new Student("주한");
MessageRenderer mr = new MessageRenderer();
mr.callByReference(student);
System.out.println("Name : " + student.name);
}
public void callByReference(Student student) {
student = new Student(“예은”);
}
0 student
98. JVM Stacks Method
Area
JVM Heap
main() Stack frame
Operand Stack
Local Variable
1 student
0 args
name = “주한”
Student Instance
callByReference()
Stack frame
Operand Stack
Local Variable
Case 1
public static void main(String[] args) {
Student student = new Student("주한");
MessageRenderer mr = new MessageRenderer();
mr.callByReference(student);
System.out.println("Name : " + student.name);
}
public void callByReference(Student student) {
student = new Student(“예은”);
}
0 student
name = “예은”
Student Instance
99. JVM Stacks Method
Area
JVM Heap
main() Stack frame
Operand Stack
Local Variable
1 student
0 args
name = “주한”
Student Instance
Case 1
public static void main(String[] args) {
Student student = new Student("주한");
MessageRenderer mr = new MessageRenderer();
mr.callByReference(student);
System.out.println("Name : " + student.name);
}
100. Call by reference
자바의 모든 객체(인스턴스)는 call by reference에 의해서 동작한다.
즉, 메소드를 호출할 때 전달되는 인자는 값이 아니라 참조하고 있는 주소 값이 전달된다.