SCJP: More Rules #Java Short Notes #SCJP

  • java -classpath gFolder/Game.jar civilization.java: In such command, -classpath will override (replace) CLASSPATH environment variable.
  • java -classpath gFolder/Game.jar civilization.java: if both gFolder and current directory contain Game.jar then the jar file under gFolder will be used.
  • If you want java compiler to recognize your jar file, either you have to mention the location of the jar file in javac command using -classpath switch or you have to add the jar file in the CLASSPATH environment variable. Mentionable – you need to add the file, adding upto the directory will not work.
  • Garbage collection: can Java program run out of memory? yes.
  • Can objects be garbage collected even if it has a valid reference? yes. when no live thread has access to the object.
  • Can Objects created within inner classes be eligible for garbage collection.? yes.
  • Do garbage collector deletes objects from the stack? No. As objects reside in heaps not in the stack.
  • If an object’s finalize method runs to completion will it always be garbage collected? No. The finalize method may create some other references.
  • Arrays.equals(Object[] a1, Object[] a2) : Returns true if the two specified arrays of Objects are equal to one another
  • The results of Binary search on an unsorted array are undefined
  • Alpha go(int i) is a valid method declaration with a generic return type. class Alpha{}

From: http://sitestree.com/?p=4891
Categories:Java Short Notes, SCJP
Tags:
Post Data:2010-06-26 02:46:16

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

SCJP: Short Notes #Java Short Notes #SCJP

From: http://sitestree.com/?p=4888
Categories:Java Short Notes, SCJP
Tags:
Post Data:2011-10-20 04:13:02

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

SCJP: Rules #Java Short Notes #SCJP

  • A class’s superclasses don’t have to implement Serializable in order to be serialized
  • if a superclass doesn’t implement Serializable then it’s constructor will run during deserialization
  • A transient variable’s state is lost during serialization, but a volatile variable’s state is not lost
  • Java:Volatile variable
  • Transient Variable
  • NumberFormat, Calendar, DateFormat are abstract classes. Use the getInstance method to get NumberFormat instances.
  • The + quantifier in a regular expression indicates 1 or more occurrences, * indicates 0 or more, [] just one character in the group, () indicates a whole group match.
  • The default separator in Scanner class is a blank NOT a comma
  • Multiple threads can be created using the same Runnable object, but a given thread can be started only once.
  • Thread.yield(): Causes the currently executing thread object to temporarily pause and allow other threads to execute.
  • Thread.join(): Waits for this thread to die.
  • Wait(), Notify(), NotifyAll() methods
  • Low coupling: classes know the least possible about each other, is preferable over tight coupling.
  • High cohesion: Each class has well focused responsibilities. Is preferable over low cohesion.
  • Polymorphism does NOT apply to static methods.
  • Instance variable cannot be referenced from static method

From: http://sitestree.com/?p=4883
Categories:Java Short Notes, SCJP
Tags:
Post Data:2011-09-04 06:32:26

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

SCJP: Java Concurrency #Java Short Notes #SCJP

From: http://sitestree.com/?p=4879
Categories:Java Short Notes, SCJP
Tags:
Post Data:2009-04-19 03:15:05

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

SCJP: Basic Java I/O #Java Short Notes #SCJP

  • ByteStream is the basic I/O stream. Handles data as a stream of bytes. Does operation with byte unit and uses 8 bit. FileInputStream, FileOutputStream – can be used to copy files as byte by byte.
  • Character Streams: FileReader and FileWriter are character streams. They treat file data as 16 bit unicode charater streams.
  • InputStreamReader, OutputStreamWriter are also character streams. May be used in socket data reading.
  • Line-Oriented I/O: BufferedReader and PrintWriter
  • Buffered Streams: BufferedInputStream and BufferedOutputStream create buffered byte streams, while BufferedReader and BufferedWriter create buffered character streams
  • You can set autoflush() of buffered streams or call manually flush() method.
  • The scanner API breaks input into individual tokens. The formatting API assembles data into nicely formatted, human-readable form.
  • Scanner:
    Scanner scanner = new Scanner(new BufferedReader(new FileReader("test.txt")));            while (s.hasNext()) {                System.out.println(s.next());            }
  • To create formatted output streams, instantiate PrintWriter not PrintStream
  • Check: System.out.format(“The square root of %d is %f.%n”, i, r);
  • System.out and System.err are PrintStream objects. PrintStream is really a byte stream but uses some mechanism to emulate character stream.
  • InputStreamReader cin = new InputStreamReader(System.in); System.in is a byte stream. InputStreamReader is used to emulate a character stream.
  • System.console provides character streams to handle console read/write operations. Provides readPassword method to read password from the console
  • Data Streams: Support I/O operations of primitive data types. DataInputStream and DataOutputStream.
  • Check:
    out = new DataOutputStream(new            BufferedOutputStream(new FileOutputStream(dataFile)));out.writeDouble(prices);out.writeInt(units);out.writeUTF(descs);
  • DataStreams detects an end-of-file condition by catching EOFException
  • Correct type to represent currency values: java.math.BigDecimal – an object type
  • Object Streams: ObjectInputStream and ObjectOutputStream. Use writeObject and readObject to write and read objects respectively.
  • A stream can contain only one copy of an object but many references to it when required.
  • File Objects: File I/O
  • Random access file:
    new RandomAccessFile("test.txt", "r");new RandomAccessFile("test.txt", "rw");RandomAccessFile methods:    * int skipBytes(int)     * void seek(long)      * long getFilePointer() 
  • The new java.nio.* package provides supports to handle file i/o for high performance applications.

From: http://sitestree.com/?p=4878
Categories:Java Short Notes, SCJP
Tags:
Post Data:2012-10-24 02:25:07

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

Java : SCJP: Important Resources #Java Short Notes #SCJP

From: http://sitestree.com/?p=4876
Categories:Java Short Notes, SCJP
Tags:
Post Data:2008-03-19 18:31:53

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

SCJP: Random Stuffs #Java Short Notes #SCJP

  • An enum may NOT be declared in a method
  • An enum can be imported
  • If the JVM has a choice, it will select a method without varargs before selecting a method with varargs
  • When enums are equal, both .equals and == always return true
  • The headMap() method returns the portion of the map whose keys are less than the key sent to it
  • The asList() method of Arrays creates a fixed-size list that is backed by the array, so no additions are possible.
  • A static initialization block is a normal block of code enclosed in braces, { }, and preceded by the static keyword. Used to initialize class variables
  • All enums implicitly extend java.lang.Enum.
  • A class can extend only one other class, an interface can extend any number of interfaces
  • An interface might also contain constant definitions.
  • An abstract class that implements an interface may not implement all interface methods

From: http://sitestree.com/?p=4872
Categories:Java Short Notes, SCJP
Tags:
Post Data:2012-12-07 07:48:57

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

SCJP: Interfaces #Java Short Notes #SCJP

Interface

  • An interface is a reference type, similar to a class
  • Interfaces can contain only constants, method signatures, and nested types
  • No method is implemented
  • Interfaces cannot be instantiated
  • They can only be implemented by classes or extended by other interfaces
  • Interfaces are not part of the class hierarchy
  • A class can implement multiple interfaces

From: http://sitestree.com/?p=4867
Categories:Java Short Notes, SCJP
Tags:
Post Data:2010-01-20 15:33:28

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

SCJP: Class Declarations #Java Short Notes #SCJP

class declarations

  • Start with modifiers such as public, private followed by class keyword
  • The class name, with the initial letter capitalized
  • The name of the class’s parent (superclass), preceded by the keyword extends (if any). A class can only extend (subclass) one parent.
  • list of interfaces implemented by the class, preceded by the keyword implements (if any). A class can implement more than one interface
  • The class body, surrounded by braces, {}.
  • Class member variable declarations
    • Requires three components, in order:
    • Zero or more modifiers, such as public or private
    • The field’s type
    • The field’s name.

Abstract Classes

  • A class declared with abstract keyword is an abstract class. It may or may not include abstract methods
  • Abstract classes cannot be instantiated
  • Abstract classes can be subclassed
  • Class containing abstract methods, must be declared to be abstract
  • Abstract methods are methods declared without implementation (braces)
  • The subclass of an abstract class must provide implementations of all the abstract methods otherwise the subclass itself needs to be declared as abstract.
  • An abstract class may have static and final fields and methods. Interfaces can not
  • If an abstract class contains only abstract method declarations with no implementations, it should better be declared as an interface
  • It’s a good design to declare a common abstract class with common methods with implementations for several very related classes (will extend the abstract class)
  • An abstract class can implement an interface but are not bound to implement all interface methods

Nested Classes

  • Classes declared under another class are called nested classes
  • Two types: Static Nested: declared with static keyword, Inner Nested: declared with no static keyword
  • inner classes have access to other members of the outer class including private members
  • Static nested classes do not have access to other members of the outer class
  • Static nested classes are accessed using the outer class name such as: OuterClass.StaticNestedClass
  • To use inner classes, the outer class must be instantiated first. Then, inner object can be created as follows: OuterClass.InnerClass innerObject = outerObject.new InnerClass();
  • Local inner classes: Declared within the body of a method
  • Anonymous inner classes: Declared within the body of a method without naming it
  • Inner classes may have similar access modifiers like other outer class members
  • Why use nested classes:
    • For logically grouping classes that are only used in one place
    • It increases encapsulation.
    • May lead to more readable and maintainable code

From: http://sitestree.com/?p=4866
Categories:Java Short Notes, SCJP
Tags:
Post Data:2012-09-13 21:25:27

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

SCJP: Flow controls and exception #Java Short Notes #SCJP

Flow Control and ExceptionsFlow control statements

  • Conditional: if, if-else and switch-case
  • Looping: for, while, do-while
  • Exception handling: try-catch-finally, throw
  • Ad hoc flow control: break, continue with or without labels

switch statement

switch(expression){
case ConstantExpression: statement(s);
case ConstantExpression: statement(s);
.
.
.
default: statement(s);
}

  • expression: must be char, byte, short, or int, or a compile-time error occurs
  • long primitive can be used if type casted to int
  • Object reference cannot be used as expression
  • Every case expression must be unique
  • break statement may be used at the end of a case statement, to discontinue execution.
  • There can be at most only one default statement.
  • The order of case statements and default can be anything.

break and continue

  • A break statement transfers the control out of an enclosing statement. break used within a loop breaks the execution of the current loop. In case of nested loops, the break statement passes the control to the immediate outer loop.
  • A continue statement breaks the current iteration and moves to next iteration.
  • break and continue with labels.
    • Labels specify the target (statement) for continue and break
    • continue with label does not jump to the labeled statement but instead jumps to the end of the labeled loop.
    • Same label identifiers can be reused multiple times as long as they are not nested.
    • Label names do not conflict with the same named identifier(variable, method or class name).

Checked and Unchecked Exceptions

Checked Exceptions

  • Checked Exceptions are checked by the compiler to see if these exceptions are properly caught or specified. If not, the code will fail to compile
  • Checked exception forces client program to deal with the scenario in which an exception may be thrown
  • Checked exceptions must be either declared or caught at compile time

Unchecked Exceptions

  • Unchecked exceptions are RuntimeException and all of its subclasses.
  • Class java.lang.Error and its subclasses also are unchecked.
  • Unchecked Exceptions are not checked by the compiler.
  • Runtime exceptions do not need to be caught or declared.

From: http://sitestree.com/?p=4864
Categories:Java Short Notes, SCJP
Tags:
Post Data:2008-08-25 00:56:33

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada