CNT 4007C Project 2 Good morning, everyone. In this class, we will have a brief look at the project 2. Project 2 is basically the same with project 1.

Slides:



Advertisements
Similar presentations
Java Programming 2 Dr. Priti Srinivas Sajja Introductory concepts of java programming as specified in PGDCA 203:Object Technology, S P University.
Advertisements

INHERITANCE BASICS Reusability is achieved by INHERITANCE
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
1 Chapter 5 Threads 2 Contents  Overview  Benefits  User and Kernel Threads  Multithreading Models  Solaris 2 Threads  Java Threads.
Slides 8c-1 Programming with Shared Memory Java Threads and Synchronization Review The following notes are based upon the Java tutorial at
02/05/2007CSCI 315 Operating Systems Design1 Java Threads Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Java Threads Part II. Lecture Objectives To understand the concepts of multithreading in Java To be able to develop simple multithreaded applications.
Multithreading A thread is the flow of execution, from beginning to end, of a task in a program. With Java, you can launch multiple threads from a program.
CS220 Software Development Lecture: Multi-threading A. O’Riordan, 2009.
Java Overview February 4, /4/2004 Assignments Due – Homework 1 Due – Reading and Warmup questions Project 1 – Basic Networking.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Multithreading.
Threading in Java – a Tutorial QMUL IEEE SB. Why Threading When we need to run two tasks concurrently So multiple parts (>=2) of a program can run simultaneously.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
Applications Development Objects in Java Key concepts and metaphors Implicit subclassing Static methods Constructors Instance.
Methods CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Object Oriented Programming: Java Edition By: Samuel Robinson.
1 Java Threads and Synchronization Review Modified from slides taken from
CIS 644 Aug. 25, 1999 tour of Java. First … about the media lectures… we are experimenting with the media format please give feedback.
Nested References 2 inner reference data types Classes-Interfaces.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
Inheritance. Introduction Inheritance is one of the cornerstones of object-oriented programming because it allows the creation of hierarchical classifications.
Threads in Java. Processes and Threads Processes –A process has a self-contained execution environment. –Has complete set of runtime resources including.
1 Web Based Programming Section 8 James King 12 August 2003.
Concurrency in Java Brad Vander Zanden. Processes and Threads Process: A self-contained execution environment Thread: Exists within a process and shares.
1 CSCD 330 Network Programming Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 9 Client-Server Programming.
Concurrent Computing CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
6.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Module 6: Process Synchronization Codes.
Parallel Processing (CS526) Spring 2012(Week 8).  Shared Memory Architecture  Shared Memory Programming & PLs  Java Threads  Preparing the Environment.
Chapter11 Concurrent. 集美大学 计算机工程学院 Java 程序设计 年 第二版 Concurrent ●Computer users take it for granted that their systems can do more than one thing.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
AD Lecture #1 Object Oriented Programming Three Main Principles 1 Inheritance Encapsulation Polymorphism.
COME 339 WEEK 1. Example: The Course Class 2 TestCourceRunCourse.
OOP Basics Classes & Methods (c) IDMS/SQL News
AP Java 1/14/2016 Inheritance Review. Learning Objectives Be able to understand how to create classes that use inheritance. Be able to dry run programs.
Concurrency in Java MD. ANISUR RAHMAN. slide 2 Concurrency  Multiprogramming  Single processor runs several programs at the same time  Each program.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Java 5 Class Anatomy. User Defined Classes To this point we’ve been using classes that have been defined in the Java standard class library. Creating.
Using Parallel Threads Why? When? Where? George Serbanut University of Turin / INFN Turin / ISS Bucharest CSC – August 28 th, 2007.
Multithreaded applets
Threads in Java Two ways to start a thread
Objects as a programming concept
PA1 Discussion.
Agenda Warmup AP Exam Review: Litvin A2
Multithreaded Programming in Java
Interface.
Inherited Classes in Java
Advanced Java Programming
METHOD OVERRIDING in JAVA
Assignment 7 User Defined Classes Part 2
Programming with Shared Memory Java Threads and Synchronization
Programming with Shared Memory Java Threads and Synchronization
Recursive GCD Demo public class Euclid {
class PrintOnetoTen { public static void main(String args[]) {
Unit 1 Lab14 & Lab15.
Java Programming with Multiple Classes
CSCD 330 Network Programming
Threads in Java James Brucker.
Sampath Kumar S Assistant Professor, SECE
Using threads for long running tasks.
Representation and Management of Data on the Internet
Chapter 11 Inheritance and Polymorphism Part 1
Gentle Introduction to Threads
Multiplexing/Demux.
Chapter 11 Inheritance and Encapsulation and Polymorphism
CMSC 202 Threads.
Java Chapter 3 (Estifanos Tilahun Mihret--Tech with Estif)
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

CNT 4007C Project 2 Good morning, everyone. In this class, we will have a brief look at the project 2. Project 2 is basically the same with project 1. You are required to write a chatting program, but you need to build some extra functions on top of your project 1. In project 1, the sever can only connect with one client at a time, but in project 2, the server should be able to connect with multiple clients at the same time. In project 1, when Alice chats with Bob, each of them can only send one message at a time. In project 2, we will extend the function to allow each client to send multiple messages. All these new functions require us to introduce the concept of threads. 11/29/2018

Process and Thread A process is an instance of a running program. Different processes do not share resources. A thread is a component of a process. Multiple threads can exist within the same process and share resources such as memory, and they can run in parallel. So what is thread? What is the difference between a process and a thread? 11/29/2018

Two ways to define and start a thread Provide a Runnable object public class HelloRunnable implements Runnable { public void run() { System.out.println("Hello from a thread!"); } public static void main(String args[]) { (new Thread(new HelloRunnable())).start(); There are two different ways to define and start a thread in Java. The first way is to provide a runnable object to the thread constructor, and a thread object will be returned. Then you can … 11/29/2018

Two ways to define and start a thread Inherit Thread class, and overload the run() method public class HelloThread extends Thread { public void run() { System.out.println("Hello from a thread!"); } public static void main(String args[]) { (new HelloThread()).start(); The second is to subclass thread, and overload the run method. Then you can create thread objects from the subclass. Still, you use the start method to start a thread. 11/29/2018

Sample Code Server.java Client.java These are sample code of client and sever using multiple threads. 11/29/2018

How to create a sending thread and a receiving thread? public class CommunicationThread extends Thread { private int mode; //determines it is a receiving thread or a sending thread public void run() if(mode == 0) always receive message; if(mode == 1) always send messages; } In order to enable a client to send and receive multiple messages each time, we need create a sending thread and a receiving thread for each client. How can we achieve that? Here is a hint 11/29/2018

Demo Video demo.mp4 Finally, this is the demo video for this project. It shows what we expect to see during your project demo. 11/29/2018