• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Android webinar class_java_review
 

Android webinar class_java_review

on

  • 336 views

 

Statistics

Views

Total Views
336
Views on SlideShare
336
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Not just a programming language but a complete platformThe Programming language Java standard class libraries which provide Application Programming Interface and JVM together form JRE (Java Runtime Environment)JDK (Java development kit) provides all the needed support for software development in Java.
  • Need a diagram to show garbage collection
  • Java compilers convert your code from human readable Java source files to something called “bytecode” in the Java world. “Bytecode” is interpreted by a JVM, which operates much like a physical CPU might operate on machine code, to actually execute the compiled code. Performance - Java performance in generally second only to C/C++ in common language performance comparisons. In the Java programming language and environment, a just-in-time (JIT) compiler is a program that turns Java bytecode (a program that contains instructions that must be interpreted) into instructions that can be sent directly to the processor.The just-in-time compiler comes with the virtual machine and is used optionally. It compiles the bytecode into platform-specific executable code that is immediately executed
  • Java compilers convert your code from human readable Java source files to something called “bytecode” in the Java world. “Bytecode” is interpreted by a JVM, which operates much like a physical CPU might operate on machine code, to actually execute the compiled code. Performance - Java performance in generally second only to C/C++ in common language performance comparisons. In the Java programming language and environment, a just-in-time (JIT) compiler is a program that turns Java bytecode (a program that contains instructions that must be interpreted) into instructions that can be sent directly to the processor.The just-in-time compiler comes with the virtual machine and is used optionally. It compiles the bytecode into platform-specific executable code that is immediately executed
  • Adv. Question : What is the range of primitive data types ?Initalization:If no value is assigned prior to use, then the compiler will give an errorJava sets primitive variables to zero or false in the case of a boolean variableAll object references are initially set to null
  • Java provides six relational operators:greater than (>), less than (=), less than or equal (<=), equal (==), and not equal (!=).
  • Is it really needed to define all the types of operators.It will be better to show their differences through a program.
  • DemoBroke into multiple sentences
  • DemoReformatted and used clip art for right and wrong
  • Demo
  • Public/PrivateMethods/data may be declared public or private meaning they may or may not be accessed by code in other classes …Good practice:keep data privatekeep most methods privatewell-defined interface between classes - helps to eliminate errors

Android webinar class_java_review Android webinar class_java_review Presentation Transcript

  • Java Review(Essentials of Java for Android)
  • What is Java ?• Java - Java is not just a programming language but it is a complete platform for object oriented programming.• JRE - Java standard class libraries which provide Application Programming Interface and JVM together form JRE (Java Runtime Environment).• JDK - JDK (Java development kit) provides all the needed support for software development in Java.
  • Java Virtual Machine (JVM)• Runs the Byte Code.• Makes Java platform independent.• Handles Memory Management.
  • Garbage Collection• The programmer is not responsible for memory management in Java.• The memory area in JVM where objects are created is called Heap.• The memory is freed during runtime by a special thread called Garbage Collector.• The GC looks for objects which are no longer needed by the program and destroys them.
  • Memory Management In Java
  • How Java works ?• Java compilers convert your code from human readable to something called “bytecode” in the Java world.• “Bytecode” is interpreted by a JVM, which operates much like a physical CPU to actually execute the compiled code.• Just-in-time (JIT) compiler is a program that turns Java bytecode into instructions that can be sent directly to the processor.
  • How Java works ?
  • Basic Java Syntax
  • Data Types in Java• Data types define the nature of a value• We need different data-types to handle real-world information Name Size (in bits) Range long 64 -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 int 32 –2,147,483,648 to 2,147,483,647 Short 16 –32,768 to 32,767 byte 8 –128 to 127 double 64 4.9e–324 to 1.8e+308 float 32 1.4e–045 to 3.4e+038 char 16 0 to 65,536 boolean ?? true/false
  • Primitive Types and Variables • boolean, char, byte, short, int, long, float, double etc. • These basic (or primitive) types are the only types that are not objects (due to performance issues). • This means that you don’t use the new operator to create a primitive variable.
  • Naming Convention of Variables• Can start with a letter, an underscore(_), or a dollar sign ($)• Cannot start with a number. long _LongNumber = 9999999; String firstName = “John”; float $Val = 2.3f; int i, index = 2; double gamma = 1.2; boolean value2 = false;
  • Operators• Provide a way to perform different operations on variables• Categories of Java Operators Assignment Operators = Arithmetic Operators - + * / % Relational Operators > < >= <= == != Logical Operators && || & | ^ Unary Operators + - ++ -- !
  • Assignment and Arithmetic Operators• Used to assign a value to a variable• Syntax – <variable> = <expression> Assignment Operator =• Java provides eight Arithmetic operators: – for addition, subtraction, multiplication, division, modulo (or remainder), increment (or add 1), decrement (or subtract 1), and negation.
  • Relational Operators• Used to compare two values.• Binary operators, and their operands are numeric expressions. Relational Operators > < >= <= == !=
  • Logical Operators• Return a true or false value based on the state of the variables• There are six logical operators Conditional AND Conditional OR AND OR NOT Exclusive OR Logical Operators && || & | ! ^
  • Static versus Non-static Variables• Static variables are shared across all the objects of a class – There is only one copy• Non-Static variables are not shared – There is a separate copy for each individual live object.• Static variables cannot be declared within a method.
  • Statements & Blocks• A simple statement is a command terminated by a semi-colon: name = “Fred”;• A block is a compound statement enclosed in curly brackets: { name1 = “Fred”; name2 = “Bill”; }• Blocks may contain other blocks.
  • Flow of Control• Java executes one statement after the other in the order they are written.• Many Java statements are flow control statements: Alternation: if, if else, switch Looping: for, while, do while
  • Java Basic Constructs• If…else• Switch Statement• For Loop• While Loop• Do...While Loop
  • If else– Syntaxif ( <condition> ){ // Execute these statements if <condition> is TRUE}else{ // Execute these statements if < condition> is FALSE}
  • switch– Syntaxswitch (expression){case cond1: block_1; break;case cond2: block_2; break;...default: block_default;}
  • For– Syntaxfor (initialization; condition; increment/decrement){ statement 1; statement 2; . . }Sample:for( int i=0; i<5; i++ ){ System.out.println(i);}
  • While – Syntaxwhile (condition){ statement 1; statement 2; . . }Sample:int i=0;while (i<5){ System.out.println(i); i++;}
  • Do While – Syntaxdo{ statement 1; statement 2; . .} while (condition) ;Sample:int i=0;do{ System.out.println(i); i++;} while (i<5);
  • Arrays• An array is a list of similar things.• An array has a fixed: – name – type – length• These must be declared when the array is created.• Array size cannot be changed during the execution of the code.
  • Example of an Array myArray = 3 6 3 1 6 3 4 1 0 1 2 3 4 5 6 7 myArray has room for 8 elements  the elements are accessed by their index.  in Java, array indices starts at 0.
  • Some more Examplesfloat[] anArrayOfFloats = new float[5];Car [] cars = new Car()[3]; // an array of cars capable of storing 3 car objectsObject[] anArrayOfObjects = new Objects[100];boolean[] answers = { true, false, true, true, false };How to get the length of an array object ?cars.length ✔ waycars.length() ✗ way
  • Java Methods & Classes
  • Java OOP• Create new object type with class keyword.• A class definition can contain: – variables (fields) – initialization code – methods Java Programming: OOP 29
  • An Example classpackage com.edureka.entity; // packagepublic class Car{ //class declaration String name; String color; float weight; ... public void move(){ // method ... }}
  • Objects• Runtime representation of a class.• Objects hold state with variables• Objects do some work with methods.• Can be created during Runtime as follows : Car carRef = new Car(); carRef New Car() Object Reference Newly created Object
  • Methods• A method is a named sequence of code that can be invoked by other Java code.• A method takes some parameters, performs some computations and then optionally returns a value (or object).• Methods can be used as part of an expression statement. Ex: public float convert_to _Celsius( float temp) { return(((temp * 9.0f) / 5.0f) + 32.0f ); }
  • Modifiers• public: any method (in any class) can access the field.• protected: any method in the same package or any derived class can access the field.• private: only methods within the class can access the field.• default is that only methods in the same package can access the field. Java Programming: OOP 33
  • •Q& A..?
  • Thanks..!