Sejarah Dan+pengertian Java

  • Uploaded by: Muhammad Faiz
  • 0
  • 0
  • January 2021
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Sejarah Dan+pengertian Java as PDF for free.

More details

  • Words: 3,608
  • Pages: 13
Loading documents preview...
Sejarah dan Pengertian Java

Java

adalah bahasa pemrograman berorientasi obyek, sehingga untuk

memperoleh pemahaman yang lebih baik terhadap materi pada bab-bab selanjutnya, perlu disampaikan beberapa topik mengenai pemrograman berorientasi obyek yang berhubungan langsung dengan topik-topik yang akan dibahas, diantaranya mengenai konsep pemrograman berorientasi obyek, inheritance dan constructor. Topik-topik lain dalam pemrograman berorientasi obyek akan dibahas lebih lanjut bila memang diperlukan. Pemrograman berorientasi obyek merupakan suatu konsep pemrograman dengan mengambil konsep obyek sebagai komponen dasar dari pemrogramannya. Obyek merupakan suatu kesatuan komponen dan struktur yang di dalamnya berisi attribut yang selanjutnya dinamakan dengan member dan method yang merupakan kumpulan fungsional dari suatu obyek. Sebagai suatu analogi obyek, kita ambil obyek mobil dan lainnya. Obyek mobil ini mempunyai method berupa maju, mundur, jalan, berhenti, dan berputar. Dengan demikian dapat dikatakan bahwa obyek mempunyai sifat-sifat, yaitu: •



Member atau sering juga disebut dengan attribut yang menjelaskan variable, parameter atau keadaan (state) dari suatu obyek, misalkan pada obyek mobil terdapat member berupa roda, kemudi, seperti yang disebutkan di atas. Method atau sering juga disebut dengan behavior yang menjelaskan perilaku, kegiatan atau kerja dari suatu obyek, misalkan pada obyek mobil terdapat method maju, mundur, berhenti, seperti yang disebutkan diatas.

Menulis program berbasis obyek menggunakan bahasa Java dilakukan dengan cara membentuk sebuah class, menentukan variabel member dan menentukan method. Pembentukan class dari suatu obyek ini dinamakan dengan enkapsulisasi. Untuk menggambarkan suatu obyek digunakan suatu diagram yang dinamakan dengan class diagram. • •

Nama Class Member



Method

Bahasa pemrograman Java pertama lahir dari The Green Project, yang berjalan selama 18 bulan, dari awal tahun 1991 hingga musim panas 1992. Proyek tersebut belum menggunakan versi yang dinamakan Oak. Proyek ini dimotori oleh Patrick Naughton, Mike Sheridan, James Gosling dan Bill Joy, beserta sembilan pemrogram lainnya dari Sun Microsystems. Salah satu hasil proyek ini adalah maskot Duke yang dibuat oleh Joe Palrang. Pertemuan proyek berlangsung di sebuah gedung perkantoran Sand Hill Road di Menlo Park. Sekitar musim panas 1992 proyek ini ditutup dengan menghasilkan sebuah program Java Oak pertama, yang ditujukan sebagai pengendali sebuah peralatan dengan teknologi layar sentuh (touch screen), seperti pada PDA sekarang ini. Teknologi baru ini dinamai “*7″ (Star Seven).Setelah era Star Seven selesai, sebuah anak perusahaan TV kabel tertarik ditambah beberapa orang dari proyek The Green Project. Mereka memusatkan kegiatannya pada sebuah ruangan kantor di 100 Hamilton Avenue, Palo Alto.Perusahaan baru ini bertambah maju: jumlah karyawan meningkat dalam waktu singkat dari 13 menjadi 70 orang. Pada rentang waktu ini juga ditetapkan pemakaian Internet sebagai medium yang menjembatani kerja dan ide di antara mereka. Pada awal tahun 1990-an, Internet masih merupakan rintisan, yang dipakai hanya di kalangan

akademisi dan militer.Mereka menjadikan perambah (browser) Mosaic sebagai landasan awal untuk membuat perambah Java pertama yang dinamai Web Runner, terinsipirasi dari film 1980-an, Blade Runner. Pada perkembangan rilis pertama, Web Runner berganti nama menjadi Hot Java.Pada sekitar bulan Maret 1995, untuk pertama kali kode sumber Java versi 1.0a2 dibuka. Kesuksesan mereka diikuti dengan untuk pemeritaan pertama kali pada surat kabar San Jose Mercury News pada tanggal 23 Mei 1995. Sayang terjadi perpecahan di antara mereka suatu hari pada pukul 04.00 di sebuah ruangan hotel Sheraton Palace. Tiga dari pimpinan utama proyek, Eric Schmidt dan George Paolini dari Sun Microsystems bersama Marc Andreessen, membentuk Netscape.Nama Oak, diambil dari pohon oak yang tumbuh di depan jendela ruangan kerja “bapak java”, James Gosling. Nama Oak ini tidak dipakai untuk versi release Java karena sebuah perangkat lunak sudah terdaftar dengan merek dagang tersebut, sehingga diambil nama penggantinya menjadi “Java”. Nama ini diambil dari kopi murni yang digiling langsung dari biji (kopi tubruk) kesukaan Gosling.Versi Awal Versi awal Java ditahun 1996 sudah merupakan versi release sehingga dinamakan Java Versi 1.0. • •

Java versi ini menyertakan banyak paket standar awal yang terus dikembangkan pada versi selanjutnya: Java.lang : Peruntukan kelas elemen-elemen dasar.



Java.io : Peruntukan kelas input dan output, termasuk penggunaan berkas.



Java.util : Peruntukan kelas pelengkap seperti kelas struktur data dan kelas kelas penanggalan



Java.net : Peruntukan kelas TCP/IP, yang memungkinkan berkomunikasi dengan komputer lain menggunakan jaringan TCP/IP.



Java.awt : Kelas dasar untuk aplikasi antarmuka dengan pengguna (GUI)



Java.applet : Kelas dasar aplikasi antar muka untuk diterapkan pada penjelajah web.

Struktur Dasar Pemrograman Java

Seperti halnya bahasa pemrograman lainnya, java memiliki struktur dasar yang wajid diketahui sebelum belajar lebih jauh tentang pemrograman java. Terdapat beberapa struktur pemrograman java yaitu Comments, Modifiers, Statements, Blocks, Classes, Methods, dan Reserved Words. Untuk mengenal lebih jauh, berikut adalah pengenalan singkat struktur program java : 1. Comments Comments digunakan untuk memberikan keterangan atau penjelasan suatu baris program, struktur comments tidak akan di kompilasi oleh compiler. Lambang untuk comments adalah double slash (//) untuk memberikan penjelasan suatu baris, sedangkan lambang /* dan */ untuk memberikan penjelasan satu baris atau lebih. Contoh Comments : public class testcomments { public static void main(String [] args){ /* System.out.println Akan Mencetak "Akan Mencetak" */ //System.out.println("tidak akan mencetak");

System.out.println("akan mencetak"); } }

Pada contoh di atas, baris dalam lambang comments tidak akan di kompilasi oleh compiler.

2. Modifiers Modifiers digunakan untuk menentukan penggunaan dari suatu data, methods dan class. Contoh modifiers adalah public, static, private, final, abstract dan protected. 3. Statements Statements merupakan baris perintah atau kumpulan perintah. Setiap statement pada java selalu diakhiri dengan titik koma (;) 4. Blocks Blocks digunakan untuk membentuk suatu grup statements. Blocks diawali dengan kurung kurawal ( {} ). 5. Classes Classes merupakan inti dari program java. Suatu class merupakan “blueprint” untuk menciptakan suatu object.

Contoh program: /* Program Bilangan Genap-Ganjil *Oleh Mohamad Iqbal - 10508114 */ import javax.swing.*; public class nilai_akhir{ public static void main(String[] args){ double nilai; char index; int tugas=Integer.valueOf(JOptionPane.showInputDialog("Input Nilai Tugas :")); int quiz=Integer.valueOf(JOptionPane.showInputDialog("Input Nilai Quiz :")); int uts=Integer.valueOf(JOptionPane.showInputDialog("Input Nilai Uts :")); int uas=Integer.valueOf(JOptionPane.showInputDialog("Input Nilai Uas :")); nilai=(tugas*0.2)+(quiz*0.1)+(uts*0.3)+(uas*0.4); if (nilai>=80 && nilai<=100) index='A'; else if (nilai>68 && nilai<=80) index='B'; else if (nilai>55 && nilai<=68) index='c'; else if (nilai>45 && nilai<=55) index='D'; else index='E'; System.out.println("Nilai Tugas : "+ tugas); System.out.println("Nilai Quiz : "+ quiz); System.out.println("Nilai Uts : "+ uts); System.out.println("Nilai Uas : "+ uas); System.out.println("Index : "+ index);

} }

Chapter 1. Introduction to J2EE Servlets and Java Server Pages • •

What is J2EE? Java Server Pages



Java Servlets: A bit of history



JSP Syntax



An Example with JBoss and Tomcat



MyGreeting: A simple web application



Exercises After completing this chapter, the student will be able to •

Goals



explain Servlets and Java Server Pages (JSPs) and their roles in developing web applications. have JBoss deploy with the Tomcat container in an integrated virtual machine.



create JSPs for use in systems producing dynamically generated HTML.

Prerequisite The student will need to be famliar with web browsers, an understanding of HTML, and familiarity s with Java and its use in programming. Objectives

This chapter is presented to provide an understanding of the role that Servlets and Java Server Pages play in the web application development process and to understand what J2EE is.

What is J2EE? J2EE (Java 2 Enterprise Edition) is a specification for developing enterprise and distributed applications from JavaSoft (Sun Microsystems). J2EE is not one thing; it encompasses a large set of technologies: • •

JavaServer Pages (JSP) Servlets



Enterprise JavaBeans (EJB)



JDBC



Java Naming and Directory Interface (JNDI)



support for XML



Java Messaging



Java Transaction Support



JavaMail



Java support for CORBA

In this course, we will talk about JSP, servlets, EJB, JDBC, and touch on JNDI.

What can using these technologies accomplish? J2EE is useful for creating web applications like Yahoo! Mail, a web-based stock trading system such as E*TRADE, or an online auction house like eBay. Anytime there is a need for many people to access a collection of data in a distributed manner, an implementation of the J2EE specification can provide a solution.

Where is J2EE? Since J2EE is a specification, it isn't located anywhere. Instead vendors make their products adhere to the J2EE specification. Examples of the vendors offering J2EE compliant products are • •

Netscape/AOL iPlanet BEA WebLogic



IBM WebSphere



The JBoss Group's JBoss

In this course, we will concentrate on JBoss, which is a free, open-source J2EE server. The JBoss server itself is written in Java, so it can run on Windows, Linux, Mac OS X, Solaris, or any other platform which fully supports the Java virtual machine.

Java Server Pages Java Server Pages (JSP) are Sun's solution to the generation of dynamic HTML. With JSPs, you can generate HTML on the fly, which is important because • •

the content of the HTML may depend upon user submitted data the information represented by the HTML is dynamic by nature



the HTML may be customizable on a per user basis

JSPs are HTML-like pages that can contain a mixture of HTML tags, data, and Java code. Here is an example of a JSP that contains a simple for loop to count to 10: (If you have not already done so, you can download this and other examples used in this course. Mac OS X or other UNIX users click here instead.) code/Chapter1/counter/counter.jsp

<%@ page language="java" %> <%

code/Chapter1/counter/counter.jsp

for (int counter = 1; counter <= 10; counter++) {

%>

<%= counter %> Mississippi,


<% }

%>

Ready or not, here I come!

We then deploy this on a web server that knows how to handle JSPs. (We'll see how to deploy it later in this chapter.) The JSP will be mapped to a specific web address on that server, and when a user comes along and types in that web address, the web server will find this JSP, dynamically compile the Java code in it, run it, merge it with the HTML tags that are interspersed around the Java code, and output an HTML page back to the user's browser. The generated HTML will look like this:

1 Mississippi,
2 Mississippi,
3 Mississippi,
4 Mississippi,
5 Mississippi,
6 Mississippi,
7 Mississippi,
8 Mississippi,
9 Mississippi,
10 Mississippi,
Ready or not, here I come!

Java Servlets: A bit of history Servlets are pure Java objects that generate HTML by writing it to a stream. The files do not contain any HTML tags; they simply contain Java code which write out HTML (as strings) to produce the page that is sent to the user's browser. Historically, this used to be the only way to generate dynamic content in Java, but it is quite painful to develop any large scale application with a bunch of servlets running around doing println() statements. This is why Sun invented JSPs in the first place: to compete with the ease-of-development of Microsoft's ASP files, which could -- you guessed it -- mix HTML tags and code in a single file.

JSPs and servlets are two different ways to accomplish the same goal: generating dynamic HTML pages using Java code. One puts Java code in your HTML, and one puts HTML in your Java code. Functionally, they are equivalent. In fact, under the covers, the web server takes a JSP and converts it to the corresponding servlet and dynamically compiles it. Here is a Java servlet that produces the same content as the JSP we just saw above: code/Chapter1/counter/counterAsServlet.java

import javax.servlet.*; import java.io.*; import java.util.*; public class SimpleServlet extends GenericServlet { public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); printWriter pw = response.getWriter(); pw.println(""); pw.println(""); for(int counter = 1; counter <= 10; counter++) { pw.println(counter + " Mississippi,
"); } pw.println("Ready or not, here I come!"); pw.println(""); pw.println(""); pw.close(); } }

You can still write Java servlets manually if you want to, and many people still swear by them. However, JSPs are more flexible, and as we'll see in later chapters, can be combined with other features to create a powerful templating engine. We will not be writing servlets in this course, although we will see them sneak in behind the scenes in chapter 4.

JSP Syntax

Directives JSPs live in an object called a container, which is essentially a server. JSPs can define information for the container with directives. Here is what directives look like in a general form: <%@ directive attribute="someValue" attribute="anotherValue" ... %>

There are three directives: • •

<%@ page ... %> specifies information that affects the page <%@ include ... %> includes a file at the location of the include directive (parsed)



<%@ taglib ... %> allows the use of custom tags in the page

<%@ page language="java" %>

will always be the first line of every JSP file.

Declarations Declarations are used to specify supplemental methods and variables. You can think of these are the page's private functions; they can only be called by the JSP where they are defined, or by another JSP that includes it (using the <@ include > directive). Here is a sample declaration: <%! // this integer can be used anywhere in this JSP page private int myVariable = -1; // this function can be called from anywhere in this JSP page public boolean isPositive() { return ( myVariable > 0 ); } %>

Scriptlets Scriptlets are bits of Java code. They can do anything (the full power of Java is available in every JSP), but they will most likely concentrate on generating HTML code or setting up variables to be part of later expressions (see below). The first JSP we saw above, counter.jsp, contained a scriptlet with a for loop.

Expressions Expressions are special-purpose mini-scriptlets used for evaluating expressions. This could be something as simple as outputting the value of a variable, or a more complicated Java expression, like calling a function and outputting the result. The JSP example counter.jsp also contained an expression: <%= counter %>

Note that counter is defined as an int, but we do not need to explicitly convert it to a string. Expressions are implicitly converted to strings when they are output. (The println() function works the same way; it can take pretty much anything and print it. That makes sense if you think about it. Remember that JSPs automatically get converted to Java servlets under the covers. So an expression like this in a JSP file is converted to a println statement in a servlet that you never see. So anything println can print, an expression can contain, without any explicit conversion.)

An Example with JBoss and Tomcat Now lets create a web application using JBoss with Tomcat. JBoss is an open-sourced J2EE server from the JBoss Group (www.jboss.org). It provides support for integrating Tomcat, which is the open-sourced Servlet and JSP engine from the Apache Group's Jakarta project (jakarta.apache.org).

Note: If JBoss with Tomcat is not already installed, the instructor will provide assistance with getting it installed. The files for a J2EE web application are placed in a web application archive file (.war extension). Inside the web application archive are JSPs, HTML pages, .properties files, XML configuration files, images, and class files, as well as any customized data files that might need to be included. At a minimum, the web application archive will consist of a WEB-INF folder at the top level. Inside the WEB-INF folder will be a web.xml file. The web.xml file provides the J2EE server with information specific to the web application contained in the same web application archive. For example, it provides the name for the default page to serve, if one is not specified.

MyGreeting: A simple web application Do this: 1. Create a directory named MyGreeting 2. Within the MyGreeting directory, create a subdirectory named WEB-INF (capitalization matters, so be precise, and that's a dash, not an underscore) code/Chapter1/MyGreeting

MyGreeting | +-- HelloWorld.jsp (*) | +-- WEB-INF | +-- web.xml (*) (*) denotes a file

3. Create a JSP file named MyGreeting/HelloWorld.jsp 4. Add the following text to the HelloWorld.jsp file: code/Chapter1/MyGreeting/HelloWorld.jsp

<%@ page language="java" %> <% for (int counter = 1; counter <= 10; counter++) { %> Hello World!
<% } %>

5. Create the web.xml file in MyGreeting/WEB-INF/web.xml 6. Add the following text to web.xml:

code/Chapter1/MyGreeting/WEB-INF/web.xml

<web-app>

7. Drop to a command line and change to MyGreeting directory 8. Create the web application archive using the command-line jar utility: c:\j2ee\code\Chapter1\MyGreeting> jar cvf MyGreeting.war *.jsp WEB-INF

9. Copy MyGreeting.war to the deploy folder in your JBoss installation: c:\j2ee\code\Chapter1\MyGreeting> copy MyGreeting.war c:\j2ee\jboss\deploy\

10. Start JBoss by running the run.bat script provided in the bin folder of the JBoss installation. Because JBoss relies on relative paths to set up its CLASSPATH, this is a two-step process. First, change to the jboss/bin/ directory, then execute run.bat. Also, be sure to specify the tomcat argument on the command line so that it also starts the Tomcat servlet engine. c:\j2ee\code\Chapter1\MyGreeting> cd c:\j2ee\jboss\bin\ c:\j2ee\jboss\bin> run.bat tomcat

11. Open a web browser and go to http://localhost:8080/MyGreeting/HelloWorld.jsp

Exercises

Exercise 1. Current time Create a web application that displays the current time in a web page. Provide a link inside the web page to reload the page with the an updated time. Use JSPs in order to produce the dynamic content.

Copyright © 2001-2 MassLight, Inc.

MassLight, Inc. specializes in professional developer training. The full version of this course includes 20 hours of lecture, 20 hours of hands-on development labs, and additional printed materials to supplement the material you see here. If you are interested in having us teach this course at your company, please contact us for details. Permission is granted to copy, distribute, and/or modify this material under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in GNU Free Documentation License. The code samples in this course are distributed under the BSD license. See the individual code files for details. Contents - The Platform for Enterprise Solutions - Making Middleware Easier - The Standard with Industry Momentum

The Platform for Enterprise Solutions The Java 2 Platform, Enterprise Edition (J2EE) defines the standard for developing multitier enterprise applications. The J2EE platform simplifies enterprise applications by basing them on standardized, modular components, by providing a complete set of services to those components, and by handling many details of application behavior automatically, without complex programming. The J2EE platform takes advantage of many features of the Java 2 Platform, Standard Edition (J2SE), such as "Write Once, Run Anywhere" portability, JDBC API for database access, CORBA technology for interaction with existing enterprise resources, and a security model that protects data even in internet applications. Building on this base, the Java 2 Platform, Enterprise Edition adds full support for Enterprise JavaBeans components, Java Servlets API, JavaServer Pages and XML technology. The J2EE standard includes complete specifications and compliance tests to ensure portability of applications across the wide range of existing enterprise systems capable of supporting the J2EE platform. In addition, the J2EE specification now ensures Web services interoperability through support for the WS-I Basic Profile.

Making Middleware Easier Today's enterprises gain competitive advantage by quickly developing and deploying custom applications that provide unique business services. Whether they're internal applications for employee productivity, or Internet applications for specialized customer or vendor services, quick development and deployment are key to success. Portability and scalability are also important for long term viability. Enterprise applications must scale from small working prototypes and test cases to complete 24 x 7, enterprise-wide services, accessible by tens, hundreds, or even thousands of clients simultaneously. However, multitier applications are hard to architect. They require bringing together a variety of skill sets and resources, legacy data and legacy code. In today's heterogeneous environment, enterprise applications have to integrate services from a variety of vendors with a diverse set of application models and other standards. Industry experience shows that integrating these resources can take up to 50% of application development time. As a single standard that can sit on top of a wide range of existing enterprise systems -- database management systems, transaction monitors, naming and directory services, and more -- the J2EE platform breaks the barriers inherent between current enterprise systems. The unified J2EE standard wraps and embraces existing resources required by multitier applications with a unified, component-based application model. This enables the next generation of components, tools, systems, and applications for solving the strategic requirements of the enterprise. The J2EE specification also supports emerging Web Services technologies through inclusion of the WS-I Basic Profile. WS-I Basic Profile compliance means that the developers can build applications on the J2EE platform as Web services that interoperate with Web services from non-J2EE compliant environments. With simplicity, portability, scalability, and legacy integration, the J2EE platform is the platform for enterprise solutions.

The Standard with Industry Momentum While Sun Microsystems invented the Java programming language and pioneered its use for enterprise services, the J2EE standard represents a collaboration between leaders from throughout the enterprise software arena. Our partners include OS and database management system providers, middleware and tool vendors, and vertical market applications and component developers. Working with these partners, Sun has defined a robust, flexible platform that can be implemented on the wide variety of existing enterprise systems currently available, and that supports the range of applications IT organizations need to keep their enterprises competitive. The success of the J2EE platform in the enterprise continues to rise as more than two-thirds of enterprise software development managers use the J2EE platform to develop and deploy their applications. With addition of interoperable Web services and other new features in version 1.4, the J2EE platform will continue to be the industry standard for enterprise solutions for many years to come.

Related Documents

Sejarah Java
January 2021 4
Java
January 2021 4
Java
January 2021 3
Java
February 2021 4
Java
January 2021 15

More Documents from "Leimonis Tasos"