Language Points
Language Points
Static members are shared among all instances of a class and can be accessed
without creating an object of the class.
Non-static methods are associated with instances of a class and cannot be invoked
without creating an object.
They can rely on the specific state of an object, and their behavior may vary
depending on the values of instance variables.
Exceptions handle errors that can be recovered from within the program.
Exceptions are represented by the Exception class and its subclasses. Some common
examples of exceptions in Java include:
Checked exceptions
PATH environment variable is used by the operating system to find any binary
CLASSPATH is only used by Java ClassLoaders to load class files.
to set CLASSPATH in Java you need to include all those directories where you have
put either your .class file or JAR file which is required by your Java application.
from Java 7 onwards, they have moved String pool to normal heap space, which is
much much larger than PermGen space.
Collections.sort(Object);
Object should extend comparable class.
@Override
public int compareTo(A other){
}
}
@Override
public int compare(A o1,A o2){
}
}
Collections.sort(A,new ComparatorA());
== compares references.
object class .equals compares reference by default
override it to compare content.
Python points:
def decorator_func(func):
def wrapper_func():
print("Warpper func 2nd")
return func()
print("decortaor func 1st")
return wrapper_func
def show():
print("Show worked 3rd")
decorator_show=decorator_fuc(show)
decorator_show()
Output-? decortator,wrapper,show
Alternative syntax
@decorator_func
def display():
print('dispaly worked 3rd')
display()
dict->dict.items()
key,value pair iteration
Generator
Generator are iterator which can execute only once.
uses yield keyword
Generators used in loops to generate an iterator
def sqr(n):
for i in range(1,n+1):
yield i*i
a=sqr(3)
print(next(a))
print(next(a))
Iterator
Iterate over iterable objects
iter() next() keywords used.
iter_list=iter(['A','B','C'])
print(next(iter_list))
Init keyword
__init__.py file:neccesary to indicate folder is python package
__init__() -constructor for class , uses self keyword = refernce to current
instance of class
class A:
def __init__(self,name):
self.name=name
Inheritance
A inherits B class
class A(B):
def show(**kwargs):
print(kwargs)
show(A=1,B=2,C=3)
try :
some code
except:
Handling of exception
else :
Some codeexecutes if no exception
finally:
Always executed
Abstraction:
works on design level
in java with interface
hiding implementation
Encapsulation:
hides data., with suuport of access modifiers.
s[start:end:step]
end is not included
_a = private variable
split()- x=list(map(int,input().split()))
dictionary
.copy() = deep copy
= is shallow copy
lambdsa [argumnet]:expression
single line function
Differnce between multiprocessing and multitreading:
Mutlithredaing- process spans mutiple threads,
GIL dont allow therads from runnign simultaneously.
functools
map(), reduce(),filter(functon,iterable(s))