Friday, March 11, 2016

Java Facts

  • James Gosling is the founder of Java (in 1995) it was formally announced in 1997.
  • Java is a case sensitive language which means that the uppercase and lowercase letters are distinct.
  • Blue J is an environment of Java (IDE) developed by David Barns and Michael Kollins.
  • There are 5 types of Tokens in Java.
  • The conversion process of Java is unique, (two step).
  • Java follows UNICODE character set.
  • char type is a Unicode character stored as an unsigned number in two bytes (range 0..65,535 or ‘\u0000′..’\uFFFF’).
  • After the two // characters, Java ignores everything to the end of the line.
  • After the /* characters, Java will ignore everything until it finds a */.
  • Class and interface names start with an uppercase letter, and continue in lowercase.
  • Lowercase is used for variable and method names. If a name has multiple words, use Camel Case
  • The names of constants should be in all uppercase.
  • The wildcard * only makes the classes in this package visible, not any of the sub-packages.
  • All classes in the java.lang package are visible without an import.
  • Java programs can run on many different machines (Intel, Sparc, PowerPC, …) and many  different operating systems (Windows, Unix, Macintosh, …).
  • Java lacks a few features that some C++ programmers find useful, for example, macros and operator overloading.
  • The programs that you normally run are called applications.
  • A typical MS Windows application has an extension of .exe, whereas in Java it will usually end with a .class or .jar extension.
  • b && c is a Logical “and”. true if both operands are true, otherwise false.
  • b || c is a Logical “or”. true if either operand is true, otherwise false.
  • b? x : y is a Conditional where if b is true, the value is x, else y. x and y must be the same type.
  • +=, -=, *= … Are all binary operators called shortcut assignment.
  • s.compareTo(t)  compares String s to String t and returns <0 (negative) if s appears before t in a dictionary, 0 if they are identical in all respect and >0 (positive) if appears after t in a dictionary.
  • s.lastIndexOf(c) returns the index of last occurrence of character c in String s.
  • s.trim( ) returns a new String with white-space deleted from beginning and end of a string.
  • s.startsWith(t) returns true if String s begins with String t.
  • s.substring(i, j) returns another from index i to index j – 1.
  • The + operator joins two strings together. If either operand is String, the other is converted to String and concatenated with it.
  • s.lastIndexOf(t, i) returns the index of last occurrence of character t on or before index i in String s.
  • do-while loop is an exit controlled loop hence executes at least one time before testing and so executes once even if the condition is false.
  • The while statement tests the expression before entering the loop. If the expression evaluates to true, it executes the body of the while. If it is false, terminates the loop and continues with the rest of the program.
  • All loop statements can be labeled, so that break and continue can be used from any nesting depth.
  • To decide which method to call, Java looks at the method signature (method name, type and order of the parameters).
  • If a method is declared void then there is no need for a return statement, but if we still use a return; will have same effect.
  • Math.min(x, y) Returns minimum of x and y and the return type depends upon the arguments selected, same with Math.max( )
  • Math.floor(d) Returns the closest integer-valued double which is equal to or less than d.
  • Math.ceil(d) Returns the closest integer-valued double which is equal to or greater than d.
  • Math.round(f) Returns the int which is closest in value to the float f.
  • Math.rint(d) Returns the closest integer-valued double which is equal to or greater than d.
  • A StringTokenizer constructor takes a string to break into tokens and returns a StringTokenizer object for that string, the breaking of string depends on de-limiter which by default is space.
  • BufferedReader & BufferedWriter are used for reading and writing text files.
  • There are some characters that can’t be written directly in a string, such characters are called non-printable characters. The backslash (‘\’) character if preceded creates escape sequence and then becomes printable.
  • Escape combinations:
    • \n : newline,
    • \\  : backslash,
    • \’ : single quote,
    • \” : double quote,
    • \r : carriage return,
    • \t : tab,
    • \b : backspace,
    • \f  : form feed.
  • Putting two strings together to make a third string is called concatenation.
  • In Java the concatenation operator is ‘+’, or a String function concat( )
  • An instance variable is a variable that is defined in a class as non static, but outside the method.
  • When an object is created, a constructor for that class is called. If no constructor is defined, a default constructor is called.
  • If a subclass redefines a method defined in a superclass, the method in the superclass is overridden.
  • A class which doesn’t define all it’s methods is called an abstract class.
  • An interface is a list of methods that must be implemented. A class that implements an interface must define all those methods.
  • There is no return type given in a constructor header/prototype. The value is this object itself so there is no need for a return value.
  • The use of super to call a constructor in a parent class. Calling the constructor for the superclass must be the first statement in the body of a constructor.
  • An interface is similar to a class without instance and static variables (static final constants are allowed), and without method bodies.
  • br.readLine() Returns next input line without new line char(s) or null if no more input this line may throw IOException.
  • An array can store many similar values in memory. Each value can be accessed by specifying a subscript or index.
  • If the array subscript is outside this range, Java throws ArrayIndexOutOfBoundsException.
  • When you declare an array, you can also allocate a pre initialized array object in the same statement.
  • The order in which expressions are evaluated is basically left to right, with the exception of the assignment operators.
  • If you need to do the same set of tasks repeatedly then we create a method to do it and call the method each time you have to do that task.
  • Because local variables and statements of a method can not been seen from outside the method, they (and their complexity) are hidden from other parts of the program, which prevents accidental errors or confusion.
  • Unary operators have higher precedence than binary operators.

No comments:

Post a Comment