Continue on the technical part of the interview. Here I answered some questions about programming languages, object oriented programming, design patterns and coding culture.
What is dynamic programming language?
Maybe referred as scripting languages, but scripting languages is the narrowest term because it refers to languages to a given runtime environment. For ex PERL, Python, PHP, Shell scripts.
Why Java is considered dynamic?
Because of bytecode. A source code written in one platform, the same code can be executed in any platform. And it also loads the class files at runtime. Anything that happens at runtime is considered as Dynamic, so the java is considered as Dynamic.
What is reactive programming?
In computing, reactive programming is a declarative programming paradigm concerned with data streams and the propagation of change.
Object Oriented Programming (OOP)
What is OOP?
Object-oriented programming (OOP) is a programming paradigm based on the concept of “objects”, which are data structures that contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods.
What are OOP principles?
- abstraction – hiding internal details and showing functionality. For example: you know how to drive a car, but not necessary know mechanical details and engine. This is not a property of Object Oriented programming language alone, any structural language provides it.
- inheritance – ability to create a class by extending an existing one. It is used for code reusability so that derived class inherits the base class’s behaviour.
- encapsulation – means putting variables and methods together in a class unit and then providing permissions for class users to access them. It provides security and saves data from inadvertent; also users only get access to members which are exposed and do not bother about the internal implementation.
- polymorphism definition is that Poly means many and morphos means forms. It describes the feature of languages that allows the same word or symbol to be interpreted correctly in different situations based on the context. In java language, polymorphism is essentially considered into two versions:
- compile time polymorphism (static binding or method overloading)
- runtime polymorphism (dynamic binding or method overriding)
Why does composition favour over inheritance?
- using composition, it’s easy to change behaviour at runtime with Dependency Injection / Setters
- easier to maintain/change/add new behaviour to certain interfaces rather than building huge base classes
- maintaining more boilerplate code
What is multiple inheritance? Is it supported by Java? Diamond problem
Multiple inheritance is when one class extends multiple ones. In Java, extending just one class is allowed(otherwise extending in hierarchy). But, Java 8 came along with default methods for interfaces which now allow multiple inheritance. Multiple inheritance might cause a diamond problem. It’s when a class extends two interfaces and they both declare default method with exactly the same signature. Compiler then gets confused which implementation to choose. Java has rules how to choose implementation.
What is difference between object oriented programming language and object based programming language?
Object based programming languages follow all the features of OOPs except Inheritance. Examples of object based programming languages are Erlang, LISP, Smalltalk
Everything you need to know is in my Github repo.
Why are static variables considered as evil?
Static variables represent global state. That’s hard to reason about and hard to test: if I create a new instance of an object, I can reason about its new state within tests. If I use code which is using static variables, it could be in any state – and anything could be modifying it.
What is a good code?
- keep it stupid simple – I saw people applying “best industry practices” for very simple applications. They end up delivering late and over engineered projects. Added complexity increases support and next point…
- readability. “Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” – Martin Fowler
- architectural consistent – project gets messy if there is no consistency and every requirement brings new technologies, libs, dependencies… There must be a framework with guidelines and vision where the project is going to
- testable – small chunks and “single responsibility” let’s test your code independently
- good logging – this is a must for debugging prod, otherwise you might spend ages at reproducing a problem.
TIP: Don’t write code when you are tired or in a bad mood.
What makes a good unit test?
- readable and it must clearly describe the requirement
- doesn’t depend on order or other unit tests
- has a small scope
- test code is under /test and doesn’t cross with prod code
Interviewing part 2.2: technical Java questions II <- Previous post