Java Presentation
Java Presentation
Java Presentation
Java was developed by a team lead by James Gosling at Sun Microsystems and released in 1995. It was originally intended as a lanuage for creating embedded software in consumer electronic devices. The internet and WWW made it a popular lanuage for creating platform independent programs. Java is a pure objected language. Java is case sensitive.The class name in the program and the filename should match in case. Java is available in many editions:Standard Edition, Enterprise Edition and micro Edition. All java Keywords must be typed in lowercase.
javac: The java compiler.it converts source code into bytescodes. java: The java application launcher.converts & executes bytecode. javadoc: The java commenting tool.creates HTML help file form
java source code. jdb: The java debugger.steps through programs as they executes,sets breakpoints and monitors behavior. javap: Disassembling classes.lists methods and class members. javah: Header file generator.used when combining java with c/c++ programs. jar: Java archive (JAR) manager.combines and compresses multiple files and directories into one. appletviewer: The java applet launcher.
Comments: Java supports three types of comments. 1-Single line comment :-It begin with a // and ends with new line
charater. Eg : // everything to the end of line is comments. 2-Multiline comment :- It starts with /* and ends with */ . Eg: /* this is multiline comments */ . 3-Javadoc comments :- It starts with /** and ends with */. Eg: /** everything here is a javadoc comment */ . Java Keywords :keywords are the predefined words of language. Data Types: It provides a set of built-in types as well as allows the user to create user defined types. Total 8 primitive data types in java. 1-Integer types : byte , short , int, long . 2-Floating points types : float , double . 3-Character typs : char . 4-Boolean type : boolean .
Control statements are used to control the flow of execution of statements in program. These statements are two categorized 1- Selection Statements : if , if-else ,Switch . 2-Loop Control Statements : while , do-while ,for . if statement : this statement executes a statement or group of statements only if the condition is true. otherwise false.not execute. Syntax- if(condition ) ststement ; Eg- if(errorcondition == 1) display() ; if-else Statement: This statement executes a statement or group of statement if the condition is true and another statement or group if the condition is false. it is a two way decision making statement. Syntax if (condition ) statement1;else statement2 ; Eg- if (n%2==0 ) System.out.println (Even Number); else System.out .println (Odd Number) ;
Loop Control Statement : These statement are used to repeat the execution of code for a fixed number of times or till some condition is satisfied . Condition should be boolean. Three loop statements. while loop : The while loop is a top-tested or entry controlled loop.this loop executes statement as the condition is true .as soon as the condition becomes false control comes out of the loop. Syntax Eg- i=0; while (condition) while (i<=10) { { System.out.println (value = +i); loop statement i=i+1; } } do-while loop: The do-while loop is bottom tested or exit controlled loop . this loop executes statement as the condition is true . the condition becomes false control comes out of the loop.
Syntax Eg int i=10 d0 d0 { { loop stetements System.out.println (value = +i); }while (condition) } while (--i>0); for loop : The for combines initialization,condition and loop expression in a single statement. this loop executes statement as the condition is true . the condition becomes false control comes out of the loop. Syntax Eg int i=1; for(initialization;condition;loop-expression) for(i=0;i<=10;i++) { { loop stetements System.out.println (value = +i); } }
Classes &objects are at the heart of object oriented programming. A class is blueprint for an object and an object is an instance of class. Defining Classes : A class define a new type.this new type can be used to create objects of that type.there are three type of classes 1-Concreate Class:concrete class is a class which can be instantiated. It is a complete class which defines data member,constractors, Methods and can also be suc-classed. 2-Abstract Class:It is incomplete class which cannot be instantiated. It defines data members,constructors,methods, declares sub-class methods. 3- Interface or Pure Abstract Class: an interface is a pure abstract class..lt declares methods and define constants as well. Creating Objects:A class define a new type.this new type can be used to create objects .To create objects of class ,two steps followed.
1-Declare a variable of class type . This variable does not create an Object.instead,it is simply a reference to an object. Syntax: ClassName object Name; 2- Acquire an actual physical copy of object and assign it to that variable using the new operator.it is dynamically allocates memory. Syntax: ClassName ObjectName = new ClassName (); Array Of Objects : create an array of objects.two steps follows 1- create an array of refernces using new. Syntax: ClassName [] arrayName =new ClassName [size]; 2- create an object for each refernce using new. Syntax: for(i=0; i<size; i++) arrayName [i] = new ClassName(); Eg:- MyRectangle [] r= new MyRectangle[5]; for (int i= 0; i<5 ; i++) r[i] = new MyRectangle();
A Constructors is special method of class which has the same name and is used for initializing the object member.this are two types. 1-Defolat Constructor :This is constructor with no parameter.it is automatically created by the compiler .it is no longer automatically. 2-Parameterized Constructor : This is constructor with parameter. It is assign specific values to member.this means that two or more methods can have the same signature within the same scope. Eg: class MyRectangle { int length ,breadth ; MyRectangle() // defolat constructor { length=0; breadth=0; } MyRectangle(int length,int breadth)//parameterized constructor { this.length=length ; this.breadth=breadth; } }
The Object Class: the Object class defines the basic state and
behavior that all objects must have such as the ability to compare to another objects to convert to a string. 1- equals method: is used to compare two objects for equality.it return true if objects are equals and false otherwise. Eg- string s1= hello; string s2=hello; if(s1.equals s2) system.out.println (they are Equals); 2-getClass method: it return this class object.we can get a variety of information about the class.Eg- Class c = obj.getClass(); 3-to String method: this method gives the String representation of an object.it returns a string that textually represents on objects. Eg- System.out.println (s.toString());
Package is a namespace that organizes a set of related classes and interface.the package which is imported by defaults is the java.lang package which contains language related classes. Creating Packages: to create a user define package .the package statement should be written in the source code file.only one package statement can be written in a file. Syntax : package <top_pkg_name> [.<sub_pkg_name>] * ; Eg- package maths.algebra; Accessing Packages : to use classes of a package in another package the classname must be qualified using the package name. Syntax : Package.className Eg- mypackage.MyClass. An easier method is to use the import statement.it allows us to access a specific class or all classes form a package. Syntax : import <pkg_name>[.<sub_pkg_name>].*.<class-name>;
Garbage collection is a machanism to remove objects from memory when they are no longer needed.Garbage collection is carried out by grabage collector.it runs as a separated thread.it invoked in two ways 1-Using System.gc() method. 2- Using an instance of the Runtime class and invoke gc (). Syntax : Runtime rt =Runtime.getRuntime(); Eg- rt.gc () ; finalize () : the purpose of finalization is to perform clean-up operations for the object i.e freeing resources ,deallocating memory,releasing connections, closing files etc. Stntax: protected void finalize () { // finalization code here }
Inheritance allows creation of new classes using existing ones.in java inheritance using the extends keyword.The class being inherited is called super,base or parent class and the class inherites properties is called sub ,derived or child class.its is-a relationship. Types are like 1-Single Inheritance: A class can have only one superclass. 2-Multilevel Inheritance: a subclass is further used to derive more classes. Eg- class B extends A and C extends class B. 3- Hierarhical Inheritance : A single superclass class ha many subclass.these are further used to create more subclasses. Member Access: A subclass inherits the member of its superclass but it cannot access all the members directly. Directly accessible: those superclass member which is declared public or protected. And no access speifier .and in same package. Not accessible: private data members and methods have same name
An abstract class is a class which h cannot be instantiated .i.e we cannot create objects of an abstract class.lt can only used to create subclass. Syntax :abstract class CalssName {} An abstract class contain data member,constructor,method ,static . Abstract Methode: An abstract class provides all the functionality required by all its subclass.An abstract method has to be overridden in the subclass .a class having an abstract method must declared as abstract. Syntax : abstract returntype methodName (parameters); Eg : abstract int area () ; Final Keyword: The use of final to create constant. The final keyword is used for these two purpose. 1-Preventing method overriding : can not override in subclass. 2- Preventing Inheritance : class is declared final cannot be inherited in subclass.
It is an fully abstract class which does not contain any instance member but only method declarations. These are implicity static and final .it is used two or more classes have the same behavior. Syntax: modifier interface <interfaceName>[extends <super interfacename>] { type methodName (parameters) .} Tagging Interfaces: some interface are defined without any methods or constant is called as tagging or marker onterface. Impementing Interface : one or more classes can implements that interface .using implement keyword in its declaration. Synyax : modifier class ClassName extends SuperClassName [implements InterfaceName1 [InterfaceName2.]] { // class body } Object Cloning : it means creating a copy of an object.object cloning create a new object which is identical to one being cloned. Eg: MyRectangle r1 =new myrectangle (); r2=r1;
In java it is possible to define a class within another class;such classes are called as nested classes. Syntax : class outerClass { // variable and methods of outer class class NestedClass { // variable and mrthods of nested class } } Since a nested class does not exit outside the outer class,an object of the nested class should be created inside the outer class.the nested class object stores a reference to the outer class object and can access all its member. Two type of nested classes. 1- Static nested : static nested class is also called as outer class. 2-Non static nested:non static nested class is also called as inner class
An Exception is an abnormal condition that arises in code at run time.exception is a runtime error.java ia inbuilt exceptin handling. There are two types of exception 1-Checked Exception :Except for RuntimeException ,error and their subclasses all other exception are called checked exceptions. Eg- IO 2-Unchecked Excepyion : Exception defined by error and Runtime Exception classes and their subclasses are called as unchecked exception. Eg- NullPointerException . Exception Handaling :exception handling in java is using 5 keyword 1-try:Exception are written within try block. 2-catch : that secifices the exception type that you wish to catch. 3- throw : is used to explicity throw an exception object. 4-throws : is used in a method header to declare exception. 5-finally : is executed whether or not an exceptions.
An applet is small java program which runs in a web browser. An applet is created by inherting from the java.applet.Applet class or the javax.swing.Japplet class. Applet Lifecycle : the Applet class defines five methods that control the creation and execution of an applet.this are 1- init () : Automatically called to perform frist-time initialization of the applet. 2- start() :every time the applet moves into sight on the web browser to allow the applet to start up its normal operations.called after init() 3-stop() : every time the applet moves into sight on the web browser to allow the applet to shut off its expensive operations.befor destroy() 4-destroy() : called when the applet is being unloaded from the page to perfrom final release of resources when applet is no longer used. 5-paint() : called each time the applet output needs to be redrawn.