View
46
Download
0
Category
Tags:
Preview:
DESCRIPTION
CSE 1341 - Honors Principles of Computer Science I. Spring 2008 Mark Fontenot mfonten@engr.smu.edu. 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
Citation preview
Spring 2008
Mark Fontenotmfonten@engr.smu.edu
CSE 1341 - HonorsPrinciples of Computer Science I
Note Set 22
Note Set 21 Overview
Creating packages in JavaWrap up
What else can you do now?
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
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
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
Directory Structure
Importing the class that was created
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.*;
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
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
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
What is possible?
Finding Cures for Diseases? Enabling the disabled?Speeding up the Internet?Developing the next great web-app?Solving world hunger?
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.
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"); } }
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;}
Recommended