The basics video
The main() method
- Can we have two main methods in a class - Yes (Only one will have the standard signature)
- Can the standard main method throw exception - Yes
ARRAY
Convert from Array to List
Arrays.toList( array )
this keyword
- this may be used only in the body of an instance method, instance initializer or constructor, or in the initializer of an instance variable of a class
Qualified this
- ClassName.this is the nth lexically enclosing instance of this
- Can only be called from an inner class at any level down.
package
Can a duplicate java.util package be created - Yes
Can a duplicate java.util.ArrayList class be created - Yes, But it cant be accessed as java.util.ArrayList is already loaded by the Classloader ??
String
Are string literals garbage collected - Yes
Storage of String Literals
http://java.dzone.com/articles/string-memory-internals
Java SE Components
java.io - InputStream, OutputStream, Reader, Writer, Console, File, Serializable, Externalizable
java.lang - Comparable, Iterable, Runnable, Float, Integer, String, Thread
java.lang.annotation - Annotation, ElementType, RetentionPolicy
java.lang.ref - Reference, SoftReference, WeakReference, PhantomReference, ReferenceQueue
java.lanf.reflect - Constructor, Field, Method, Modifier, Array, Proxy-InvocationHandler
java.lang.math - BigDecimal, BigInteger, MathContext, RoundingMode
java.sql - Driver, Connection, ResultSet, Savepoint, Statement, Date, Timestamp
java.util - Collection
java.util.concurrent
java.util.atomic
java.util.locks
java.util.logging
java.util.regex
https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html
Runtime.availableProcessors() - Returns number of processors.
equals:
The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).
hashCode:
As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)
Java IO
IN / OUT is with respect to data from client
FileInputStream - Data comes IN to client from File.
FileOutputStream - Data goes OUT from client to File
java.io.File - This class presents an abstract, system-independent view of hierarchical pathnames
- InputStream - Abstract Class
- ByteArrayInputStream - Provides data from byte[] passed to the Constructor
- FileInputStream - Provides data from File passed to the Constructor
- ObjectInputStream - Deserializes primitive data & Objects previously written using ObjectOutputStream
- PipedInputStream - Should be connected to PipedOutputStream. PIS provides whatver data is written by POS. Writing & Reading should be done by two different Threads.
- SequenceInputStream - Logical concatenation of other InputStreams. Provides ALL data from first stream before starting with data of nextStream.
- FilterInputStream - Container for any other InputStream. Adds functionality to other InputStreams - adds ability to buffer and supports mark & reset operations.
- DataInputStream - lets an application read primitive Java data types in machine independent way..
- PushbackInputStream - Adds functionality to another stream. The ability to pushback/ unread one byte.
----
OutputStream | ByteArrayOutputStream | FileOutputStream | FilterOutputStream | BufferedOutputStream | DataOutputStream | ObjectOutputStream | PipedOutputStraem
PrintStream - Adds functionality to another Output Stream.
Access Modifiers
final = Can only be initialised where the variable is declared. This is enforced only by Intellij ??? conflict as per below.
In some cases, such as deserialization, the system will need to change the
final
fields of an object after construction. final
fields can be changed via reflection and other implementation dependent means. The only pattern in which this has reasonable semantics is one in which an object is constructed and then the final
fields of the object are updated. The object should not be made visible to other threads, nor should the final
fields be read, until all updates to the final
fields of the object are complete. Freezes of a final
field occur both at the end of the constructor in which the final
field is set, and immediately after each modification of a final
field via reflection or other special mechanism.
Even then, there are a number of complications. If a
final
field is initialized to a compile-time constant in the field declaration, changes to the final
field may not be observed, since uses of that final
field are replaced at compile time with the compile-time constant.
Another problem is that the specification allows aggressive optimization of
Final field can get Leaked if its passed as callback to a calling Class/Method
final
fields. Within a thread, it is permissible to reorder reads of a final
field with those modifications of a final field that do not take place in the constructor.Final field can get Leaked if its passed as callback to a calling Class/Method
Java System Properties
The environment is a system-dependent mapping from names to values which is passed from parent to child processes.
If the system does not support environment variables, an empty map is returned.
Gets the system property indicated by the specified key.
First, if there is a security manager, its
checkPropertyAccess
method is called with the key as its argument. This may result in a SecurityException.
If there is no current set of system properties, a set of system properties is first created and initialized in the same manner as for the
getProperties
method.The default name-separator character is defined by the system property file.separator, and is made available in the public static fields separator and separatorChar of the File class
ProcessBuilder.environment() -
ProcessBuilder is used to launch new OS processes from Java.
java keywords
Constant Propagation
Multiple Return from a Method
To establish multiple return from a method we need to pass a ( or more ) parameter (mostly array) whose contents can be changed by the method that is called.
Resource Leak in Java
1. Memory Leak - (Permgen Leak) http://stackoverflow.com/questions/17968803/threadlocal-memory-leak
2. Database Connection Leak - Connection created but not closed somehow.
3. Connection Pool Leak - A connection is obtained from the Connection pool but is not returned. It is assumed to be in use but actually is not.
3. Connection Pool Leak - A connection is obtained from the Connection pool but is not returned. It is assumed to be in use but actually is not.
3. File Handle Leak (InputStream / OutputStream)
4. Sockets Leak / Networking
No comments:
Post a Comment