Download presentation
Presentation is loading. Please wait.
1
Java Tutorial Zhe Li
2
Topics Socket Programming GUI Maven Project(Tomcat)
3
Socket Programming Overview
Java socket programming provides facility to share data between different computing devices. A socket is an endpoint between two way communication.(Server and Client) Overview
4
Socket Programming Client Server Socket Class ServerSocket Class
Socket socket = new Socket(“ ”, 5000) public InputStream getInputStream() public OutputStream getOutputStream() public synchronized void close() ServerSocket Class public Socket accept() public synchronized void close() A socket is simply an endpoint for communications between the machines. The Socket class can be used to create a socket. The ServerSocket class can be used to create a server socket. This object is used to establish communication with the clients. InputStream returns the InputStream attached with this socket. Accept returns the socket and establish a connection between server and client.
5
Establish a Socket Connection Communication Closing the connection
A socket connection means the two machines have information about each other’s network location (IP Address) and TCP port. Socket socket = new Socket(“ ”, 5000) Communication public InputStream getInputStream() public OutputStream getOutputStream() To communicate over a socket connection, streams are used to both input and output the data. Closing the connection The socket connection is closed explicitly once the message to server is sent. public synchronized void close() To connect to other machine we need a socket connection.The java.net.Socket class represents a Socket. To open a socket:
6
socket demo Feature1: Client keeps reading input from user and sends to the server until “Over” is typed. Server prints out what the client sends to it. Feature2: Client will write first to the server then server will receive and print the text. Then server will send the message back to the client and the client will receive and print the text.
7
Graphical User Interface
GUI Java APIs for graphic programming: AWT(Abstract Windowing Toolkit) Swing JavaFX HTML/CSS, Jquery, JavaScript Graphical User Interface
8
GUI AWT API was introduced in JDK 1.0.
Swing API, a much more comprehensive set of graphics libraries that enhances the AWT, was introduced as part of Java Foundation Classes (JFC) after the release of JDK 1.1. JFC consists of Swing, Java2D, Accessibility, Internationalization, and Pluggable Look-and-Feel Support APIs. JFC has been integrated into core Java since JDK 1.2. The latest JavaFX, which was integrated into JDK 8, is meant to replace Swing. Most of the AWT components have become obsolete and should be replaced by newer Swing components.
9
AWT java.awt package contains the core AWT graphics classes:
GUI Component classes, such as Button, TextField, and Label. GUI Container classes, such as Frame and Panel Custom graphic classes, such as Graphic, Color and Font java.awt.event package supports event handling: Event classes, such as ActionEvent, MouseEvent, KeyEvent and WindowEvent Event Listener Interface, such as ActionListener, MouseListener, MouseMotionListener Event Listener Adapter classes, such as MouseAdapter, KeyAdapter, and WindowAdapter
10
Awt demo It has a top-level container Frame, which contains three components - a Label "Counter", a non-editable TextField to display the current count, and a "Count" Button. The TextField shall display count of 0 initially. Each time you click the button, the counter's value increases by 1.
11
Swing If you understood the AWT programming (in particular, container/component and event-handling), switching over to Swing is straight-forward. Compared with the AWT component classes (in package java.awt), Swing component classes (in package javax.swing) begin with a prefix "J", e.g., JButton, JTextField, JLabel, JPanel, JFrame, or JApplet.
12
Writing Swing Applications
In summary, to write a Swing application, you have: Use the Swing components with prefix "J" in package javax.swing, e.g., JFrame, JButton, JTextField, JLabel, etc. A top-level container (typically JFrame) is needed. The JComponents should not be added directly onto the top-level container. They shall be added onto the content-pane of the top-level container. You can retrieve a reference to the content-pane by invoking method getContentPane() from the top-level container. Swing applications uses AWT event-handling classes, e.g., ActionEvent/ActionListener, MouseEvent/MouseListener, etc. Run the constructor in the Event Dispatcher Thread (instead of Main thread) for thread safety, as shown in the following program template.
13
Swing demo Let's convert the earlier AWT application example into Swing. Compare the two source files and note the changes (which are highlighted). The display is shown below. Note the differences in look and feel between the AWT GUI components and Swing's
14
HTML+iQuery(Web-based)
HyperText Markup Language Purpose: How the website will look like(Layout) jQuery Manipulation of html elements
15
jQuery(Library) jQuery is a library used primarily for Document Object Model (DOM) manipulation. The DOM is a tree-like structure that represents all elements on a webpage. jQuery can select DOM elements, create animations, handle events, and more. Its goal is to be extensible, simple, and clear to use. It takes care of all cross-browser incompatibilities, and it promotes the separation of HTML and JavaScript.
16
Bootstrap (framework)
Bootstrap is an open-source front-end framework to help you with designing websites. It features a number of CSS styles, icons, components, and JavaScript plugins. These plugins include a lot of common things you might use when building a website. This includes modals, dropdowns, alerts, and buttons, to name a few. Bootstrap greatest strength is how easy it is for non-designers to quickly create decent- looking websites. Not to mention, Bootstrap makes it easy to create responsive designs (websites that adjust dynamically according to the device used: tablets, mobile phones etc).
17
AngularJS HTML is great for declaring static documents, but it falters when we try to use it for declaring dynamic views in web-applications. Data-binding eliminates DOM manipulation. Controllers are the behavior behind the DOM elements. HTML was not designed for dynamic views Data-binding is an automatic way of updating the view whenever the model changes, as well as updating the model whenever the view changes.
18
Maven Project Maven is a build automation tool used primarily for Java projects. It addresses two aspects of building software: First, it describes how software is built, and second, it describes its dependencies.
19
Maven file
20
Java Application
22
Building a JavaScript Client
23
Demo
24
tips about tomcat Tomcat version Mvn clean install
25
Thank you
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.