Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
JAVA
PROGRAMMING
LEARNING OUTCOMES:
At the end of the session, the students should be
able to:
1. Can narrate the key highlights behind JAVA
programming
2. Can distinguish the features of java.
3. Familiarize on the JAVA programming environment
What is Java?
JAVA Versions
• JDK Alpha and Beta (1995) • Java SE 7
• JDK 1.0 (23rd Jan, 1996) (28th July, 2011)
• JDK 1.1 (19th Feb, 1997) • Java SE 8
(18th March, 2014)
• J2SE 1.2 (8th Dec, 1998)
• Java SE 9
• J2SE 1.3 (8th May, 2000) (21st Sep, 2017)
• J2SE 1.4 (6th Feb, 2002) • Java SE 10
• J2SE 5.0 (30th Sep, 2004) (20th March, 2018)
• Java SE 6 (11th Dec, 2006)
Java Features
• Some features of Java:
– The Java Virtual Machine
– Garbage Collection
– Code Security
– Platform Independence
– Object Oriented
Java Features
• Some features of Java:
– The Java Virtual Machine
Java Virtual Machine (JVM)
– an imaginary machine that is implemented by
emulating software on a real machine
– provides the hardware platform specifications to
which you compile all Java technology code
Java Features
• Some features of Java:
– The Java Virtual Machine
Bytecode
– a special machine language that can be understood
by the Java Virtual Machine (JVM)
– independent of any particular computer hardware,
so any computer with a Java interpreter can execute
the compiled Java program, no matter what type of
computer the program was compiled on
Java Features
• Some features of Java:
– The Java Virtual Machine
(byte code)
Java Features
The execution of java code internally will be in the
following steps:
Execution Command -->java Test
1.Start JVM
2.Create and Start Main Thread
3.Look at Test.class File
4.Load Test.class file
5.Execute Main method
6.Unload Test.class
7.Terminate Main Thread
8.Shut down JVM
Java Features
• Phases of a Java Program
Java Features
• Phases of a Java Program
Java Features
• Some features of Java:
– Garbage Collection
– responsible for
freeing any memory
that can be freed.
This happens automatically during the lifetime of the
Java program.
– programmer is freed from the burden of having to
deallocate that memory themselves
Java Features
• Some features of Java:
– Code Security
- Code security is
attained in Java
through the
implementation of its
Java Runtime Environment
● JRE
– runs code compiled for a
JVM and performs class loading (through the
class loader), code verification (through the
bytecode verifier) and finally code execution
CC102- PROGRAMMING FUNDAMENTALS
20
LESSON I – INTRODUCTION TO JAVA PROGRAMMING
Java Features
• Some features of Java:
– Platform Independence
- “write once, run anywhere.” (WORA)
-The Java compiler compiles the source code
into bytecode, which can be interpreted by a
suitable JVM on any platform.
Java Features
• Some features of Java:
– Platform Independence
Java Features
• Some features of Java:
– Object Oriented
Java Features
• Some features of Java:
– Object Oriented
– Encapsulation: combining an object’s
data with its methods
– Inheritance:
• Code reusability
• Code maintenance
• Implementing OOP
– Polymorphism: allows an object of a
superclass to refer to an object of any
subclass
Java Features
Coding reminders:
• A .java file name should match the name of a
class in the file. If one of those classes is declared
public, then the name of the .java file must
match the name of the public class
• There can be only one main class at maximum
in a source file
• The compiler generates a file with extension
.class corresponding to each class in the source
file that is compiled
• The name of the .class file matches the name of
the corresponding class
CC102- PROGRAMMING FUNDAMENTALS
29
LESSON I – INTRODUCTION TO JAVA PROGRAMMING
Tips: Names
Tips: Names
Classpath
• When the compiler or the interpreter encounters a
class name in your code, they look for classes in
each directory or a JAR (Java Archive) file listed in
the classpath
• Let’s assume that we put the class files in the
c:\app\class\com\netalong\course directory, the
classpath must include this:
path name:
C:\app\class
Example programs/activity:
/*
CallingMethodsInSameClass.java
* illustrates how to call public static void printOne(){
* static methods a class System.out.println("Hello World");
* from a method in the same }
* class*/ public static void printTwo() {
public class printOne();
CallingMethodsInSameClass printOne();
{ }
public static void }
main(String[] args) {
printOne();
printOne();
printTwo();
}