Posts

Showing posts from November, 2020

Implement UNIX system calls like ps, fork, join, exec family, and wait for process management (use shell script/ Java/ C programming).

//A small example to show how to use execvp() function in C. We will have two .C files , EXEC.c and execDemo.c and we will replace the execDemo.c with EXEC.c by calling execvp() function in execDemo.c . //EXEC.c  #include<stdio.h>  #include<unistd.h>  int main()   {        int i;       printf("This  is EXEC.c, called by execvp() ");        printf("\n");       return 0;   }  Now,create an executable file of EXEC.c using command  gcc EXEC.c -o EXEC //execDemo.c #include<stdio.h> #include<stdlib.h>  #include<unistd.h>  int main()  {     //A null terminated array of character      //pointers       char *args[]={"./EXEC",NULL};       execvp(args[0],args);     /*All statements are ignored after execvp() call as this whole process(execDemo.c) is replaced by ...

Write a Java program for pass-II of a two-pass macro-processor. The output of assignment-3 (MNT, MDT and file without any macro definitions) should be input for this assignment.

import java.io.*; import java.util.HashMap; import java.util.Vector; public class macroPass2 { public static void main(String[] Args) throws IOException{ BufferedReader b1 = new BufferedReader(new FileReader("intermediate.txt")); BufferedReader b2 = new BufferedReader(new FileReader("mnt.txt")); BufferedReader b3 = new BufferedReader(new FileReader("mdt.txt")); BufferedReader b4 = new BufferedReader(new FileReader("kpdt.txt")); FileWriter f1 = new FileWriter("Pass2.txt"); HashMap<Integer,String> aptab=new HashMap<Integer,String>(); HashMap<String,Integer> aptabInverse=new HashMap<String,Integer>(); HashMap<String,Integer> mdtpHash=new HashMap<String,Integer>(); HashMap<String,Integer> kpdtpHash=new HashMap<String,Integer>(); HashMap<String,Integer> kpHash=new HashMap<String,Integer>(); HashMap<String,Integer> macroNameHash=new HashMap<String,Int...

Design suitable data structures and implement pass-I of a two-pass macro-processor using OOP features in Java.

  /* Problem Statement: Design suitable data structures and implement pass-I of a two-pass macro-processor using OOP features in Java */ import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.HashMap; public class macroPass1 { public static void main(String[] Args) throws IOException{ BufferedReader b1 = new BufferedReader(new FileReader("input.txt")); FileWriter f1 = new FileWriter("intermediate.txt"); FileWriter f2 = new FileWriter("mnt.txt"); FileWriter f3 = new FileWriter("mdt.txt"); FileWriter f4 = new FileWriter("kpdt.txt"); HashMap<String,Integer> pntab=new HashMap<String,Integer>(); String s; int paramNo=1,mdtp=1,flag=0,pp=0,kp=0,kpdtp=0; while((s=b1.readLine())!=null){ String word[]=s.split("\\s"); //separate by space if(word[0].compareToIgnoreCase("MACRO")==0){ flag=1; if(word.length<...

Abstract class and method in Java.

Abstract Class:           An abstract class is something which is incomplete and you can not create an instance of the abstract class. If you want to use it you need to make it complete or concrete by extending it. It is created using abstract keyword. This class can contain abstract and non abstract methods. Before learning about abstract class and abstract I recommend you to first learn about abstraction concept in Java. Few important things to remember about abstract class: An abstract class must be declared with an abstract keyword. It can have abstract and non-abstract methods. It cannot be instantiated. It can have constructors and static methods also. It can have final methods which will force the subclass not to change the body of the method. Example of Abstract class with abstract method: abstract   class  Animal{      abstract   void  run();   }   class  Horse  extends ...

Abstraction vs Encapsulation.

           An OOP concept which focuses on relevant information by hiding unnecessary details .           Abstraction hides complexity by giving more abstract picture, sort of 10000 feet view while Encapsulation hides internal working so that you can change it later.            Abstraction hides details at design level, while encapsulation hides details at implementation level. Its sole purpose is to hide the internal working of objects from the outside world so that you can change it later without impacting outside clients.           Abstraction is about hiding unwanted details while giving out the most essential details, while encapsulation means hiding the code and data into a single unit e.g. class or method to protect the inner working of an object from the outside world. (Abstraction can also be thought of as extracting common details or generalizing things).   ...

Difference between Class and Object.

Class is a blue print or a model, objects are actual things which are created using these blue prints/models. Generally, objects are created at runtime when you start JVM with  java  command and JVM will start executing your code, whenever JVM encounters  new  keyword it will create an object.

What are Objects in Object Oriented Programming aka OOP?

This could be best way to answer what are Objects in Java, this is more than enough for a beginner level engineer, keep note of following information Objects are instances of class, class defines blue prints and objects are things which are created based upon that blueprint.  Object is also known as instance in Java, e.g. when we say an instance of String class, we actually mean an object of String class. Object has state and behaviour. State: State is represented using instance variable and static variable. Behaviour: And behaviours are implemented using methods in Java. The things which differentiate two objects of same class are their states e.g. if we take two instances of String class 'A' & 'B' their contents are different which is nothing but their state. There are several ways to create objects in Java, .e.g., Serialization. Cloning, Reflection, etc. But the most common and easy way to create objects in Java is by using new() keyword. When we create an object...