Transcript Note Set 22
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.*;
What does that mean really?
Every class belongs to a package
Packages
contain groups of related classes
help organize code base of complex applications
facilitate software reuse
help prevent class-name conflicts
Steps for Declaring Reusable Class
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 created
Netbeans does this automatically for source and compiled
version
4. Use code elsewhere
1.
Example
Student.java
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;
}
}
Directory Structure
Importing the class that was created
Import Types
Single-type-import declaration
specifies exactly one class to import
import java.util.Scanner;
Type-Import-On-Demand Declaration
Allows all classes from a package to be accessed and used
import 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 dumb
they need to be told exactly what to do – step by step
Programming is a tool
Few people program just to earn “cool” points
Use 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 Edition
examples: mobile phones, PDAs, TV set-top boxes, printers
Create web-based services and next-gen web applications
J2EE – Java 2 Enterprise Edition
Examples: E-commerce websites
Access web-services and APIs
Google API
YouTube API
Facebook API
What is possible?
Finding Cures for Diseases?
Enabling the disabled?
Speeding up the Internet?
Developing the next great web-app?
Solving world hunger?
Examples
Bioinformatics/Computational Biology
Using computer science and algorithms to solve biologically
relevant problems
Data Mining/Informatics
Effectively managing data and gleaning information from raw
data
Computer Aided Design (not drawing houses)
Using computers to design computers
Optimization Issues (OR and CS)
UPS reduces number of left turns to save fuel.
Other Languages – C#
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");
}
}
C# Code
String csString = "Apple Jack";
csString.ToLower();
Java Code
String jString = "Grapes";
jString.toLowerCase();
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;
}