Arsitektur Aplikasi Perangkat Enterprise #5 Antonius Rachmat C, S.Kom, M.Cs
Enterprise Demand Company A Mobile Employees
Consumers, Partners
Company B Mobile Employees
Consumers, Partners
Customers Partners Suppliers
Enterprise Application Inside
Application Platforms Today Browser Apps
GUI Services
Web Services Apps
Transaction Services
Local Apps
Web Scripting
Data Access
Standard Library Runtime Environment Operating System
Other Apps
More
What is Microsoft .Net? .NET is microsoft technolgy and platform for developing and integrating services in the digital world To unify Desktop, Web, and Mobile programming
Diperkenalkan oleh Microsoft sejak Feb 2002
.NET FRAMEWORK Bersifat independen dalam hal bahasa Aplikasi dapat dikembangkan di beberapa bahasa yang didukung oleh .NET: C# Managed Extensions for C++ Java - Visual J# .NET JavaScript - JScript .NET Perl Pascal, Delphi PHP Smalltalk
Programmer dapat memilih salah satu bahasa yang paling dikuasainya.
Mampu dijalankan beberapa platform (tidak semua)
Keuntungan .NET
.NET Blueprint
Sales Data Service Corporate Fullfilment Service
Visual Studio.NET Applications Using Your Service Smart Clients .NET FW Windows
Smart Devices .NET FW
Simple Browsers
Your Internal Services
Your application and web service .NET Framework Windows CE, XP, 2000, .NET Open Internet Protocols XML, XSLT, XSD, SOAP, DISCO, UDDI, XHTML, HTTP, SSL, WAP
.NET Enterprise Servers SQL Server BizTalk Server Application Center Commerce Server Host Integration Server Internet Security and Acceleration Exchange Server
.NET FW
Windows
Building Block Services Passport – Identity Service Calendaring Service … [myServices]
3rd Party Web Services Geographic Mapping Service Credit Card Statement Service … [ActiveX Paradigm]
.NET Framework in General
.NET Framework 4.0
.NET Framework class System.Web Services Description
UI HtmlControls
Discovery
WebControls
System.WinForms Design
ComponentModel
System.Drawing
Protocols Caching
Security
Drawing2D
Printing
Configuration
SessionState
Imaging
Text
System.Data ADO.NET Design
System.Xml
SqlClient OleDB, odbc, Oracle
XmlDocument
Serialization
Xslt/XPath
Reader/Writers
System Collections
IO
Configuration
Runtime InteropServices
Security
Net
ServiceProcess
Text
Reflection
Diagnostics
Remoting
Globalization
Resources
Threading
Serialization
.NET Compact Framework class System.Web Services Description
UI HtmlControls
Discovery
WebControls
System.WinForms Design
ComponentModel
System.Drawing
Protocols Caching
Security
Drawing2D
Printing
Configuration
SessionState
Imaging
Text
System.Data
System.Xml
ADO.NET
SqlClient
XmlDocument
Serialization
Design
SqlServerCe
Xslt/XPath
Reader/Writers
System Collections
IO
Configuration
Runtime InteropServices
Security
Net
ServiceProcess
Text
Reflection
Diagnostics
Remoting
Globalization
Resources
Threading
Serialization
Common Language Runtime Bagian utama dari framework yang akan mengkompilasi dan mengeksekusi program yang ditulis dengan bahasa yang mendukung .NET Compilation process Pertama program di compile menjadi Microsoft Intermediate Language (MSIL) / Common Intermediate Language (CIL) Mendefinisikan instruksi untuk CLR
Kemudian MSIL code diterjemahkan kedalam machine code Machine code untuk platform yang khusus
Mengapa dua proses kompilasi ? Agar platformnya bersifat independence .NET Framework dapat diinstal di platform berbeda Mengeksekusi program .NET tanpa modifikasi kode-nya
Language independence .NET program tidak terikat dengan bahasa tertentu Komponen yang lama dan baru dapat terintegrasi
MSIL HelloWorld: .assembly hello {}
.assembly extern mscorlib {} .method static public void main() il managed { .entrypoint .maxstack 1 ldstr "Hello World from IL!" call void [mscorlib]System.Console::WriteLine(class System.String) ret }
Common Language Runtime Keuntungan lain dari CLR Execution-management features Manages memory Programmer lebih berkonsentrasi pada program logic
CLR menyediakan JIT compilation. JIT hanya akan mengkompilasi method-method yang memang digunakan dalam suatu bagian aplikasi pada saat tertentu, dan hasil kompilasi ini sendiri di cache di dalam mesin dan akan dikompile kembali jika memang ada perubahan pada kode aplikasi kita. Jadi tidak semua method diload ke-memori pada saat yang sama
CLR disimpan pada file: mscoree.dll C:\windows\System32
Common Language Runtime Base Class Library Support Thread Support
COM Marshaler
Type Checker
Exception Manager
Security Engine
Debug Engine
IL to Native Compilers
Code Manager Class Loader
Garbage Collector
CLR Execution Model VB
Native Code
C#
Install time Code Gen
Script
...
Assembly: MSIL + Metadata
Development Deployment Common Language Runtime
JIT Code Gen
Native Code
Compiling & Executing Managed Code Compilation Source Code
Language Compiler
Microsoft Intermediate Language (MSIL)
The first time each method is called
Native Code
JIT Compiler Execution
Data Types in the CLR The CLR mendefinisikan Common Type System (CTS) All languages built on the CLR use the CTS (managed code)
Ada 2 kategori: Value types: Relatively simple types Allocated on the stack
Reference types: More complex types Allocated on the heap Destroyed through garbage collection
Illustrating the Common Type System Object Class Interface
ValueType Byte
Int16
UInt16
Single
Char
Int32
UInt32
Double
String
Int64
UInt64
Delegate
Decimal
Structure
Others
Boolean
Others
Array
Reference Types
Value Types
Enum
CTS Data Type
.NET Class Library Sering disebut sebagai Base Class Library. Class library bersifat berorientasi objek yang akan menyediakan types dan fungsi-fungsi managed code. Dengan BCL kita dapat membuat: Aplikasi Aplikasi Aplikasi Aplikasi Aplikasi
console berbasis windowd (Windows Form) ASP.NET (berbasis web) Web Services XML berbasis Windows Services
.NET Class Library (2) Tampilan ILDASM – assembly view
.NET assembly Private assemblies are required to be located in application’s directory or subdirectory The disadvantage is that each time a copy of the Assembly is created which in turn occupies more memory and reduces the performance Output: .dll Must be imported
Shared assemblies installing an assembly: gacutil.exe –i MyAssembly.dll
Two or more assemblies of the same name can coexist in the GAC (must have different versions) the end of "DLL hell"
Adding external assembly to ur application (on C#)
Obfuscation Entity renaming changing names of namespaces, classes, methods, properties, fields, enumerations
Control flow obfuscation modifying the original code (e.g. transforming if or while statements by using goto statement)
Removal of unused members String encryption Breaking IL Disassembler injecting code into the obfuscated assembly that is designed to break IL Disassembler so that it won’t open the assembly at all
Compiling into native code
Hasil Obfuscation
C++ .NET C++ with Managed Extensions can be used to create .NET applications Managed C++ provides: Garbage collection support Built-in support for interfaces, properties, and events Access to all other CLR features
C++ can still create native binaries if desired All other Visual Studio.NET languages produce only MSIL
Database Access in .NET In .NET there is ADO.NET “connectionless”
Client DataSet
Data Adapter Command
DataSetCommand
Connection
Data Source
DataReader
Managed Provider
ASP.NET (Server-Side Scripting) ASP.NET Architecture: (1) get a.apx
Client (4) HTTP file
IIS Web Server
(2) process
(3) result
.NET Assembly
Other Assemblies
.NET Engine Database
.NET framework .NET Framework 1.1 was included in Windows Server 2003 and was an optional component of Windows XP Service Pack 1 Redistributable packages (dotnetfx.exe) .NET Framework 1.1 23.1 MB Windows 98/Me/NT/2000/XP/2003, IE 5.01
.NET Framework 2.0 22.4 MB Windows 98/Me/NT/2000/XP SP2/2003, IE 5.01 Windows Installer 3.0 disk space: 280 MB (x86), 610 MB (x64)
.NET 3.5 -> 197 MB
MONO Mono project (http://www.mono-project.com) support for .NET client and server applications on Linux, Solaris, Mac OS X, Windows and Unix sponsored by Novell
LGPL (Lesser General Public Licence) supported systems: GNU/Linux, NetBSD, FreeBSD, 120,000 lines of C code and 600,000 lines of C# code.
Cygwin/Mingw32, Mac OS X, Solaris, AIX GPL (General Public Licence) Official international standards: ECMA-334: The C# Language Specification ECMA-335: The Common Language Infrastructure (CLI)
Mono Architecture ASP.NET
ADO.NET
Windows.Form
MySQL/Postgress
Evolution#
Mozilla
Novell iFolder
Apache Mono
Gtk#
Novell LDAP
Gnome#
Java Compatibility
ZipLib
Microsoft Compatibility Libraries
Mono Libraries
Mono Runtime (Implementation of ECMA #335)
Windows Phone 7 Architecture
Java 2 Platform Dimulai tahun 1995 pada browser HotJava – Netscape Platform diperkenalkan pada June, 1999 WORE – Write Once Run Everywhere
Java 2 Platform
J2SE Platform
Java system overview
Yang dibutuhkan? J2RE untuk menjalankan Java. J2RE akan berisi Java Virtual Machine.
J2SDK untuk mendevelop Java. J2SDK akan berisi JVM dan SDK
J2ME untuk mendevelop aplikasi Mobile J2EE untuk mendevelop aplikasi Enterprise J2EE berisi seluruh komponen Java 2 Platform
Proses Kompilasi Pada kompilasi Java, terdapat 2 bagian penting yaitu: Java Compiler dan Java Interpreter Java compiler mengenerate bytecode (sekumpulan instruksi yang me-ressemble kode mesin, tetapi tidak spesifik pada prosesor) yang bersifat “cross-platform intermediary, halfway between source code and machine language”. Java interpreter akan meng-interpret Java bytecode yang ada untuk eksekusi program. Kekurangan dari bytecode terletak pada kecepatan eksekusi, karena tidak bersifat native
Proses Kompilasi Win32 Kode Java
Java bytecode HP-UX Intermediate compilation Runtime VM Intepretation
Solaris
Mac
The Java Virtual Machine An abstract computing machine that executes bytecode programs An instruction set and the meaning of those instructions An algorithm to verify the class file
Interpreter Simple, compact Slow
Just-in-time compilation Hanya mengkompilasi “bagian” yg dibutuhkan saja
A Bytecode Example public class X { public static void main(String[] args) { add(1, 2); } public static int add(int a, int b) { return a+b; } }
public static void main(java.lang.String[]); Code: 0: iconst_1 1: iconst_2 //Method add:(II)I 2: invokestatic #2; 5: 6: return public static int add(int,int); Code: 0: iload_0 1: iload_1 2: iadd 3: ireturn
pop
Introduction to the JVM JVM is a component of the Java system that interprets and executes the instructions in our class files.
Memory configuration by the JVM.
Introduction to the JVM (Cont’d) Each instance of the JVM has one method area, one heap, and one or more stacks - one for each thread When JVM loads a class file, it puts its information in the method area As the program runs, all objects instantiated are stored in the heap The stack area is used to store activation records as a program runs
Introduction to the JVM (Cont’d)
Content of Memory Blocks at runtime.
The Class Loader Subsystem The class loader performs three main functions of JVM, namely: loading, linking and initialization The linking process consists of three sub-tasks, verification, preparation, and resolution
Class loading process.
Tahap Compile & Execute Loading means reading the class file for a type, parsing it to get its information, and storing the information in the method area. Verification is the process of ensuring that binary representation of a class is structurally correct In preparation, the JVM allocates memory for the class (i.e static) variables and sets them to default initial values. Resolution is the process of replacing symbolic names for types, fields and methods used by a loaded type with their actual references. Class initialization, This is the process of setting class
variables to their proper initial values - initial values desired by the programmer.
J2EE Stands for “Java 2, Enterprise Edition” Superset of Java 2 Standard Edition (J2SE) J2EE (1.4+) is an infrastructure specification for: Components ("Beans") Data Source Connectivity XML and Messaging Web Pages and Web Services
Class-class Java Java Servlets (menggunakan Apache-Tomcat): javax.servlet JSP (menggunakan Apache-Tomcat): javax.servlet.jsp EJB (menggunakan JBoss): javax.ejb.* JMS: javax.jms.* JDBC (J2SDK): java.sql.*, javax.sql.* JNDI (J2SDK): javax.naming.* JTA / JTS: java.transaction.* JavaMail (Java MailAPI): javax.mail.* XML: javax.xml.* JavaNet: java.net
J2EE Architecture
4 Aplikasi Java Applications: program standalone di komputer, dari aplikasi console sampai dengan GUI yang kompleks yang menggunakan javax.swing Applet: program Java yang dijalankan di web browser dengan menggunakan HTML. Servlet: program yang melakukan generating isi webpage namun berjalan di java-enabled web server yang kemudian akan dikirimkan hasilnya ke client. JSP / JSF: aplikasi web yang berjalan di sisi server.
J2EE Server Technologies Servlets Server side Java code
Java Server Pages (JSP) dan Java Server Faces Server side Java code
Enterprise JavaBeans (EJB) Java server components that encapsulate business logic to be shared across the enterprise
Database Access in Java Java provides JDBC to access relational data Application
Statement Resultset
Prepared Statement Callable Statement
Connection
Driver Manager JDBC/ ODBC Bridge
ODBC Driver
ODBC DB
Java Server Pages and Servlets Java also allows for server-side scripting JSPs are based on Servlets (1) get a.jsp
Client (5) HTTP file
Web Server
(2) process
Other Components
JSP
(3) gen. Servlet Servlet
Impl. (4) result
Servlet Database
JVM
Perbandingan J2EE dan .NET Framework
A typical .NET Enterprise Solution
IIS on W2k Server Browser
Windows Client
ASP .NET
.NET managed component
SQL Server
A typical J2EE Enterprise Solution
Java App Server Servlet EJB JSP
Browser
Java Client
DB Server
The .NET Framework Browser Apps
Windows Forms
Web Services Apps
Enterprise Services
ASP.NET
Local Apps
Other Apps
ADO.NET
More
.NET Framework Class Library Common Language Runtime Windows
The Java Environment Browser Apps
Swing
Web Services Apps
Enterprise JavaBeans
JavaServer Pages
Local Apps
JDBC
Standard Java Packages Java Virtual Machine (VM) Windows, Solaris, Linux, others
Other Apps
More
RMI Client IIOP Client HTTP Client
JMS EJB Container HTTP Engine
.NET App SOAP Client HTTP Client
RDBMS
EJB Container
IIS – HTTP Engine
JSP Servlet Servlet Container J2EE Server
Component Component Component CLR Host Component Component Component Comp. Services CLR Host ASMX Controls ASPX ASP.NET CLR Platform
Message Queue CORBA Server Other Resource
RDBMS Message queue Other Server Other Resource
J2EE Solutions vs Microsoft .Net Solutions Both multi-tiered, similar computing technologies Both support “standards” Both offer different tools & ways to achieve the same goal. Very difficult to compare and qualify the comparison because each has its own advantages & disadvantages.
Comparing the stacks Enterprise solutions …
…
Third party extensions
Extensions:
P&P blocks
Phoenix, Tiles, Java Faces
ASP.Net
JSP
Base Class Library
J2EE Class Library
CLR
Java runtime
Win32 / Linux
J2EE App Servers Websphere, Weblogic, Tomcat, etc.
VB
MSMQ, COM+, IIS, WMI, AD, ADAM, Indexing, UDDI, etc.
JMS
Apache
Win32, Unix, Linux
BEA Weblogic
C++
JDBC
Java
C#
ADO.NET
Webshpere Studio
Servlets
Eclipse
Perl
Visual Studio.net / Mono
Python
Struts
CLR vs JVM C#
VB .Net
Managed Lots of other C/C++ Languages
Java
MSIL
Byte Codes
CLR CTS GC Security Runtime Services
JRE (JVM) GC Security Runtime Services
Windows OS
Mac Win Unix Linux
Both are ‘middle layers’ between an intermediate language & the underlying OS
JVM vs. CLR JVM
CLR
Managed execution environment
X
X
Garbage Collection
X
X
Metadata and Bytecode
X
X
Platform-abstraction class library
X
X
Runtime-level security
X
X
Runs across hardware platforms
X
?
Choosing between Java/J2EE and .Net The ultimate choice usually depends not on technical superiority, but on: cultural/”religious”/political preferences Customer preference Vendor relations Skill set of your developers You are most likely to be developing in both environments for the foreseeable future Look out for “The third way”: Linux, Apache, MySQL, PHP, …
NEXT Database for Enterprise: JDBC, ADO.NET dan LINQ