Skip to main content

Posts

Showing posts with the label Java

Digital twins in manufacturing

Digital Twins in Manufacturing: Revolutionizing the Future of Production In today’s era of Industry 4.0, digital twins are reshaping the way manufacturing systems are designed, monitored, and optimized. A digital twin is a virtual replica of a physical system, process, or product, updated in real-time with data from sensors and IoT devices. By mirroring the real world in a digital environment, manufacturers gain valuable insights to improve efficiency, reduce costs, and drive innovation. What is a Digital Twin? A digital twin is more than just a 3D model or simulation. It integrates real-time data, artificial intelligence (AI), machine learning, and advanced analytics to simulate behavior, predict outcomes, and optimize operations. In manufacturing, digital twins can represent machines, production lines, supply chains, or even entire factories. Applications in Manufacturing Product Design and Development Engineers can test virtual prototypes before building physical ones, reducing des...

Java important question - 13

What are the ways to initialize a final variable ?           We must initialize a final variable, otherwise compiler will throw compile time error. A final variable can only be initialize once, either via an initializer or an assignment statement. There are three ways to initialize a final variable, 1) You can initialize a final variable when it is declared. This approach is most common. A final variable is called blank final variable, if it is not initialized while declaration. Below are the two ways to initialize a blank final variable. 2) A blank final variable can be initialized inside constructor. If you have more than one constructor in your class then it must be initialized in all of them, otherwise compile time error will be thrown. 3) A blank final static variable can be initialized inside static block. What is the difference between transient and volatile variable in Java ? Transient:           In Java, it is used to specify th...

Java important question - 12

What is the use of final keyword in java ?           final keyword is used in different contexts. First of all, final is a non-access modifier applicable only to a variable, method or a class. Following are different contexts where final is used, a) Final variable -  To create constant variable. When a variable is declared with final keyword, it's value can't be modified, essentially a constant. This also means that you must initialize a final variable. If the final variable is reference this means that the variable cannot be rebound to reference another object, but the internal state of the object pointed by that reference variable can be changed. i.e. you can add or remove elements from final array or final collection. It is good practice to represent final variables in all uppercase, using underscore to separate words. Java interface variables are by default final and static. b) Final methods - Prevent method overridding. We can use the final keyword wit...

Java important question - 11

What is the difference between creating String as new() and literal ?           When we create String with new() operator, it's created in heap and not added into string pool. When String created using literal are created in String pool itself which exist in permgem area of heap.  String s = new String("Test");           This does not put the object in string pool, we need to call String.intern() method which is used to put them into String pool explicitly. When you create String object as String literal. Eg : String s = "Test" java automatically put that into String pool. Define a StringJoiner and write sample code ?           StringJoiner is a utility method to construct a string with the desired delimiter. StringJoiner strJoiner = new StringJoiner                                              ...

Java important question - 10

Can we use String with switch case ?           One of the java7 features was improvement of switch case to allow strings. So if you are using java 7 or higher version, you can use String in switch case statement. private   static void printColorUsingSwitch                                                (String color) { switch(color) { case "blue":      System.out.println("Blue");      break; case "red":      System.out.println("Red");      break; default :      System.out.println("Invalid color                                                code"); } Q) Difference between String, StringBuilder and StringBuffer in java String :       ...

Java important Question - 9

Q) Can we declare a class as static ?           We can't declare a top-level class as static however an inner class can be declared as static. If inner class is declared as static,it's called  static nested class. The static nested class is same as any other top-level class and is nested for only packaging convenience. Also when we declare a class as 'static' then it can be referenced without the use of an object. Q) What is static import ?           static import is a feature introduced in java version 5.0 that allows members defined in a class as public static to be used in Java code without specifying the class in which the field is defined. If we have to use any static variable or method from other class, usually we import the class and then use the method/variable with class name. We can do the same thing by importing the static method or variable only and then use it in the class as if it belong to it. import static java.lang....

Java important question - 8

Q) What is composition in Java ?           Composition is the design technique to implement has a relationship in classes. We can use object composition for code reuse.           Java composition is achieved by using instance variables that refer to other objects. The benefit of using composition is that we can control the visibility of other objects to client classes and reuse only what we need. Q) What is the benefits of composition over inheritance ?           Prefer composition over inheritance is a one of the popular object oriented design principles, some of the possible reasons are 1) Inheritance is tightly coupled whereas composition is loosely coupled. 2) Any change in superclass might affect subclass even though we might not be using the superclass methods. For example, if we have a method test() in the subclass and suddenly somebody introduces a method test() in the superclass, we may get compilation e...

Java important question - 7

Q) What is Inheritance ?           Inheritance is one of the key features of object oriented programming. It is the mechanism in java in which one class inherits the properties (methods and fields) of another class.           The class which inherits the properties of other is known as subclass and the class whose properties are inherited is known as superclass.           extends is the keyword used to inherit the properties of a class. Following is the syntax of extends keyword. Syntax: class Super { .......... .......... } class Sub extends Super { .......... .......... } Q) Can an interface implement or extend another interface ?          Interface can't implement  another interface, since interfaces can't have method implementations. An interface can extend another interface. Q) What is Marker interface ?         A Marker interface is an empty interface withou...

Java important question - 6

Q) What is the difference between abstract class and interface ? Answer : 1) The abstract keyword is used to declare  abstract class.  The interface keyword is used to declare interface. 2) Abstract class have all the features of a normal java class except that we can't instantiate it. We can use abstract keyword to make a class abstract but interfaces are a completely different type and can have only public static final constants and method declarations. 3) Abstract class can have abstract and non abstract methods. Interface can have only abstract methods. 4) Abstract class can have final, non-final, static and non-static variables. Interface has only static and final variables. 5) A java abstract class can have class members like private, protected,etc. Members of a java interface are public by default. 6) Abstract classes can have constructors but interface can't have constructors. 7) A subclass can extend only one abstract class but it can implement multiple interfaces. 8)...

Java important Question - 5

Q) What are wrapper classes? Why do we need wrapper classes ? Answer :           Wrapper class provides the mechanism to convert primitive into object and object into primitive. In the java.lang package java provides a separate class for each of the primitive data types namely Boolean, Byte, Short, Integer, Float, Long, Double & Character. These are known as wrapper classes because they wrap the primitive data type into an object of the class. Need of wrapper classes : * They convert primitive data types into objects. Objects are needed if we wish to modify the arguments passed into a method. * The classes in java.util package handles only objects and hence wrapper classes help in this case also. * Data structures in the collection framework, such as ArrayList and vector, store only objects and not primitive types. * An object is needed to support synchronization in multithreading. Q) What is an interface ? Answer :           An inte...

Java important question - 4

1) What is anonymous inner class ?           A local inner class without name is known as anonymous inner class. An anonymous class is defined and instantiated in a single statement. Anonymous inner class always extend a class or implement an interface.           Since an anonymous class has no name, it is not possible to define a constructor for an anonymous class. Anonymous inner classes are accessible only at the point where it is defined. 2) What is the difference between == and .equals() method in Java?           In general both equals() and "==" operator in java are used to compare objects to check equality but here are some of the difference between the two: 1) Main difference between . equals() method and == operator is that one is method and other is operator. 2) We can use == operators for reference comparison and .equals() method for content comparison. In simple words, == checks if both objects point ...

Java Important questions - 3

1) Name the methods of Object class? clone() - This method helps to create and return a copy of the object. equals() - This method helps to compare. finalize () - called by the garbage collector on an object. getclass() - It helps to return the runtime class of an object. hashcode() - Helps to return a hash code value for the object toString() - helps to return a string representation of the object. notify(), notifyAll() and wait() - It helps to synchronize the activities of independently running threads in a program. 2) What are constructors in java? What are the types of constructors?           In java, the constructor is a block of code used to initialize an object. The constructor is a method which has the same name as class name. There are two types of constructors: 1. Default constructor :           A constructor that has no parameters is known as default constructor. If we don't define a constructor in a class, the compiler...

Class in java

Define class in Java           In java, a class is a template used to create object and define the data type. It acts as a building block for java language oriented systems. All java codes are defined in a class. A class has variables and methods.           Variables are attributes which define the state of class.           Methods are the place where the exact business logic has to be done. It contains a set of statements or instructions to satisfy the particular requirement. Eg:  public class Addition // class name declaration { int a= 5; // variable declaration int b= 5;  public void add() { // Method declaration int c=a+b; } } What do you mean by object ?           Object is a basic unit of  Object oriented programming and represents the real life entities. A typical java program creates many objects, which interact each other by invoking methods. A java object is a com...

Main method in Java

What is main method in Java?           Main method in Java is an standard method which is used by JVM to start execution of any java program. Main method is referred as entry point of any standalone java application.           Main method in Java is public so that it's visible to every other class, even which are not part of it's package. If it is not public, JVM class might not able to access it.           Main method is static so that java runtime can access it without initializing the class. While JVM tried to execute java program, it doesn't know how to create instance of main class as there is no standard constructor is defined for main class.           Main method is void in Java because it doesn't return anything to caller which is JVM. Signature of main method:           main method is public, static and void and accept an array of String as argument throu...

Java Important Questions - 2

1) Does Java uses pointers?          No, java doesn't use Pointers. Carelessness in their use may result in memory problems. Also it has tough security. Instead of Pointers, reference are used in java as they are safer and more secure when compared to a Pointer. 2) How are Destructors defined in java?           Since, java has it's own garbage collection, no destructors are required to be defined. Destruction of objects is automatically carried by the garbage collection mechanism. 3) What is the difference between path and classpath variable?           PATH is an environment variable used by operating system to locate the executables. Once you installed java on your machine, it is required to set the PATH environment variable to run conveniently run the executables (javac.exe, java.exe, javadoc.exe,and so on) from any directory without having to type the full path of the command,such as: c:\javac Testclass.java O...

Difference between JDK, JRE and JVM

Difference between JDK,JRE and JVM           JDK, JRE and JVM are core concepts of java programming language. Although they all look similar and as a programmer we don't care about this concepts a lot, but they are different and meant for specific purpose. JDK           Java development kit is the core component of java environment and provides all the tools, executables and binaries required to compile, debug and execute a java program. JDK is a platform specific software and thats why we have separate installers for Windows, Mac and Unix system. We can say that JDK is superset of JRE. Since it contains JRE with java compiler, debugger and core classes. Current version of JDK is 16 also known as java 16. JVM            JVM is the heart of java programming language. when we run a program, JVM is responsible to converting Byte code to the machine specific code. JVM is also platform dependent and provides core...

Java Questions and Answers - 1

1) What do you mean by platform independent in java?           Platform independence means that you can run the same java program in any Operating system. For example, you can write java program in window and run it in Mac OS. 2) What is JVM and is it platform independent ?           Java virtual machine (JVM )  is the heart of java programming language. JVM is responsible for converting byte code into machine readable code. JVM is not platform independent, that's why you have different JVM for different operating system. We can customize JVM with java options, such as minimum and maximum memory to JVM. It is called virtual because it provides an interface that doesn't depend on the underlying OS. 3) Java compiler is stored in JDK, JRE or JVM ?           The task of java compiler is to convert java program into byte code, we have javac executeable for that. So it must be stored in JDK, we don't need it in JR...