Source Code Byte Code Object Code
Total Page:16
File Type:pdf, Size:1020Kb
Class 8 Chapter 7 Introduction to BlueJ What is JAVA? Java is a high-level programming language. It is developed by Sun Microsystem in 1995. Java is pure object oriented programming language. What are the features of Java? Five features of Java are: 1. It is an Object Oriented Programming Language. 2. It is platform independent. It provides us Write Once, Run Anywhere (WORA) feature. 3. It uses a compiler as well as an interpreter. 4. It is case sensitive. 5. It is secured. Why Java is called a Platform Independence Language? Java is WORA (Write Once Run Anywhere). Java programs are compiled to Bytecode that can run on any Java Virtual Machine (JVM). Therefore it is called Platform independent. Source Compiled Byte Interpreted Object code code JVM code What are the features of Object Oriented Programming? 1. Object- Object is an instance of a class. These objects share two characteristics: state (data) and behavior (functions), which define meaningful operations on that object. Example, we humans have different name, address, mobile numbers etc. but doing common functions like talking, walking, reading, sleeping etc. 2. Class- A Class is used to create various Objects that have different characteristics and common behaviors just like a factory can produce similar items based on a particular design. Each object follows all the features defined within a class. That is why class is also referred to as a blue print or prototype of an object. 3. Abstraction- Abstraction means data hiding. It hides the complexity of the program and shows only required things to the outside world. 4. Encapsulation- Encapsulation is a process in which data and function are combined together as a bundle. Encapsulation can be achieved by Access Specifiers (public, private, protected). 5. Inheritance- Inheritance is a process in which properties of parent (Base) class are inherited by the child (Derived) class. 6. Polymorphism- Polymorphism means having same thing in many forms. You can define more than one function with the same name is called Polymorphism. What is BlueJ? BlueJ is a free java Development environment that allows you to develop java programs quickly and easily. BlueJ is an IDE (Integrated Development Environment). What are the features of BlueJ? Five features of BlueJ are: 1. Simple beginner friendly graphical user interface. 2. It allows creating objects of the class dynamically, invoking their methods and also supplying data to the method arguments if present. 3. It supports syntax highlighting. (Syntax highlighting means showing the different tokens of the program like keywords, variables, separators, etc. in different colours so that they show up more clearly.) 4. It facilitates easier debugging as lines causing compilation errors are marked clearly and the error is displayed at the bottom of the window. 5. It provides a code editor, compiler and debugger integrated into a single tool. Write the different component of a program. 1. Identifiers 2. Keywords 3. Literal 4. Datatypes 5. Operators 6. Variables What is Identifier? Also write the rules of Identifier. Any name of class, method, variable package or interface in program is called identifier, which is used for identification purpose. Rules- 1. Identifier should be a single and meaning full word. No space allowed 2. Identifier should start with an alphabet or underscore or $ symbol. 3. Identifier should not be a keyword. 4. Identifiers are case sensitive. 5. Identifiers can be Alphanumeric Characters. What are keywords? Keywords are reserved words that carries special meaning to the compiler. For Ex. class, int, for, etc What are Literals? Literals refers to fixed value that do not change during the execution of the program. Types of Literals 1. Integer – Can take only Positive and Negative numbers without decimal places. 2. Floating Point - Can take only Positive and Negative numbers with decimal places. 3. Character- Any single character enclosed within single inverted comma. 4. Boolean- It can take only two values true or false. 5. String – It can take more than one Character within double inverted comma. What are DataTypes? DataTypes define the type of data that can be stored within a variable in the program. There are two types of DataType - • Primitive data types: There are 8 primitive datatypes. These are predefined by the language and named as a keyword. • Non- Primitive data types: These are user defined data types. Such as Array, String, Class etc. Explain briefly all types of Primitive data types with example. Category Data Types Description Default Default Example value size Boolean boolean Takes only false 1 bit or boolean two values: 1 byte f=false true or false. It is used to track the conditions. Integer byte It will take 0 1 byte byte a=10 only between -128 to +127 short It will take 0 2 byte short a=30000 between - 32,768 to +32,767 int It will take 0 4 byte int a= between -231 234567890 to +231-1 long It will take 0L 8 byte long between -263 a=1234056789 to +263 -1 Character char It will take ‘\u0000’ 2 byte char a=’a’ one character at a time. Floating float It can take 0.0f 4 byte float a=5.6f Point decimal values till 6 digits. Like ±3.4e+38 double It can take 0.0d 8 byte double decimal a=5.678d value till 15 digits. What are Operators? Explain types of operators briefly. Operators are symbols that are used to perform different types of operations. There are following types of operators- Arithmetic operators- These are used to perform mathematical calculations Operators Description Execution Example ++ Increment ++a means a=a+1 solve first -- Decrement } -- means a=a-1 () Bracket Solve second (3+4)-7=0 % Modulas 7%4=3 (remainder) / Division } solve next which 7/4=1 (quotient) * Multiplication 7*4=28 come first + Addition 7+4=11 solve next which - Subtraction } 7-4=3 come first Relational operators- These are used to compare two values and give Boolean result. These are used with decision statements. Operator Description Example == Equal to 3 == 3 returns true != Not Equal 3 != 3 returns false > Greater than 3 > 2 returns true < Less than 3 < 2 returns false >= Greater than or Equal to 3 >= 3 return true <= Less than or equal to 3 <= 2 returns false Logical operators- These are used to check multiple conditions and return Boolean results. Operator Name Example Description || And (3 > 2) && (3 < 4) Means If all conditions returns true. are true. Then result will be true otherwise false ! Or (3 > 2) || (4 < 3) Means if any or all returns true conditions are true, the result will be true otherwise false. && Not !(3 >4 ) returns true Means it returns the opposite of the condition that is if condition is true it will return false otherwise return true. Assignment Operator- Assignment Operator (=) is used to store right side value to the left side variable. For Example- a = 4 means 4 will be stored in variable a. What is a variable? Explain the method of declaration and Initialization. A variable is a container which holds the value at the time of program execution. Variable is a name of memory location. Variable is a mixture of two terms, vary + able that means its value can be changed. Example: int age = 10, float price = 300.0, char letter = ‘W’; Here age, price, letters are variable names. Declaration: You are only creating a space in memory without any value. Syntax: <DataType> <Identifier>; Example : int age; float price, rate; You can define multiple variables separated by comma sign. Initialization : In initialization, you can assign a value to the variable. Syntax: <DataType> <Identifier> = <Value>; Example: int age = 18; float price = 340.95; Exercise Fill in the blanks- 1. Inheritance is a process in which properties of parent class are inherited by the child class. 2. Keywords are Reserved words that have predefined meaning in the language. 3. Boolean data type has only two value: true or false. 4. Operator is a symbol that is used to perform operations. 5. Literal refer to Fixed value that do not change during the execution of the program. Write T for the true statement and F for the False one: 1. Java is not secure and robust. F 2. Class contains both data and functions together. T 3. Variable is a name of memory location. T 4. Polymorphism allows us to define more than one function with same Name. T 5. BlueJ is an ITE (Integrated Training Environment). F Choose the right Option: 1) Identify the relational Operator a) ++ b) <= c) && 2) Identify Arithmetic Operator a) || b) % c) == 3) Identify the Logical Operator a) != b) % c) ! 4) Identify Assignment Operator a) >= b) == c) = 5) Choose the non-primitive data type a) Byte b) Boolean c) Array .