web view1n 1996, sun microsystems released a new programming language called java. see java timeline...

14
MOBILE ITnT Solutions, LLC. Java Developer I Program Class Notes: Getting Started with Java & NetBeans - Part ONE

Upload: lydan

Post on 11-Mar-2018

219 views

Category:

Documents


2 download

TRANSCRIPT

MOBILE ITnTSolutions, LLC.

Java Developer I

Program

Class Notes:

Getting Started with Java & NetBeans-

Part ONE

Topics Covered:

How to get started with Java and NetBeanso Intro to Javao Using NetBeans to work with existing projectso Using NetBeans to develop new projects

Introduction to Java 1n 1996, Sun Microsystems released a new programming

language called Java See Java timeline below:

Throughout Java’s history, the terms Java Development Kit (JDK) and Software Development Kit (SDK) have been used to describe the Java toolkit

o Java toolkit or Java Development Toolkit is a program development environment for writing Java applets and applications

o Consists of a runtime environment that “sits on top” of the operating system layer as well as the tools and programming that developers need to compile, debug, and run applets and applications written in the Java language

Different numbering schemes have been used to indicate the version of Java

o For example: Java 5.0 and Java 6 refer to versions 1.5 and 1.6 of Java

The current Standard Edition of Java is known as Java SE The current Enterprise Edition of Java is known as Java EE This Java program will show how to use Java SE 7, but it

should also work for earlier and future versions of Java

Operating systems supported by Java: Windows Linux Solaris Macintosh OS X

Applications, applets, and servlets:

These figures describe the 3 types of programs you can create with Java

When you create these desktop apps, you can use a graphical user interface(GUI) to get user input and perform a calculation as shown here

The console application: runs in the console, or command prompt, that’s available from your operating system, as shown here.

One of the unique characters of Java is that you can use it to create a special type of web-based application known as an applet

This figure shows an applet that works the same way as the application above it

The main difference between an application and an applet is that an applet can be stored in an HTML page and can run inside a Java-enabled browser

As a result, you can distribute applets via the Internet or an intranet

You will learn how to create and deploy applets later in this program

Although applets can be useful for creating a complex user interface within a browser, they have their limitations

You usually need to install a plug-in on each client machine, which isn’t ideal for some types of applications

Second, since an applet runs within a browser on the client, it’s not ideal for working with resources that run on the server, such as enterprise databases

To provide access to enterprise databases, many developers use Java EE to create applications that are based on servlets

A servlet is a special type of Java application that runs on the server and can be called by a client, which is usually a web browser

As shown in our example, you can see that the servlet works much the same way as the applet

o The main difference is that the code for the application runs on the server

When a web browser calls a servlet, the servlet performs its task and returns the result to the browser, typically in the form of an HTML page

o For example, suppose a browser requests a servlet that displays all unprocessed invoices that are stored in a database

o Then when the servlet is executed, it reads data from the database, formats that data within an HTML page, and returns the HTML page to the browser

When you create a servlet-based application like the one shown here, all the processing takes place on the server and only HTML is returned to the browser

To make it easy to store the results of a servlet within an HTML page, the Java EE specification provides for JavaServer Pages (JSPs)

o Most developers use JSPs together with servlets when developing server-side Java applications

o Java Servlets and JSPs are covered in the Java Developer II program

Code for the console version of the Future Value application:

To give you an idea on how the code for a Java application works, our example here presents the code for the console version of the Future Value application…

If you have no programming experience, don’t worry, you will learn all on how this code works in the next few video lessons. . .for now, here’s a brief explanation of this code

Most of the code for this application is stored in a class name FutureValueApp

o This class begins with an opening brace ({) and ends with a closing brace (})

o Within this class, two methods are defined These methods also begin with an opening brace and

end with a closing brace, and they are indented to clearly show that they are contained within the class

o The 1st method, named main, is the main method for the application

The code within this method is executed automatically when you run the application

In this case, the code displays the data the user sees on the console, accepts the data the user enters at the console, and calculates the future value

o The 2nd method is named calculateFutureValue This method is called from the main method and

calculates the future value based on the data the user enters

Example below:

Show real code in class

How Java compiles and interprets code: When you develop a Java application, you create one or more

classes For each class, you write the Java statements that direct

the operation of the classo Then, you use a Java tool to translate the Java

statements into instructions that can be run by the computer, as show below

To start, enter and edit the Java source code for a class

o These are Java statements, like the Java code we just viewed, that tell the application what to do

Then use the Java compiler to compile the source code into a format known as Java bytecodes

o At this point, the bytecodes can be run on any platform that has a Java interpreter to interpret (or translate) the Java bytecodes into code that can be understood by the underlying operating system

Introduction to Java IDEs To develop Java apps, you typically use an Integrated

Development Environment(IDE) Although you can use a simple text editor, an IDE provides

features that can make developing Java applications considerably easier

Here are some features of the most popular IDEs

The first two IDEs: Netbeans and Eclispe, are arguably the 2 most popular Java IDEs

o Both IDEs help you complete your code and notify you on potential compile-time errors

o They both compile your code before you run it

o They both include a debugger that lets you perform standard debugging functions like setting breakpoints, stepping through code, and viewing the values of variables

The default installation of NetBeans provides a feature of building graphical user interfaces(GUI)

o To use this GUI builder, you can drag controls onto a form on the design surface

The last 3 IDEs shown aren’t as popular as NetBeans and Eclipse

Other Java IDEs are available as well that aren’t included in this list

We will be using NetBeans in this program. . .it’s more intuitive and easier to use than Eclipse