Thursday, October 1, 2020

Home






Mastering Java Interview Questions: Your Comprehensive Guide


       If you're preparing for a Java interview or just looking to enhance your foundational knowledge of Java, you're in the right place. We've compiled a list of frequently asked Java interview questions that not only aid you in interviews but also strengthen your understanding of essential Java topics.

Java Basics                             




Hello readers

           We welcome you to dnb-java.blogspot.com, this blog is not a tutorial but the guide for you to crack interviews for java. I will be keep on updating with some more technologies, which are helpful in java to improve your code & functionality.






 

JVM (Java Virtual Machine), JRE (Java Runtime Environment), JDK (Java Development Kit)

            These are basic things in java. which do don't bother about & ignore. But we should have clarity about these topics. These are basic & most important questions, which will be asked in every interview, irrespective of  whether You are freshers of experienced.
     



Some of the basic topics this blog contains:

  •        difference between 32-bit and 64-bit JVM
  •       Types of memory areas are allocated by JVM
  •        classloader
  •        JIT compiler
  •        singleton class
  •        Encapsulation
  •       Polymorphism
  •       Abstraction

Java Commands:
             Knowing how to compile and run Java code is a fundamental skill. Follow these steps for smooth execution:
  1. Save your Java code with the filename as the class name and the extension .java.

  2. Compile the code using the javac command:

                                   javac Classname.java                                                                                                         

           Once you run above javac command. It creates .class file, with the same name of program.
           once code is compiled, it is converted into byte-codes. & now program is ready to run in any machine irrespective of operating system. It only requires JVM. This converted code runs over JVM.

           To Run java code use command java (without any extension).
                                   java Classname                                                                                                         


Related Links :
            Threads                 https://dnb-java.blogspot.com/p/thread.html
           Linux Commands   https://dnb-java.blogspot.com/p/linuxcommands.html
          Windows Commands  https://dnb-java.blogspot.com/p/rwindowscommands.html


Additional Resources :
                 https://dnb-ai1.blogspot.com/


           We welcome to you too for posting comments & share more documents related to topic. Which can help more people to get updated & always get ready to launch for interview.




    Tuesday, December 3, 2019

    Mount logical Partition in Linux VM

     

    Expand Linux VM Logical Volume Partition or Mount Logical Volume


        In a virtualized environment when a LINUX OS created. There are min three partitions created 
    •     ROOT 
    •     HOME 
    •     SWAP

        But here if you think that just expanding partition will solve your purpose then you are wrong. Because expanded partition gets appended after swap memory. So, we need to mount the expanded partition and merge it with the partition that requires expansion.

    So let go step by step.
    • Power off the virtual machine.
    • Edit the virtual machine settings and extend the virtual disk size.
    • Power on the virtual machine.
    • Identify the device name, which is by default /dev/sda, and confirm the new size by running the command
            fdisk -l


    • Now execute this below command to initialize the expanded space and mount it.
            fdisk /dev/sda
    • Press p to print the partition table to identify the number of partitions.
    • Press n to create a new primary partition.
    • Press p for primary.
    • Press 3 for the partition number, depending on the output of the partition table print.
    • Press Enter two times.
    • Press 3 to select the newly creation partition.
    • Type 8e to change the Hex Code of the partition for Linux LVM.
    • Press w to write the changes to the partition table. 

    • Reboot the virtual machine.
    • Now we need to create physical & logical volumes execute below command to create physical volume.

             pvcreate /dev/sda3

    • Execute below command to get the name of current Volume Group

            vgdisplay

             Note Down the VG Name from output of command for further commands.

    • Execute below command to extend the Volume Group with /dev/sda3. replace VG Name with the VG name displayed by above command.

            vgextend <VG Name> /dev/sda3


    • Execute below command to get Logical Volume path.

            lvdisplay

            This command will give you LV Path & will be used in next command.

            

    • Execute below command to extend the Logical Volume with /dev/sda3. replace <LV Path> with the output value of above command.

            lvextend <LV Path> /dev/sda3 


    • Execute below command to update the Logical Volume

            xfs_growfs /dev/VolGroup/lv_root

    •  Check for the new disk space.

            df -h

         Here you are done with expanding & mounting partition.


    Thursday, November 7, 2019

    Kubernetes Commands

     Kubernetes Commands


    Minikube :

         Steps for Running minikube in console:

                Starting Minikube in console by assigning memory 6G with virtualbox-

                minikube start --vm-driver=virtualbox --memory 6000 

                 

                 Setting up docker environment-

                minikube docker-env


           To load minikube dashboard in browser-

                minikube dashboard




    Kubernetes: 

            When You want to reset your minikube with specific namespace,

        kubectl -n <namespace> delete deployment,pod,svc/secret,rs,jobs,statefulset,daemonset --all


        Get all Namespace & Deleting specific namespace,

            kubectl get namespaces

            kubectl delete namespaces <namespace>


    Some Other useful kubernetes commands:

            kubectl run <servicename> --image=<imagename>

            kubectl get pods

            kubectl get services

            kubectl get ep

            kubectl delete svc <service name>

            kubectl apply -f <yaml file name>



    Useful Docker commands:

        Create Dockerfile in project's base directory & then run command in command prompt to build the Docker image.

                    docker build -t <output imagename> <outputpath>





    Monday, September 30, 2019

    String to Math expression



    How to use String into Mathematical Expression or Generating dynamic Math formula from String.



    Java 1.6 onward you can use JavaScript engine to convert String into Mathematical expression.

    import javax.script.ScriptEngineManager;
    import javax.script.ScriptEngine;
    import javax.script.ScriptException;
    
    public class MathExpression{
      calcualte() {
        ScriptEngineManager sem= new ScriptEngineManager();
        ScriptEngine scEngine= sem.getEngineByName("JavaScript");
        String formula = "30+50";
        System.out.println(scEngine.eval(formula));
        } 
    }





    Above code works fine for java. But JavaScript   is not available in Android. so we have to use rhino  in android.


    add below entry to gradle dependency.
    dependencies {
        implementation 'io.apisense:rhino-android:1.0' 
     }


    import javax.script.ScriptEngineManager;
    import javax.script.ScriptEngine;
    import javax.script.ScriptException;
    
    public class MathExpression{
      calcualte() {
        ScriptEngineManager sem= new ScriptEngineManager();
        ScriptEngine scEngine= sem.getEngineByName("rhino");
        String formula = "30+20";
        System.out.println(scEngine.eval(formula));
        } 
    }





    Saturday, August 3, 2019

    combineImages





    Combine two images and draw new Image Java Code.



    import java.io.File;
    import java.awt.Color;
    import java.awt.Graphics2D;
    import javax.imageio.ImageIO;
    import java.awt.image.BufferedImage;


    public class Main {
       
    public static void main(String args[]) throws Exception {
            BufferedImage img1 = ImageIO.read(
    new File("1.jpg"));
            BufferedImage img2 = ImageIO.read(
    new File("2.jpg"));
            BufferedImage joinedImg = combineImage(img1, img2);
            ImageIO.write(joinedImg,
    "png", new File("combined.png"));
        }







    public static BufferedImage combineImage(BufferedImage img1, BufferedImage img2) {
           
    int offset = 2;
           
    int width = Math.min(img1.getWidth(), img2.getWidth()) + offset;
           
    int height = img1.getHeight()+ img2.getHeight() +offset;
            BufferedImage outImage =
    new BufferedImage(width, height,
                    BufferedImage.TYPE_INT_ARGB);
            Graphics2D g2D = newImage.createGraphics();
            Color imgColor = g2D.getColor();
            g2D.setPaint(Color.BLACK);
            g2D.fillRect(
    0, 0, width, height);
            g2D.setColor(imgColor);
            g2D.drawImage(img1,
    null, 0, 0);
            g2D.drawImage(img2,
    null,0,img1.getHeight()+offset);
            g2D.dispose();
           
    return outImage;
        }
    }





    **************************************************


    Combine two images and draw new Image Android Code.


    public void combineImage(Context context) {
       
    int offset = 2;
        File sdcard = Environment.getExternalStorageDirectory();
       
        File dir =
    new File(sdcard.getAbsolutePath() + "/path/");
        Bitmap topImage = BitmapFactory.decodeFile(dir +
    "/img1.JPG");
        Bitmap bottomImage = BitmapFactory.decodeFile(dir +
    "/img2.JPG");
       
       
    int width = Math.min(topImage.getWidth(), bottomImage.getWidth()) + offset;
       
    int height = topImage.getHeight() + bottomImage.getHeight() + offset;
       
        Bitmap mutableBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.
    ARGB_8888);

        Canvas comboImage =
    new Canvas(mutableBitmap);

        Paint paint =
    new Paint();

        comboImage.drawBitmap(topImage,
    0, 0, paint);
        comboImage.drawBitmap(bottomImage,
    0, topImage.getHeight(), paint);
       
        OutputStream os =
    null;
       
    try {
            os =
    new FileOutputStream(new File(dir, "output.JPG"));
            mutableBitmap.compress(Bitmap.CompressFormat.
    JPEG, 50, os);
            os.flush();
            os.close();
        }
    catch (Exception e) {
            e.printStackTrace();
        }
    }

    Home

    Mastering Java Interview Questions: Your Comprehensive Guide         If you're preparing for a Java interview or just lookin...