Download presentation
Presentation is loading. Please wait.
Published byVincent Harper Modified over 9 years ago
2
SOFTWARE TECHNOLOGY - I JAVA/OOP Wickramanayake HMKSK kamal@ee.pdn.ac.lk Department of Electrical & Electronic Engineering Faculty of Engineering University of Peradeniya Peradeniya
3
HISTORY ● Developed by Sun Microsystems in 1991 ● Originally called Oak ● Originally designed for Tvs, VCRs, Toasters, etc ● Mostly based on C & C++ ● Simple and reliable ● Platform-neutral (WORA) James Gosling
4
JAVA FEATURES ● Compiled and Interpreted ● Platform Independent and Portable ● Object Oriented ● Robust and Secure ● Distributed ● Familiar, Simple and Small ● Multithreaded and Interactive ● High Performance ● Dynamic and Extensible
5
Places where Java is used ● Screen phones ● Mobile phones ● Desktop computers with Java enabled web browsers ● Desktop computers with Java technology based applications ● Servers with Java applications and Servlets
6
JDK, SDK & JRE
7
Java Development Kit Tools ● appletviewer ● javac ● java ● javap ● javah ● javadoc ● jdb
8
Life of a Java Program
9
Types of Java Programs ● Stand-alone applications Console based and GUI based applications that run of their own. Require JRE installed in the machine. ● Applets Small programs that run inside a Java enabled web browser (Java plug-in installed).
10
A Simple Program class MyFirstProg { public static void main(String[] args) { System.out.println("I am Kamal"); } Exercises: Modify the above program to print your name below my name. Replace System.out.println("I am Kamal") by System.out.print("I am Kamal") and see the output. MyFirstProg main(args : String[])
11
Java Platform
12
Find the square root of a number /* This program finds the square root of a number. This was written by kamal@ee.pdn.ac.lk. 22-January 2003Version 0.1 Copyright 2003 */ import java.lang.Math; class SquareRoot { public static void main(String[] args) { double x = 5.0;// Declare, initialize double y;// Just declare y = Math.sqrt(x); System.out.println("Square root of " + x + " is " + y); } Exercise: Draw a class diagram for the SquareRoot class.
13
Important points... ● Comments /* This is a multiple line comment........ / // This is an end of line comment /** This is a documentation comment........ */
14
Important points... (cont.) ● import statement "import java.lang.Math;" line tells the compiler to use the "Math" class of the "java.lang" package. Examples: import java.net.*;// import all classes of net package import javax.swing.*; // import swing package classes
15
Two class example class Person { String name;// A string to hold the name int age;// An integer to hold the age void setName(String new_name) { name = new_name; } void setAge(int new_age) { age = new_age; } void showInfo() { System.out.println(name + " is " + age + " years old"); }
16
Two class example... class PersonTest { public static void main(String[] args) { Person me = new Person(); // Create an object called me me.setName("Kamal"); me.setAge(26); Person you = new Person();// Create an object called you you.setName("Your name here"); you.setAge(85); me.showInfo(); you.showInto(); }// main() ends here }// class PersonTest ends here
17
Class Diagrams
18
Java Program Structure ● Documentation Section ● Package Statement ● Import Statements ● Interface Statements ● Class Definitions ● Main Method Class
19
Java Tokens ● Reserved Keywords class, int, public, static, etc... ● Identifiers MyProg, me, age,... ● Literals 23, "Kamal", false,... ● Operators +, -, *,... ● Separators (, ), {, ",",...
20
Token Exercise Identify comments, white spaces, different types of tokens in the following program. /* Token Test Program */ import java.util.*; class DateTest { public static void main(String[] args) { Date today = new Date(); // Create a Date object System.out.println(today); }
21
Command Line Arguments /* WARNING: This program might throw an ArrayIndexOutOfBounds exception */ class MyProgram { public static void main(String[] args) { System.out.println("No of arguments: " + args.length); System.out.println("First argument: " + args[0]); System.out.println("Second argument: " + args[1]); }
22
Command Line Arguments... class MyProg { public static void main(String[] args) { int i = 0; while(i < args.length) { System.out.printn(args[i]); i = i + 1; } Exercises: Write a program to print integers from 0 to 10 using a while loop. Write a program to print integers from 10 to 0 using a while loop.
23
Wisdom comes not from extensive reading, but from inward inspection and reflection
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.