I find that the harder I work, the more luck I seem to have.
--Your friends at LectureNotes

Java Programming

by Prâ Ðêêp
Type: NoteOffline Downloads: 4Views: 203Uploaded: 22 days agoAdd to Favourite

Share it with your friends

Suggested Materials

Leave your Comments


Prâ Ðêêp
Prâ Ðêêp
Overview of Java Java is a high-level programming language originally developed by Sun Microsystems under the guidance of James Gosling and there team, and released in 1995. OOPs Concepts in Java Java is an Object-Oriented Language. As a language that has the Object-Oriented feature, Java supports the following fundamental concepts – 1) Object: Any entity that has state and behavior is known as an object. For example: chair, pen, table, keyboard, bike etc. It can be physical and logical. 2) Class: A class is a group of objects which have common properties. It is a template or blueprint from which objects are created. It is a logical entity. It can't be physical. 3) Encapsulation: Binding (or wrapping) code and data together into a single unit is known as encapsulation. A java class is the example of encapsulation. 4) Abstraction: Hiding internal details and showing functionality is known as abstraction. 5) Inheritance: The process by which one class acquires the properties and functionalities of another class is called inheritance. It provides code reusability. 6) Polymorphism: When one task is performed by different ways i.e. known as polymorphism. In java, we use method overloading and method overriding to achieve polymorphism. Features of Java 1) Simple: The Java language is easy to learn and its coding style is easy to read and write. 2) Object Oriented: It has all OOP features such as abstraction, encapsulation, inheritance and polymorphism. 3) Portable: Java programs can execute in any environment (Linux, Window, Mac etc.) 4) Platform Independent: Java is guaranteed to be Write Once, Run Anywhere language. 5) Secure: With Java's secure feature it enables to develop virus-free, tamper-free systems. 6) Robust: Its capability to handle Run-time Error, automatic garbage collection, the lack of pointer concept, Exception Handling etc. makes java robust. 7) Architectural Neutral: To enable a Java application to execute anywhere on the network, the compiler generates an architecture-neutral object file format.
8) Dynamic: It supports Dynamic memory allocation due to this memory wastage is reduce and improve performance of the application. 9) Interpreted: The Java compiler generates byte-codes, rather than native machine code. 10) High Performance: Java enables high performance with the use of just-in-time compiler. 11) Multithreaded: It utilizes same memory and other resources to execute multiple threads at the same time. 12) Distributed: It has networking facilities, so it can be transmit, run over internet. JDK (Java Development Kit): JDK is a container of tools which are needed to develop java programs. JRE (Java Runtime Environment): JRE is an implementation of the JVM which actually executes Java programs. JVM (Java Virtual Machine): JVM is an abstract machine that enables your computer to run a Java program Data Types in Java Data types represent the different values to be stored in the variable. In java, there are two types of data types:
1. Primitive data types: Primitive data types are predefined by the language and named by a keyword. 2. Non-primitive data types: These data types are those which are developed by programmers by making use of appropriate features of the language. Primitive Data Types Sr. No. Data Type 1. byte 2. short 3. int 4. long 5. float 6. double 7. char 8. boolean Size 1 byte 2 byte 4 byte 8 byte 4 byte 8 byte 2 byte 1 bit Contains Byte Length Integer Short Integer Integer Long Integer Single Precision Floating Point Double Precision Floating Point A Single Character(Unicode Character) A Boolean Value(True or False) Control Statements in Java The control statements are used to control the flow of execution of the program. Java contains the following types of control statements: 1) Branching Statements (Selection Statements) Selection statements allow you to control the flow of program execution on the basis of the outcome of an expression or state of a variable known during runtime. Selection statements can be divided into the following categories: • • The if statements: It executes the if block if condition is true. Syntax: if(condition) { //code to be executed } The if-else statements: It executes if block if condition is true otherwise else block is executed. Syntax: if(condition) { //code if condition is true } else
• • { //code if condition is false } The if-else-if statements (nested if-else statements): It executes one condition from multiple statements. Syntax: if(condition1) { //code to be executed if condition1 is true } else if(condition2) { //code to be executed if condition2 is true } else if(condition3) { //code to be executed if condition3 is true } ... else { //code to be executed if all the conditions are false } The switch statements: It is used when we have number of options (or choices) and we may need to perform a different task for each choice. Syntax: switch(expression) { case value1: //code to be executed; break; //optional case value2: //code to be executed; break; //optional ...... default: code to be executed if all cases are not matched; }

Lecture Notes