Sie sind auf Seite 1von 42

Made by-Bhumika Dikola Divyasha

Introduction Java virtual machine JRE and JDK Garbage Collector Java Bean Convention Arrays Inheritance Interface Dynamic Method Dispatching Exception Handling Package AWT JFC Event Handling String Wrapper Classes Database connectivity File Handling Applet Threading

Java is a programming language created by James Gosling from Sun Microsystems in 1991. The first publicly available version of Java (Java 1.0) was released in 1995. Its more platform independent
this makes it great for Web programming

Its almost entirely object-oriented. Its more secure. It does Automatic Memory Management.

The .class files generated by the compiler are not

executable binaries
so Java combines compilation and interpretation

Instead, they contain byte-codes to be executed

by the Java Virtual Machine.


This approach provides platform independence, and

greater security.
The Java virtual machine is written specifically for a

specific operating system.

A Java distribution comes typically in two flavors,

the Java Runtime Environment (JRE) and the Java Development Kit (JDK).
The JRE consists of the JVM and the Java class

libraries and contains the necessary functionality to start Java programs.


The JDK contains in addition the development tools necessary to create Java programs. The JDK consists therefore of a Java compiler, the JVM, and the Java

class libraries.

Garbage Collector is itself a Demon Thread which

automatically deallocates the memory at the end of the program.


Demon Thread is a program which runs

continuously in OS from starting of the computer to its switching off.


The garbage collector releases the programmer

from the need to explicitly manage memory .


It is called by the JVM.

Class Method Variable Class_ constants

StudentDemo studentDemo studentDemo

STUDENTDEMO

In java array is an object.

Types of Array1. 1-D Array syntax: datatype []ref_name=new datatype[size];


2. 2-D Array syntax: datatype [][]ref_name=new datatype[size][size]; 3. Jagged Array syntax: datatype [][]ref_name=new datatype[size][];

When the derived class inherits properties from base class & also can have some features of its own.
Inheritance

"Is a Relationship

Has a Relationship

Object is the super class of every class . Inheritance is achieved by the keyword extends

It is a purely abstract class,has no body in methods thus objects cant be created. Inheritance of Interface is done using keyword implements. Multiple inheritance is possible with Interfaces. It can inherit other interfaces by using keyword extends.

Dynamic Method Dispatching


The reference of super class can point to the object of

subclass. import java.lang.Object keyword final : for a variable: Once a variable is declared as final,its value cant be changed. for a class: A final class cant be abstract. for a method:A final method cant be abstract.

Exception is the super class of all the runtime exceptions. What do you do when Exception occurs1.Either handle it by using try-catch-finally. 2.Throw the exception back to the calling method.

Exceptions fall into two categories:


Checked Exceptions Unchecked Exceptions

class A{ public static void main(String arg[]) {int a=4,b=0; try{ System.out.println(a/b); }catch(Exception e) { System.out.println(e); } } }

Packages

are javas way of grouping a variety of classes & interfaces together.


JAVA

lang

util

io

awt

net

applet

Fig: Frequently Used API Packages

awt stands for Abstract Window Toolkit. awt is a set of classes for implementing graphical user interface(GUI). They include classes for windows, buttons , lists, menus and so on . . . The awt is a package within the package java. some classes under awt package are Frame,Color,Graphics,Button,Label etc.

The Java Foundation Classes (JFC) are a graphical framework for building portable Javabased graphical user interfaces (GUIs) JFC classes are also known as swing field as we can import JFC classes by javax.swing.JFrame; It does not interact with the operating system. Drawbacks of awt package is overcome through JFC. It doesnt have any native API control.

Event is a folder inside the awt package. Event Handling-the process of responding to button clicks,mouse movements and so on . . Default event model of Java is Delegated Event Handling. For registering the events we need to implement an Event Listener interface.

1. 2.

3. 4.

Commonly used interfaces of Events areActionListener handles action events such as button clicks. MouseListener- listens for cases in which the mouse is dragged,moved or clicked. ItemListener-handles the cases in which the state of an item changes. KeyListener- listens for keyboard events.

String class is present under lang package. String class makes immutable objects.
Hello World Hello World Memory

String a=Hello; a=a+World; System.out.print(a);

For

creating a mutable string object we use StringBuffer class.

Wrapper

class is present under java.lang package.

Why was Wrapper class introduced? - Some people had a view that, since java uses primitive Data types thus they didnt consider java as purely Object Oriented This led to the Introduction of WRAPPER CLASSES.
PRIMITIVE TYPES byte boolean char double float WRAPPER CLASSES Byte Boolean Char Double Float

int

Integer

A database is an organized collection of data. In computer science, a database connection is the means by which a database server and its client software communicate with each other.

The term database connection is used whether or not the client and the server are on different machines.
The client uses a database connection to send commands to and receive replies from the server.

The PRIMARY KEY constraint uniquely identifies each record in a database table; must contain unique values; cant have NULL values. A FOREIGN KEY in one table points to a PRIMARY KEY in another table. We may write a query connecting to table named login as

String q=Select * from login where username=Mita and password= mita;

Java supports many powerful features for managing input & output of data using files called FILE HANDLING . Stream is the flow of data between Java program & File. To use file Handling we have to import java.io package which throws Checked Exception.

FileInputStream and FileOutputStream are subclasses of InputStream and OutputStream respectively. The FileOutputStream class is meant for writing streams of raw bytes into files The FileInputStream class is designed for reading streams of raw bytes from files. Buffer classes are used to increase the size of Input-Output Stream.

Character Stream Classes Character streams can be used to read & write 16 bits character.

CHARACTER STREAM CLASS

READER STREAM CLASS

WRITER STREAM CLASS

Serialization is the process of writing objects to a stream and reading them back. The serialization facilities can save and store the objects that implement the serializable Interface which defines no members. To work with serializable Objects we use two classes:a. ObjectInputStream b. ObjectOutputStream

Applets are small java program which can be transported over the internet from one computer to another and run using the Applet Viewer or any web browser that supports Java.

It is a package as well as class. It is used for client side programming. It cant interact with any file system in client side. It requires JVM to run and every web browser has its own JVM. We cant run .exe files using Applets. Applets dont use main() method for initiating the execution of the code.

1. 2. 3. 4.

We cant create objects in applet programming ,instead they are created by the Web Browsers Java. Applet are run from inside a web page using html tags. Applet are restricted from using libraries from other languages such as C or C++. We have to inherit Appletclass in our programs to run the applets and the inheritance is of type is a relationship. four default functions of Applets : public void init(); public void start(); public void stop(); public void destroy();

java.lang.Object

java.awt.Component

java.awt.Container

java.awt.Panel

java.applet.Applet

THREADING
A Thread is a stream of code execution. Multithreading is a conceptual programming paradigm where a program(process) is divided into two or more subprograms ,which can be implemented at the same time in parallel. Thread class is present inside the java.lang package. The main() function is itself a thread. There are two ways to create your own Thread 1. implementing the Runnable interface . 2. extending the Thread class. The run() method is the heart and soul of any thread.

We can give the threads different priority .

The default priority assigned to the thread is 5. Synchronization : excluding other threads from an operation that operation has completed is called Synchronization. There are two ways to Synchronize thread code execution 1. synchronizing block of codes. 2. synchronizing methods.

until

synchronizing block of code :


synchronized (lock-object) { .. //code here is synchronized. .. }

synchronizing a method :
synchronized method() { . . }

so this was

little cup of java coffee

Das könnte Ihnen auch gefallen