160 likes | 309 Vues
Lab Information Security Using Java (Review). Lab#0 Omaima Al- Matrafi. Office# 78-A Office hours : S.M.W 10-11 S…W 12:30-2 Email : omaima_almatrafi@yahoo.com. Java - General. Java is: High level language similar to C++ in syntax
E N D
Lab Information SecurityUsing Java (Review) Lab#0 Omaima Al-Matrafi
Office# 78-A • Office hours : S.M.W 10-11 S…W 12:30-2 • Email : omaima_almatrafi@yahoo.com
Java - General • Java is: • High level language similar to C++ in syntax • Platform independent programming language
Java Interpreter Just in Time Compiler How it works…! Compile-time Environment Compile-time Environment Class Loader Bytecode Verifier Java Class Libraries Java Source (.java) Java Bytecodes move locally or through network Java Virtual machine Java Compiler Runtime System Java Bytecode (.class ) Operating System Hardware
How it works…! • Java is independent only for one reason: • Only depends on the Java Virtual Machine (JVM). • The Java compiler produces a special format called byte code, which is interpreted by the resident JVM (regardless of computer architecture), • JIT (just in time) compilers attempt to increase speed. Write Once, Run everywhere
Java Features • Portable - Write Once, Run Anywhere • Automatic memory management • Designed for network programming • Multi-threaded (multiple simultaneous tasks) • Dynamic & extensible (loads of libraries) • Classes stored in separate files • Loaded only when needed • Security has been well thought through
Java lets you write special programs called applets that can be downloaded from the Internet and played safely within a web browser. • Java restricts what an applet can do. • A Java applet cannot write to your hard disk without your permission. • It cannot write to arbitrary addresses in memory and thereby introduce a virus into your computer. • It should not crash your system.
Software required: • Java Development Kit (JDK) version 5 • Download: http://java.sun.com/javase/ • JCreator LE version • http://www.jcreator.org/download.htm
(JDK) is a Sun Microsystems product aimed at Java developers. • Some of JDK contents: • java – The loader for Java applications. This tool is an interpreter. • javac – The compiler, which converts source code into Java bytecode . • jar – The archiver, which packages related class libraries into a single JAR file. • jdb – The debugger • appletviewer – This tool can be used to run and debug Java applets without a web browser. Java Development Kit (JDK)
A Class : A class defines the abstract characteristics of a thing and its behavior. An Object : An exemplar of a class. it consists of state and related behavior. An object stores its state in fields and exposes its behavior through methods. Inheritance: programming allows classes to inherit commonly used state and behavior from other classes. use the extends keyword, followed by the name of the class to inherit from: class subClassextendssuperClass Some Object-Oriented Terminology
Interface: just like classes except that they use the word interface instead of class and is restricted to containing method declarations without bodies. Interface interface_name { } And to use the interface in the class definition: Public class class_name implements interface_name { } • A package: is a namespace that organizes a set of related classes and interfaces. The Java platform provides an enormous class library (a set of packages). This library is known as the "Application Programming Interface", or "API“. Some Object-Oriented Terminology
Variables • Instance Variables (Non-Static Fields) • Class Variables (Static Fields) • Local Variables (method’s variables) • Parameters • Primitive Data Types: byte, short, int, long, float, double, boolean, char. • Arrays Language Basics
For writing a java program to read file line by line: • Use import java.io.*; • DefineFileInputStream object to obtain input bytes from a file in a file system (to open the file). • Define DataInputStream object to let an application read primitive Java data types from an underlying input stream in a machine-independent way. • Define InputStreamReader object which is used as a bridge from byte streams to character streams. Reading from a file
Define BufferedReaderobject to Read text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines. • Read File Line By Line using readLine() method of BufferedReaderobject. • Close the input stream. Reading from a file Cont.
http://java.sun.com/docs/books/tutorial/java/index.html GOOD LUCK Good References
Practice to write to a file… You will need that later in your HWs. For writing to a file, you will need to use FileOutputStreamobject. Need to do…