![Page 2: CSE 1341 - Honors Principles of Computer Science I](https://reader036.vdocument.in/reader036/viewer/2022062310/5681637b550346895dd45963/html5/thumbnails/2.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062310/5681637b550346895dd45963/html5/thumbnails/3.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062310/5681637b550346895dd45963/html5/thumbnails/4.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062310/5681637b550346895dd45963/html5/thumbnails/5.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062310/5681637b550346895dd45963/html5/thumbnails/6.jpg)
Directory Structure
![Page 7: CSE 1341 - Honors Principles of Computer Science I](https://reader036.vdocument.in/reader036/viewer/2022062310/5681637b550346895dd45963/html5/thumbnails/7.jpg)
![Page 8: CSE 1341 - Honors Principles of Computer Science I](https://reader036.vdocument.in/reader036/viewer/2022062310/5681637b550346895dd45963/html5/thumbnails/8.jpg)
![Page 9: CSE 1341 - Honors Principles of Computer Science I](https://reader036.vdocument.in/reader036/viewer/2022062310/5681637b550346895dd45963/html5/thumbnails/9.jpg)
Importing the class that was created
![Page 10: CSE 1341 - Honors Principles of Computer Science I](https://reader036.vdocument.in/reader036/viewer/2022062310/5681637b550346895dd45963/html5/thumbnails/10.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062310/5681637b550346895dd45963/html5/thumbnails/11.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062310/5681637b550346895dd45963/html5/thumbnails/12.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062310/5681637b550346895dd45963/html5/thumbnails/13.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062310/5681637b550346895dd45963/html5/thumbnails/14.jpg)
![Page 15: CSE 1341 - Honors Principles of Computer Science I](https://reader036.vdocument.in/reader036/viewer/2022062310/5681637b550346895dd45963/html5/thumbnails/15.jpg)
![Page 16: CSE 1341 - Honors Principles of Computer Science I](https://reader036.vdocument.in/reader036/viewer/2022062310/5681637b550346895dd45963/html5/thumbnails/16.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062310/5681637b550346895dd45963/html5/thumbnails/17.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062310/5681637b550346895dd45963/html5/thumbnails/18.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062310/5681637b550346895dd45963/html5/thumbnails/19.jpg)
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;}