You are on page 1of 10

CSC 201

Lecture 12
Agenda
• Practicing few Java classes - questions.
• Reading/Writing to Files.
• Access specifiers in Java.
• Packages in Java.
• Real-world project coded and presented
by a student.
Questions
• Encryption and Decryption – Caesar
Cipher.
• How to get the ASCII value of a String or
a character?
• In a given String, count the number of
consonants and vowels.
Questions (contd..)
• You are asked to develop a small ‘Library
check-out system’. There can be 20 books
in your library and 10 students who can
check-out these books. At a given time, a
student cannot have more than 3 books
reserved under his name.
Please write a Java program to simulate
this scenario. You are free to use your
own methods and classes.
Access Specifiers in Java
• Public
• Private
• <none>
• Protected (covered later)
Access specifiers for class
variables-Member level
• Access specifiers for class variables:
Specifier Same class Same Other
package Packages
private Y N N
public Y Y Y
(none) Y Y N
Packages in Java
• We have been working on small project.
What if it was a very big package?
• How to create a package? Netbeans IDE
automatically does it for you when you
create a new project.
Importing other user created
packages into your package
1) Create a ‘new’ project package p2 and
rename main class which is public as
‘sample’
2) Go to another package p1 and rename
the main class as ‘importsample’.
3) Go to the .java file where in you want to
import other package. In my case, I want
to import package p1 into package p2.
4) Click on ‘File’, click on ProjectProperties.
• Click on ‘Add Project’ and add the
project/package you want to.
• Write the import statement and create an
instance of the class you want to use.
– import p1.className

You might also like