learn java at amc square learning

14
Learn JAVA at AMC Square Learning

Upload: amc-square

Post on 16-Sep-2015

5 views

Category:

Documents


2 download

DESCRIPTION

AMC Squarelearning Bangalore is the best training institute for a career development. it had students from various parts of the country and even few were from West African countries.

TRANSCRIPT

  • Learn JAVA at AMC Square Learning

  • Java History1991: used in consumer devices1994: used in browsersprogrammers embraced because:simpler than C++.rich library.portable programs.micro edition and enterprise edition provide support for wide range of apps, from cell phones to large Internet servers.safe and secure.Java virtual machine (JVM) catches many mistakes, makes it easier to use.

  • Learning JavaVery similar to C++in most respectsAll programs are class definitions All objects are created dynamically (using new)Extensive library you must read Java documentation!

  • VariablesRules for identifiers:Can include letters, digits, _, $, cant start with digitsSpaces and other characters not permittedCannot use reserved words (e.g., public)Case sensitiveConventions you must follow for CSCI306:variable and method names should start with lower case, may include uppercase within (camel case). e.g., luckyNumberClass names should begin with uppercaseConstants should be in ALL_CAPSVariable and class names should be meaningful!!

  • Assignment and InitializationAs in C++, variables have a typeUnlike C++, variables MUST be assigned a value before being usedint example;System.out.println(example); // ERROR

    if (tot = 5) // Compiler ERROR must be boolean

  • Numeric Data Types Integer values can be represented exactly, but numeric operations may result in overflowFloating point values may not be exact, so rounding errors may occur (shouldnt use == with floating point values, use tolerance)double is therefore not appropriate for financial calculationsjava.math has BigInt and BigDec classes which are slow but have better size/precision. Must use add, subtract and multiply (no operator overloading in Java)

  • Constant valuespreceded by keyword final (vs const in C++)naming convention is all uppercasee.g., final double QUARTER_VALUE = 0.25;

    if used in a class, often make public (since cant change anyway) and often use keyword static, meaning constant belongs to the class:public static final double DIME_VALUE =0.1;Math class has some useful constants, e.g.,double circumference = Math.PI * diameter;(vs Math::PI in C++)

  • Numeric Operations

    It has a number of static functions like sqrt, pow, sin, cos, exp, log, round, max, min, etc..

    put space after every Java keyword, but not between a method name and parenthesesput space around all binary operatorsfactor out common code

    Remember that you may need to round floating point values

    double f = 4.35;int n = (int) (100 * f);System.out.println(n); // prints 434!Replace with:int n = (int) Math.Round(100 * f);

  • Loops in Javawhile loops same as C++same common errors: infinite loops, off-by-onedo loops same as C++for loops same as C++ (but with another useful syntax for collections)same common errors: forget semicolon if need empty body, or include semicolon on for statementQuality tip: for loops are best for counting loops. Use a while loop for other typesnested Loops same as in C++Quality tip: dont use != to test the end of a range, better to use
  • ClassInobject-oriented programming, aclassis an extensible program-code-template for creatingobjects, providing initial values for member variables and implementations of member functions,methods. The class name is used as the name for the class and as thetypeof objects generated by the type, and these distinct concepts are easily conflated.

  • ObjectsObjects are key to understandingobject-orientedtechnology. Look around and you'll find many examples of real-world objects.

    For example : Dog, television set, bicycle.

    They all havestateandbehavior. these have state (name, color..etc.) and behavior (the way they works/ behave).

    Identifying the state and behavior for real-world objects is a great way to begin thinking in terms of object-oriented programming.

  • Java IDEA Java IDE (Integrated Development Environment) is a software application which enables users to more easily write and debug Java programs. Many IDEs provide features likesyntax highlightingand code completion, which help the user to code more easily.NetBeans..etc. are called java IDEsAs we know which are more popular, like.

    Eclipse

  • Comparing StringsTo compare contents of strings, use equals:if (string1.equals(string2)) . . .

    May prefer to ignore case:if (string1.equalsIgnoreCase(string2)) . . .

    Can use compareTo to find out the relationship (0 if first is greater):

    if (string1.compareTo(string2)) < 0) . . .

  • Thank you

    ***********