Introduction To Java
Introduction To Java
Course Description
Location : SREC Lectures: Weekdays at 11:00 am Labs: Weekdays at 01:30 pm Presenter: Sujit Majety, Software Engineer, Tech Fort IT Solutions (INDIA) PVT Ltd.
Features
JVM Architecture of JVM Introduction to OOPS Object Class
Introduction to JAVA
The slogan of java is write once and run anywhere, this allowed java to gain enormous popularity. Its rapid ascensation and wide acceptance can be traced to its design and programming features.
The name JAVA came from the name of the coffee seed. JAVA released to market in three versions J2SE, J2EE, J2ME
Programming Paradigm
Procedure Oriented
Object Oriented
More emphasis on algorithms. Programs divided into functions. Most functions share data, less security to data. Data move around the system between functions, any function can change the data. Adding new code is very difficult.
More emphasis on data. Programs are divided into objects. Functions operate on data are tied together in the data structure.
Data is secured; it is hidden to external functions, can be accessed by functions tied to it.
Adding new code is very easy.
History
Features
There are eleven promising features in java
Simple (no pointers, interfaces, rich set of API, friendly syntaxes) Secure (many number of security mechanisms to block stray programs) Portable (can run on any operating system) Robust (memory management, exceptional handling) Distributed (runs on multiple servers and can be accessed by no of clients) Interpreted (both compiled and interpreted) Multi Threading (multiple flow of controls) Dynamic (is always open for updating) Architecture Neutral (can run on any processor) High Performance (garbage collector, leaves resources wile waiting for inputs) Object oriented (everything is written in class)
Architecture of JVM
Class Files
Method Area
Heap
Stack
PC Registers
Execution Engine
Introduction to OOPS
Object oriented programming models the real world. Object oriented programming organizes a program around its data and set of well defined interfaces to that data. An object-oriented program can be characterized as data controlling access to code. By switching the controlling entity to data, you can achieve several organizational benefits. Object oriented programming, the first letter indicates object. What is an object?
Object
An object is the basic unit of object orientation with behaviour and identity. An object is a real time entity. E.g.. Car, bike, book, me and you.
E.g. An object is created to represent a rabbit. It would have data: how hungry it is, where it is. And methods : eat, hide, run and dig.
Class
A class is a way of binding the data and associated methods into a single unit. A class can also be said as a blue print to create an object.
If we want to develop a java program, then that should be developed with respective of class only. i.e. without class there is no java program.
Syntax:
Class Name Data members/ properties/ Attributes Animal Name, Number of legs, Colour
Class <clsname>
{
Variable declaration; Methods definition; };
Behaviours/ Methods
Sample Program
class Test {
public static void main(String[] args) { System.out.println(Hello World); } } Execution: > javac Test.java > java Test
The java program execution can be seen through the following figure.
Test.class
JVM
JVM converts byte code to m/c code
Console
Byte code
Program Output
What is the most widely used protocol on internet What is the difference between an executable file and .class file?
Assignments
Check the hello world program by removing each and every word. Shuffle the order of public static void main Try experimenting with print & println. Try giving different names for args. Try giving int args[] instead of String args[] in main. Give Different name for the filename and the class name Repeat the above problem with declaring class as public
Copy the class file into different folder name and execute it.
Write your own program, compile it and execute it. Try giving different data types ( the one you know like int x, double d ) in the prinltn and see if it prints all of them. I have two Integers int x =1; and int x=2; I wish to print 12. find the ways to print.
Repeat the same if I want to print given int x=1; double d=2.5; and print 12 instead of 12.5
Questions?