Published on

Published in: Education, Technology
1 Comment
  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Property of AuD©
  • Property of AuD©
  • Java

    1. 1. JAVA AuD©
    2. 2. JAVA
    3. 3. Introduction to javaJava is a object oriented programming languagewhich developed by James Gosling at SunMicrosystems (which is now a subsidiary of OracleCorporation) and released in 1995 .It is platform independent which can call as portableUsing java we can create interactive web pages orprogram to PC or mobileSo Lets get started…………………………………
    4. 4. Introduction to javaOver 3.5 people learn java and using it day by day inplaces like NASA , IBM and so.Java was originally created for run simple webapplications.
    5. 5. What we can do??Web serversRelational databasesOrbiting telescopesPDACellular phonesBlue-ray disks
    6. 6. History of javaJames Gosling, Mike Sheridan, and Patrick Naught oninitiated the Java language project in June 1991.Javawas originally designed for interactive television, butit was too advanced for the digital cable televisionindustry at the time. The language was initially calledOak after an oak tree that stood outside Goslingsoffice; it went by the name Green later, and was laterrenamed Java, from a list of random words. Goslingaimed to implement a virtual machine and a languagethat had a familiar C/C++ style of notation
    7. 7. Java programsJava applications Java application is a program that run from command line interfaceJava Applets Java applets are programs that run on web pages. It also compile on cmd but to run you must have web browserJava servlet This is a special program that runs on web browser(for on line soft ware)
    8. 8. Advantages of javaSimple Java program left many of the unnecessary features of high level languageObject oriented Java programs use OOP concepts to create programsPortable Java program can run in any flat form (Windows, Linux, mac OS X etc…) as long as it install Java runtime(JVM)
    9. 9. Advantages of javaMultithreaded Java program can perform several tasks @ same time which most of programming languages can’t;SecureHigh performanceDistributedDynamic
    10. 10. How java work
    11. 11. OOPWhat Is an Object? An object is a software bundle of related state and behavior. Software objects are often used to model the real-world objects that you find in everyday life.What is a class? Class is a collection of a objects with common properties.
    12. 12. ObjectSoftware objects are conceptually similar to real-worldobjects: they too consist of state and related behavior. Anobject stores its state in fields (variables in someprogramming languages) and exposes its behaviorthrough methods (functions in some programminglanguages). Methods operate on an objects internal stateand serve as the primary mechanism for object-to-objectcommunication. Hiding internal state and requiring allinteraction to be performed through an objects methodsis known as data encapsulation — a fundamental principleof object-oriented programming.
    13. 13. ObjectObjects are key to understanding object-orientedtechnology. Look around right now and youll find manyexamples of real-world objects: your dog, your desk, yourtelevision set, your bicycle. Real-world objects share twocharacteristics: They all have state and behavior. Dogs have state<attributes> (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Bicycles also have state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes). Identifying the state and behavior for real-world objects is a great way to begin thinking in terms of object-oriented programming.
    14. 14. ClassIn the real world, youll often find many individualobjects all of the same kind. There may be thousandsof other bicycles in existence, all of the same makeand model. Each bicycle was built from the same setof blueprints and therefore contains the samecomponents. In object-oriented terms, we say thatyour bicycle is an instance of the class of objectsknown as bicycles. A class is the blueprint from whichindividual objects are created.
    15. 15. What Is Inheritance?Different kinds of objects often have a certain amount in common with eachother. Mountain bikes, road bikes, and tandem bikes,for example, all share the characteristics of bicycles (current speed, currentpedal cadence, current gear). Yet each also defines additional features thatmake them different: tandem bicycles have two seats and two sets ofhandlebars; road bikes have drop handlebars; some mountain bikes have anadditional chain ring, giving them a lower gear ratio. Object-oriented programming allows classes to inherit commonly usedstate and behavior from other classes. In this example, Bicycle nowbecomes the superclass of MountainBike, RoadBike, and TandemBike. In theJava programming language, each class is allowed to have one directsuperclass, and each superclass has the potential for an unlimited number ofsubclasses:
    16. 16. Inheritance
    17. 17. InterfaceInterface makes the relationship between classes andfunctionality to those classes implement easier tounderstand and to designA interface is a collection of methods that indicate aclass has some behavior in addition to what in inheritsfrom supper class;
    18. 18. PackagesPackages are use to grouping related classes andinterfacesJava has many packages than make our work loteasierBy default you have access to “java.lang” package;For take advantages of other packages you mustimport them
    19. 19. Setup your computerDownload java SE JDK mlInstall itSet PathAll set & ready to write a program
    20. 20. Syntaxpublic class syntax{public static void main(String args[]){ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ }}
    21. 21. Pro1public class yourName{public static void main(String args[]){System.out.println(“IDM-Horana”); }}
    22. 22. VariableA variable is a place where information can be storedwhile a program is running.Kinds of variable Instance variable Local variableNaming variable Name of variable must start with letter, “_”, “$” Can’t start with number Can’t use keyword to defining a variable
    23. 23. Keywordsabstract continue for new switchassert default goto package synchronizedboolean do if private thisbreak double implements protected throwbyte else import public throwscase enum instanceof return transientcatch extends int short trychar final interface static voidclass finally long strictfp volatileconst float native super while
    24. 24. Syntax<datatype> <variableName>;EX:public cass variabeEx1{public static void main(String args[]){ int x; x=10; int y=20; int a,b,c;}}
    25. 25. Data typesData Type Default Value (for fields)byte 0short 0int 0long 0Lfloat 0.0fdouble 0.0dchar u0000String (or any object) nullboolean false
    26. 26. Examplespublic class varEx1{Public static void main(String args[]){int a,b;String c;a=10;b=15;c=“IDM-Horana”System.out.println(a);System.out.println(b);System.out.println(c);}}
    27. 27. Arrays
    28. 28. Array examplepublic class arrayEx1 { public static void main (String args[]){ //Defining an array String[] array1; array1 = new String[5]; //add data to array array1[0]="Aaliyah"; array1[1]="Sera"; array1[2]="Emma"; array1[3]="Ely"; array1[4]="Wendy"; System.out.println(array1[0]); System.out.println(array1[1]); System.out.println(array1[2]); System.out.println(array1[3]); System.out.println(array1[4]); }}
    29. 29. OperatorsOperator PrecedenceOperators Precedencepostfix expr++ expr--unary ++expr --expr +expr -expr ~ !multiplicative */%additive +-shift << >> >>>relational < > <= >= instanceofequality == !=bitwise AND &bitwise exclusive OR ^bitwise inclusive OR |logical AND &&logical OR ||ternary ?: = += -= *= /= %= &= ^= |= <<= >>=assignment >>>=
    30. 30. Arithmetic Operators+ additive operator (also used for Stringconcatenation) - subtraction operator* multiplication operator/ division operator% remainder operator
    31. 31. Arithmetic Operators Exampleclass ArithmeticEx1 {public static void main (String[] args){ int result = 1 + 2; // result is now 3System.out.println(result); result = result - 1; // result is now 2System.out.println(result);result = result * 2; // result is now 4 System.out.println(result); result = result / 2; // result is now 2 System.out.println(result);result = result + 8;System.out.println(result); // result is now 10 result = result % 7;System.out.println(result); // result is now 3}}
    32. 32. Unary Operators+ Unary plus operator; indicates positive value(numbers are positive without this, however) - Unary minus operator; negates an expression ++ Increment operator; increments a value by 1 -- Decrement operator; decrements a value by 1 ! Logical complement operator; inverts the value of a boolean
    33. 33. Unary Operators Exampleclass UnaryEx1 { public static void main(String[] args){ int result = +1; // result is now 1System.out.println(result);result--; result is now 0System.out.println(result);result++; // result is now 1System.out.println(result);result = -result; // result is now -1System.out.println(result);boolean success = false;System.out.println(success); // falseSystem.out.println(!success); // true } }
    34. 34. Comparison Operators== equal to!= not equal to> greater than>= greater than or equal to< less than<= less than or equal to
    35. 35. Comparison Operators Exampleclass ComparisonDemo {public static void main(String[] args){int value1 = 1;int value2 = 2if(value1 == value2) System.out.println("value1 == value2");if(value1 != value2) System.out.println("value1 != value2");if(value1 > value2) System.out.println("value1 > value2");if(value1 < value2) System.out.println("value1 < value2");if(value1 <= value2) System.out.println("value1 <= value2");}
    36. 36. Flow ControlIF elseSwitchWhileDo whileFor
    37. 37. IF else
    38. 38. If else Exampleimport java.util.*;class ifElseEx1{public static void main(String args[]){int x;Scanner input=new Scanner(;System.out.print("Enter number for X:-");x=input.nextInt();if(x<=10){System.out.println("X is less than 10");}else{System.out.println("X is Grater than 10");}}}
    39. 39. import java.util.*; More If elseclass ifElseEx2 { public static void main(String args[]){ //declaring variables int m1,m2,m3,tot; double avg; //inputs Scanner mark = new Scanner(; System.out.print("Enert maek 1:-"); m1=mark.nextInt(); System.out.print("Enert maek 2:-"); m2=mark.nextInt(); System.out.print("Enert maek 3:-"); m3=mark.nextInt(); //calculations tot = m1+m2+m3; avg = tot/3; System.out.println("Total mark is:-"+tot); System.out.println("Average mark is:-"+avg); //Selecton if(tot>=210){ System.out.println("You are Selected"); }else{ System.out.println("Try again"); } }}
    40. 40. Switchimport java.util.*;class switchEx1 { public static void main(String args[]){ int x; Scanner num=new Scanner(; System.out.print("Enter root number:-"); x=num.nextInt(); switch(x){ case 281:System.out.println("Thalgahawila-Horana"); break; case 282:System.out.println("Padukka-Horana"); break; case 315:System.out.println("Meepe-Horana"); break; case 120:System.out.println("Colombo-Horana"); break; case 450:System.out.println("Panadura-Horana"); break; default:System.out.println("Enter valid root no"); } }}
    41. 41. While
    42. 42. While Examplepublic class flowWhile { public static void main(String []args){ int a = 0; while(a<=10){ System.out.println(a+"> AuD"); a++; } System.out.println("Done"); }}
    43. 43. Do While
    44. 44. Do while Examplepublic class flowDoWhile { public static void main (String[] args){ int x=0; do{ System.out.println(x+"> AuD"); x++; } while(x<=10); }}
    45. 45. For
    46. 46. For Examplepublic class flowFor { public static void main(String args[]){ for(int a=0;a<=10;a++){ System.out.println(a+"> Aud"); } System.out.println("Done........"); }}
    47. 47. Thank You AuD©