-
Notifications
You must be signed in to change notification settings - Fork 1
Process, Thread, Program
In computing, a process is an instance
of a computer program that is being executed. It contains the program code and its current activity. Depending on the operating system
(OS), a process may be made up of multiple threads of execution
that execute instructions concurrently
.
A computer program is a passive collection of instructions, while a process is the actual execution of those instructions. Several processes may be associated with the same program; for example, opening up several instances of the same program often means more than one process is being executed. Each of the instances are termed as a process.
Process will be created by the Operating System by allocating memory | address space for the required resources from secondary storage
device (hard disk drive, CD-ROM, etc.) into main memory
.
Example: Reading data from java console - IO Operation, will change the state of an process to waiting state, After completing the event success | Failure process will terminate.
Process p1 = Runtime.getRuntime().exec("cmd.exe /c start java -jar "+JARFile+" "+args1+" "+args2);
InputStream is = p1.getInputStream();
int i = 0;
while( (i = is.read() ) != -1) {
System.out.print((char)i);
}
System.out.println("Process will terminate. « https://www.youtube.com/watch?v=ljxHH7i7u3Q");
A process consists of multiple threads. A thread is a smallest part of the process that can execute concurrently with other parts(threads) of the process.
A thread is a subset(part) of the process which shares same memory | address space allotted to its process by the kernel.
It is termed as a ‘lightweight process’
.
Multitasking is a method to allow multiple processes to share processors (CPUs) and other system resources.
Each CPU executes a single task at a time. However, multitasking
allows each processor to switch between tasks
that are being executed without having to wait for each task to finish.
Multithreading
Multithreading
is mainly found in multitasking operating systems. Multithreading is a widespread programming and execution model that allows multiple threads to exist within the context of one process. These threads share the process's resources, but are able to execute independently. The threaded programming model provides developers with a useful abstraction of concurrent execution. Multithreading can also be applied to one process to enable parallel execution on a multiprocessing system.
- Advantages: Responsiveness, Faster execution, Lower resource consumption, Better system utilization, Simplified sharing and communication, Parallelization.
- Drawbacks:
Synchronization
,Thread crashes a process
: an illegal operation performed by a thread crashes the entire process; therefore, one misbehaving thread can disrupt the processing of all the other threads in the application. CPU will maintain the thread's state via a single program counter, and set of registers
Threads differ from traditional multitasking operating system processes in that:
- processes are typically independent, while threads exist as subsets of a process
- processes carry considerably more state information than threads, whereas multiple threads within a process share process state as well as memory and other resources
- processes have separate address spaces, whereas threads share their address space
- processes interact only through system-provided inter-process communication mechanisms
- context switching between threads in the same process is typically faster than context switching between processes.
Programming paradigms are a way to classify programming languages
based on the features of th languages. Languages can be classified into multiple paradigms.
A programming language is a formal language that specifies a set of instructions that can be used to produce various kinds of output. Programming languages generally consist of instructions for a computer. Programming languages can be used to create programs that implement specific algorithms.
An instruction set, with its instruction set architecture (ISA), is the interface between a computer's software
and its hardware
, and thereby enables the independent development of these two computing realms; it defines the valid instructions that a machine may execute.
It is the part of the computer architecture
related to programming
, including the native data types, instructions, registers, addressing modes, memory architecture, interrupt and exception handling, and external I/O. An ISA includes a specification of the set of opcodes (machine language), and the native commands implemented by a particular processor.
Computer programming (often shortened to programming) is a process that leads from an original formulation of a computing problem to executable computer programs. Programming involves activities such as analysis, developing understanding, generating algorithms, verification of requirements of algorithms including their correctness and resources consumption, and implementation (commonly referred to as coding) of algorithms in a target programming language.
A computer program is a collection of instructions that performs a specific task when executed by a computer. A computer requires programs to function and typically executes the program's instructions in a central processing unit(CPU).
- A computer program is usually written by a computer programmer in a programming language called source code.
- In computing, source code is any collection of computer instructions, possibly with comments written by a human in plain text (i.e., human readable alphanumeric characters) Files. These files are stored on a computer's hard disk; usually these files are carefully arranged into a directory tree, known as a source tree. The source code for a particular piece of software may be contained in a single file or many files. Though the practice is uncommon, a program's source code can be written in different programming languages.
- The purpose of programming is to find a sequence of instructions that will automate performing a specific task or solving a given problem.
- Final program must satisfy some fundamental properties. like
Reliability
,Robustness
,Usability
,Portability
,Maintainability
,Efficiency
/performance
- Source code may be converted into an executable image by a compiler or executed immediately with the aid of an interpreter.
Compiler « Javac
is Java Compiler -- Compiles your Java code into Byte-code.
Interpreter
« Interpreters are used to execute source code from a programming language line-by-line.
Interpreting code is slower because the interpreter must decode each statement and then perform it.
JIT
« Java virtual machine Hotspot contains a Just In Time Compiler which selectively compiles[Runs/Interprets/translates] Java byte-code into machine code - but only code which Hotspot predicts is likely to be used many times.
Either compiled or interpreted programs might be executed in a batch process without human interaction.
executable image
« machine code consists of the central processing unit's native instructions, ready for execution.
An Instruction code is a group of bits that instruct the computer to perform a specific operation.
___________________________________________
| Operation | Address - Specifies operands,|
| Code | registers (or)_memory word |
|____________|______________________________|
Object-oriented programming
(OOP) is a programming paradigm based on the concept of "objects", which may contain data,
in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods.
In class-based programming, objects are created from classes by subroutines called constructors, and destroyed by destructors.
Languages that support object-oriented programming typically use inheritance for code reuse and extensibility in the form of either classes or prototypes. Those that use classes support two main concepts:
- Class - collection of common features of group of objects, which can be considered as plan for creating objects. i.e. classes contains the data members and member functions
- Object - physical entity an instance of a class that requires memory {state[v] - behavior[m]}. objects are entities that combine state (i.e. data), behavior (i.e. methods) and identity (unique existence among all other objects). The structure and behavior of an object are defined by a class, which is a definition, or blueprint, of all objects of a specific type. An object must be explicitly created based on a class and an object thus created is considered to be an instance of that class.
method area + heap area = premgem space
java.exe
is the command where it waits for application to complete untill it takes the next command.
javaw.exe
is the command which will not wait for the application to complete.
The difference is in the subsystem that each executable targets.
- java.exe targets the CONSOLE subsystem.
- javaw.exe targets the WINDOWS subsystem.
In a class-based object-oriented language, in general, state is carried by instances, methods are carried by classes, and inheritance is only of structure and behavior. Basic, Refactoring Techniques
Method signature: It consists of method name and parameter list (number/type/order of the parameters). methodName(parametersList y)
. An instance method in a subclass with the same signature
and return type
as an instance method in the super-class overrides the super-class's method.
Java OOP concepts
Class - Collection of a common features of a group of object [static/instance Fields, blocks and Methods]
Object - Instance of a class (instance fields)
Abstraction - Process of hiding complex info and providing required info like API, Marker Interfaces ...
Encapsulation(Security) - Class Binding up with data members(fields) and member functions.
Inheritance (Reusability by placing common code in single class)
1. Multilevel - {A -> B -> C} 2. Multiple - Diamond problem {A <- (B) -> C} [Java not supports] 3. Cyclic {A <-> B} [Java not supports]
* Is-A Relation - Class A extends B
* Hash-A Relation - Class A { B obj = new B(); } - (Composition/Aggregation)
Polymorphism (Flexibility) 1. Compile-Time Overloading 2. Runtime Overriding [Greek - "many forms"]
int[] arr = {1,2,3}; int arrLength = arr.length; // Fixed length of sequential blocks to hold same data type
String str = "Yash"; int strLength = str.length(); // Immutable Object value can't be changed.
List<?> collections = new ArrayList<String>(); int collectionGroupSize = collections.size();
Map<?, ?> mapEntry = new HashMap<String, String>();
Set<?> keySet = mapEntry.keySet(); // Set of Key's
Set<?> entrySet = mapEntry.entrySet(); // Set of Entries [Key, Value]
// Immutable Objects once created they can't be modified. final class Integer/String/Employee
Integer val = Integer.valueOf("100"); String str2 = String.valueOf(100); // Immutable classes
final class Employee { // All Wrapper classes, java.util.UUID, java.io.File ...
private final String empName; // Field as Final(values can be assigned only once) Only getter functions.
public Employee(String name) { this.empName = name; }
}
Native Java Code for Hashtable.h
, Hashtable.cpp
SQL API
.
You can check your current JDK and JRE versions on your command prompt respectively,
- JDK
javac -version [C:\Program Files\Java\jdk1.8.0_121\bin]
o/p:javac 1.8.0_121
- JRE
java -version
[C:\Program Files\Java\jdk1.8.0_121\bin]
o/P:java version "1.8.0_102"
JAVA_HOME - Must be set to JDK otherwise maven projects leads to compilation error. [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
C:\Softwares\OpenJDK\
, 7-zip
Fatal error compiling: invalid target release: JRE and JDK must be of same version
1.8.0.XXX
Disable TLS 1.0 and 1.1
security-libs/javax.net.ssl
: TLS 1.0 and 1.1 are versions of the TLS protocol that are no longer considered secure and have been superseded by more secure and modern versions (TLS 1.2 and 1.3).
Core Java
-
Java Programming Language Basics
- Object, Class, Encapsulation, Interface, Inheritance, Polymorphism (Method Overloading, Overriding)
- JVM Architecture, Memory Areas
- JVM Class Loader SubSystem
- Core Java Interview Questions & Programs
- Interview Concepts
Stack Posts
- Comparable vs Comparator
- Collections and Arrays
-
String, StringBuffer, and StringBuilder
- String reverse
- Remove single char
- File data to String
- Unicode equality check Spacing entities
- split(String regex, int limit)
- Longest String of an array
-
Object Serialization
- Interface's Serializable vs Externalizable
- Transient Keyword
-
implements Runnable
vsextends Thread
- JSON
- Files,
Logging API
- Append text to Existing file
- Counting number of words in a file
- Properties
- Properties with reference key