Programming 1 - Chapter 2: Java (PDF)
Document Details
Uploaded by Deleted User
Universidad de Dagupan
Tags
Summary
This document provides an overview of Java programming, including its origin, applications, and advantages. It discusses the language's development, its use in education and industry, and its platform independence.
Full Transcript
UNIVERSIDAD DE DAGUPAN Arellano St., Dagupan City, Pangasinan PROGRAMMING 1 program that we have written, the Java Chapter 2: The Origin, Applications, Virtual Machine interprets the byte code and Ad...
UNIVERSIDAD DE DAGUPAN Arellano St., Dagupan City, Pangasinan PROGRAMMING 1 program that we have written, the Java Chapter 2: The Origin, Applications, Virtual Machine interprets the byte code and Advantages of Java and it translates it into machine code. Programming Nowadays Java programming language is used primarily in school in Java programming language is one teaching computer programming concepts of the most popular and widely used among students. It is the syntax and programming languages, both in education commands that is easy to understand and and in the industry, it was first written and it teaches the students to write better code developed by Dr. James Gosling and his because it uses object-oriented concepts in colleagues in early 1990's at Sun writing a program. We used Java in almost Microsystem, which is now part of Oracle all the projects we are working on, Corporation after its acquisition was especially in enterprise projects that deal completed on January 27, 2010. Java was with secure, scalable and platform released in 1995 as part of Sun independent applications we deploy to Microsystem's Java platform. The language our various clients around the world. itself is based primarily in terms of syntax and structure in C and C++. Brief History of Java Java is an open source language In June of 1991, the that is freely available over the Internet to conceptualization of the Java programming download and use. All Java applications are language was spearheaded by James usually compiled to byte codes of class Gosling, Mike Sheridan, and Patrick files that can run on any Java Virtual Naughton. Interestingly, its original design Machine. One of the interesting features of was purposed for interactive television. the Java language is that it is an However, its forward-thinking capabilities object-oriented language that makes were a step too far, proving too software development much easier to sophisticated for the then-present digital design and implement. It uses classes, cable television industry. Initially, the methods and objects to create language was christened 'Oak', inspired by applications. Applications written in Java the majestic oak tree visible from Gosling's can run on many different operating office window. Over time, the project systems with little or no modification of the underwent a few transitions in its identity, code. This makes Java a platform briefly known as 'Green', before ultimately independent language that makes the life of settling on the name 'Java', borrowed from the developer or programmer much easier a popular type of coffee. Gosling in porting their applications on different envisioned the language to resonate with operating systems with ease. Java does this both system and application programmers, by making the Java compiler turn the code which is why he infused it with a syntax into Java byte code instead of machine style that echoes the familiarity of C and code. It means that when we execute the C++. BCNV 1 UNIVERSIDAD DE DAGUPAN Arellano St., Dagupan City, Pangasinan In 1995, Sun Microsystems (FOSS) under the terms of the GNU debuted the first public version of Java 1.0, General Public License (GPL). By May 8, embracing a "Write Once, Run Anywhere" 2007, they completed the process, making (WORA) philosophy. The platform offered Java's core code available under FOSS cost-free runtime on widely-used platforms distribution terms, except for a minor section and a reasonable level of security with of the code not owned by Sun. customizable restrictions for network and file access. Quickly gaining traction, major Rich Green, Sun's vice-president, web browsers began supporting Java envisioned Sun as a Java "evangelist." applets, enhancing the interactivity of web Oracle Corporation, which acquired Sun pages. Arthur van Hoff re-engineered the Microsystems in 2009-2010, positioned Java 1.0 compiler in Java itself, strictly itself as the "steward of Java technology" adhering to the language specification. By with a profound commitment to promoting a the end of 1998, Java evolved into Java 2, transparent, participative community. first known as J2SE 1.2. It offered several Despite this, Oracle initiated a lawsuit configurations for different platforms. Java 2 against Google for incorporating Java into Enterprise Edition (JEE) incorporated the Android SDK. Java software has technologies and APIs tailored for become omnipresent, powering everything server-side applications, while Java 2 from laptops and game consoles to data Micro Edition (J2ME) was optimized for centers and high-performance mobile applications. The standard desktop supercomputers. James Gosling, the version was renamed J2SE. In 2006, to creator of Java, resigned from Oracle on enhance marketing, Sun Microsystems April 2, 2010. rebranded new J2 versions as Java EE, Java ME, and Java SE. Types of Java Applications In 1997, Sun Microsystems sought There are many types of Java standardization of Java from the ISO/IEC programs which run differently: JTC 1 and Ecma International but eventually pulled back. Despite this, Java 1. Java Applet is usually stored on a has remained a widely-adopted standard, website and is downloaded and runs on a governed by the Java Community Process. client computer from within a web browser. While most of Sun's Java implementations were freely available, they retained 2. Application - can only be run on the proprietary status. Sun's primary revenue computer. If online, it has to be from Java came from the sale of licenses for downloaded before being run. specialized products like the Java Enterprise System. 3. JAR (Java Archive) File - A compact container that amalgamates multiple Java In a landmark move on November files into a solitary, cohesive entity, 13, 2006, Sun declared a significant portion operating in a manner strikingly similar of Java as free and open-source software to a zip file. BCNV 2 UNIVERSIDAD DE DAGUPAN Arellano St., Dagupan City, Pangasinan potentially leading to unpredictable failures 4. Servlet - A web server-resident program and perplexing bugs, Java ensures stability that plays a key role in the generation and through this requirement. presentation of web pages. 3. Consistent with its commitment to 5. Swing application - A comprehensive stability, Java demands that every method tool that enables the construction of declaring a return type must indeed return applications with a rich graphical user a value, which further aids in preventing bug interface, complete with elements like introduction. windows, buttons, menus, and more. 4. One of Java's primary assets is its 6. EJB (Enterprise Java Beans) - A web comprehensive API, providing an server-executed software component that is extensive selection of prebuilt classes and employed in the creation and methods. This resource reduces the need management of intricate, large-scale web to write extensive amounts of code from the platforms. ground up. Characteristics of Java 5. Unlike C, Java's primitive types, such as 'int', always maintain the same size in 1. Java is simple. terms of bit count. This consistency 2. Java is object-oriented. contributes to seamless cross-platform 3. Java is distributed. compatibility. 4. Java is interpreted. 5. Java is robust. 6. Historically, Java was considered slower 6. Java is secure. than C. However, with the recent advances 7. Java is architecture-neutral. in computing power, this perceived 8. Java is portable. disadvantage has become less relevant. 9. Java has high performance. 10. Java is multithreaded. 7. Java's structured exception-handling 11. Java is dynamic. requires programmers to manage error conditions such as input/output errors Benefits of Java effectively, thereby promoting more robust and reliable code. 1. Java often serves as an introductory programming language for students, but 8. One of Java's standout features is its it is also widely employed by seasoned "write once, run anywhere" approach. professionals in the industry. Code compiled on one Java platform 2. A notable feature of Java is the can be executed on any other platform that obligation to initialize every variable. supports Java without any modification to Unlike older languages such as C, which the source or byte-code. This means, for allow variables to remain uninitialized example, a Java program developed on a BCNV 3 UNIVERSIDAD DE DAGUPAN Arellano St., Dagupan City, Pangasinan Windows computer can effortlessly run on a language, and classes are a fundamental Linux or Mac system. part of the object-oriented paradigm. The second line of our program is public static void main(String[] args). In this particular part of our program, it is the starting point of program execution of our Java program. The keyword "public" means any variables or value that is being declared in the method can be used anywhere in our program. The next symbol is an open and close curly brace, Analyzing the Program this means the starting and ending point (Hello_World.java) where we can issue a command in the body of our Java program. We write In our first sample program in Java System.out.println(); this is one of the our program will display a message on the most common commands in Java that screen Hello Word and then in the second enables us to display a message on the line it will display a message End of screen of our computer or we can use this Program. When I first started learning how command to create formatted output of our to program in Java, one of the most program. common mistakes that I have committed is that the file name and the class name are The next statement not the same when I save my Java System.out.println("Hello World."); will program. That's why when I compile my display the message Hello World. on our program, it generates an error. The screen when we compile and run our Java filename of our program is Hello_World.java program. The use of System.out.println and our class name is Hello_World. They means we want to have a newline for the should be the same in every program you next statement which will display a write in Java to avoid this error during the message End of Program. This is followed compilation process of our program. by two right curly braces to close our method that will serve to end our program The first statement in our program statement. is class Hello_World, is the name of our program. The first keyword in our program is class. A class is the fundamental unit of program structure in Java, so it is not surprising that the first line of our program declares a class. All Java programs are classes, although some programs use many classes instead of just one. As we all know, Java is an object-oriented programming BCNV 4