Monday, November 30, 2015

Language: Java (My understanding)....

#Install Java on Linux Systems
sudo apt-get install openjdk-8-jre
yum install java-1.8.0-openjdk

#Installing a java file
java -jar scala-2.9.0.1-installer.jar
java -jar VarScan.jar  pileup2snp file.pileup
java -jar file.jar

#Run a java file (.jar file)
java -jar fsh.jar

IDE
Eclipse, NetBeans (folder has src, it has package, it has the java file)
####################
Java: object-oriented, portable, cross-platform, interpreted, high performance
Java is based  key concepts: polymorphism, inheritance, encapsulation, abstraction, classes, objects, instance, method, message parsing

Object can be made from a Class by declaration, instantiation and initialization
Objects have states and behavior e.g Water is (ice,gas) and has (fluidity,solidity)
Class describes the above attributes of the object. Object is an instance of class.
Behaviors are the methods.
Class can have many methods

Methods are followed by() e.g. public void size()
State are the values assigned to instance variables
Class is concrete while interface is abstract
Java variables can be local, class, instance
An object's state is created by the values assigned to the instant variables.
The public class name must be the java file name to be executed.


Class has methods
string: str compareTo (string) , compareToIgnoreCase(String), compareTo(object string),strOrig.lastIndexOf(Stringname), removeCharAt(string,position), StringBuffer(String string), toString(),  split(string),  toUpperCase() 
####################
compilation of  .java file
javac Script.java
Execution of .jar file
javac Script
java jar path_to_.jar_file
To print the statement
System.out.println("xyz"); return null; 
####################
public static void size()
Access modifiers: default, public, private, protected
Non-access modifiers e.g. static, final, abstract, synchronized
Modifiers: void, boolean, int, Object
public void clear() {
public int size()
public boolean indexExists ) {
private int binarySearch() {
####################
extends (inherits): for extending a class (interface extends)   e.g. extends Object
implements: for implementing an interface (data structure implements) e.g. implements  Comparable<Calendar>
####################
class
Object class is super-parent
java.util.Object (This class provides methods to classes below)
java.util.Arrays---------------sort (), binarySearch ()
java.util.Collections---------- reverse(), 
####################
Methods
constructor, accessor
getter (accessor) returns value
setter (mutator) resets the value
add (E), clear(), comparator(), contains (Object o), iterator(), peek(), poll(), size(), toArray()

Standard methods: sort (), binarySearch (), reverse(),  
User-defined methods: printArray(), insertElement (), Collections.reverse(ArrayList)

####################
IteratorHelper is a field
Polymorphism: Required method is used during runtime
####################
Data structure (container)
array, list,vector
Stack, queue, hash table
LinkedList
#To loop through things in  a container
for(int i=0; i<n; ++i) doSomething;
for(int& i: someDataStructure) { doSomething();}
for(int i: someDataStructure) doSomething();

Abstract data types (ADT)
Priority queue: Common operations are add (x), isEmpty (), remove(), peek()
####################
if (keys==null) return -1;
####################
Search methods
Linear search: easy but not good for long array. 
Binary search; good for long ordered list. Based on binary search tree (BST) algorith, that ignores one half.
Both search methods can be iterative or recursive
####################
Common errors
ArrayStoreException: When wrong type of object is stored into an array of objects
IllegalArgumentException:
NullPointerException: When null is used in place of required object
####################
Compilation, execution
To keep compiled java classes
mkdir dir
#Compile
java -jar ~/path
javac -classpath .jar_file -d dir .java_file
#Execute
jar -cvf units.jar -C dir/ .
#Creating directory in target
mkdir dir
put file
ls dir
job -status < job_ID
job -history < dir_name
job -kill < job_ID
####################
echo %CLASSPATH

java -version
//When compilation error occurs, use -Xlint
javac -Xlint Example.java 
Errors..........
NullPointerException : If class objects are null

No comments:

Post a Comment