CSE 1341 - Honors Principles of Computer Science I

19
Spring 2008 Mark Fontenot [email protected] CSE 1341 - Honors Principles of Computer Science I Note Set 22

description

CSE 1341 - Honors Principles of Computer Science I. Spring 2008 Mark Fontenot [email protected]. Note Set 22. Note Set 21 Overview. Creating packages in Java Wrap up What else can you do now?. Packages. We’ve done a good deal of import java.util .*; import javax.swing .*; - PowerPoint PPT Presentation

Transcript of CSE 1341 - Honors Principles of Computer Science I

Page 1: CSE 1341 - Honors Principles of Computer Science I

Spring 2008

Mark [email protected]

CSE 1341 - HonorsPrinciples of Computer Science I

Note Set 22

Page 2: CSE 1341 - Honors Principles of Computer Science I

Note Set 21 Overview

Creating packages in JavaWrap up

What else can you do now?

Page 3: CSE 1341 - Honors Principles of Computer Science I

PackagesWe’ve done a good deal of

import java.util.*;import javax.swing.*;

What does that mean really?

Every class belongs to a packagePackages

contain groups of related classeshelp organize code base of complex applicationsfacilitate software reusehelp prevent class-name conflicts

Page 4: CSE 1341 - Honors Principles of Computer Science I

Steps for Declaring Reusable Class1. Declare a class public. If class not public, can only be used

by other classes in same package.2. Choose unique name and add package declaration to

source file package edu.smu.cse.mef;

3. Compile class so that directory structure is createdNetbeans does this automatically for source and compiled version

4. Use code elsewhere

Page 5: CSE 1341 - Honors Principles of Computer Science I

Example

package edu.smu.cse.mef;

public class Student { private String name; private String id; private int test1; private int test2; public Student(String n, String i, int t1, int t2) { name = n; id = i; test1 = t1; test2 = t2; }}

Student.java

Page 6: CSE 1341 - Honors Principles of Computer Science I

Directory Structure

Page 7: CSE 1341 - Honors Principles of Computer Science I
Page 8: CSE 1341 - Honors Principles of Computer Science I
Page 9: CSE 1341 - Honors Principles of Computer Science I

Importing the class that was created

Page 10: CSE 1341 - Honors Principles of Computer Science I

Import TypesSingle-type-import declaration

specifies exactly one class to importimport java.util.Scanner;

Type-Import-On-Demand DeclarationAllows all classes from a package to be accessed and usedimport java.util.*;

Page 11: CSE 1341 - Honors Principles of Computer Science I

What else is there?What else is there beyond Java?

Some say there are over 2000 (!!!!) programming languages in existence.

Why learn to program?computers are dumbthey need to be told exactly what to do – step by step

Programming is a toolFew people program just to earn “cool” pointsUse a computer to solve a particular problem – must tell it

what to do

Page 12: CSE 1341 - Honors Principles of Computer Science I

Why?Computers are nearly ubiquitous

Think of a scenario where you can exists for 7 days with out interaction of a computer OR without interaction with anything that was influenced or designed by a computer!!!!

Computers/processors are all over the place….They all need software to run so that they perform useful work

Page 13: CSE 1341 - Honors Principles of Computer Science I

What else can Java do?Create apps for portable devices/embedded devices

J2ME – Java 2 Micro Editionexamples: mobile phones, PDAs, TV set-top boxes, printers

Create web-based services and next-gen web applicationsJ2EE – Java 2 Enterprise EditionExamples: E-commerce websites

Access web-services and APIsGoogle APIYouTube APIFacebook API

Page 14: CSE 1341 - Honors Principles of Computer Science I
Page 15: CSE 1341 - Honors Principles of Computer Science I
Page 16: CSE 1341 - Honors Principles of Computer Science I

What is possible?

Finding Cures for Diseases? Enabling the disabled?Speeding up the Internet?Developing the next great web-app?Solving world hunger?

Page 17: CSE 1341 - Honors Principles of Computer Science I

ExamplesBioinformatics/Computational Biology

Using computer science and algorithms to solve biologically relevant problems

Data Mining/InformaticsEffectively managing data and gleaning information from raw

dataComputer Aided Design (not drawing houses)

Using computers to design computersOptimization Issues (OR and CS)

UPS reduces number of left turns to save fuel.

Page 18: CSE 1341 - Honors Principles of Computer Science I

Other Languages – C#

C# Code

String csString = "Apple Jack"; csString.ToLower();

Java Code

String jString = "Grapes"; jString.toLowerCase();

C# Code using System; class A{ public static void Main(String[] args){ Console.WriteLine("Hello World"); }}Java Code class B{ public static void main(String[] args){ System.out.println("Hello World"); } }

Page 19: CSE 1341 - Honors Principles of Computer Science I

Other Languages – C++

int main () { string s; s = “Hello”; stack<char> stk; for (int i = 0; i < s.size(); i++) stk.push(s[i]); while (!s.isEmpty()){ cout << stk.top(); stk.pop(); } return 0;}