Core Java Page1

Answer:

  1. Java is a robust, object-oriented, secure & high-level programming language. It has multiple features, such as platform-independent, multithreaded, portable, & high performance. Been developed in June 1991 by James Gosling, Java is also known as a platform as it provides its own JRE & API.
  2. James Gosling developed in 1991. It is a high-level, object-oriented, & class-based programming language.
  3. Java is a compiler that compiles the source code of a program & generates bytecode. In simple terms, it produces the Java byte code from the source code written *.java file. JVM executes the bytecode to run that program.
  4. There are several definitions for Core Java, yet the most commonly accepted meaning of Java is related to its syntax, data structures, & elements that a developer needs to learn. Core Java usually excludes JSPs, Servlets, JPA, etc.
  5. Being a robust general-purpose programming language, Java fosters embedded systems, big data processing, desktop or mobile applications, and other software development. As per Oracle, Java runs on 3 billion devices globally, making it one of the most popular programming languages.
  6. Java is a popular computing platform & a programming language that was released in 1995 at Sun Microsystems. Several applications & websites do not work unless Java is installed in their systems. It is a reliable, fast, & secure language. For that reason, Java is used everywhere, from laptops, game consoles to datacenters, scientific computers, & cell phones.
  7. Java is a platform-independent language developed at Sun Microsystem by Patrick Naughton, Ed Frank, James Gosling & Mike Sheridan. Java supports different applications ranging from Enterprise applications, Financial applications to Scientific applications

Answer:

  1.  JVM or Java Virtual Machine empowers computers to run programs written in Java. It facilitates a runtime environment that executes Java bytecode. Java Virtual Machine is detailed by a specification that defines what needs for the implementation of JVM.  JVM compiles Java code to be a Bytecode, which is close to the native code & machine-independent.
  2.  JVM stands for Java Virtual Machine that provides a runtime environment to execute Java code or applications. It converts bytecode into machine language. JVM implementation is known as JRE or Java Runtime Environment.

Answer:

    • JVM
      1. Java Virtual Machine, abbreviated as JVM, is an abstract machine that provides a runtime environment that can execute Java bytecode. It is a specification that describes the working of JVM. The implementation of JVM is called JRE. Oracle & many other companies have provided the implementation of JVM.
      2. JVM is available for several software & hardware platforms. It is a runtime instance that is generated when we run the Java class. JVM has three notions, namely: implementation, specification, & instance.
      3. JVM means Java Virtual Machine that drives Java codes. We can run Java bytecode using JVM by converting them into the current OS machine language. It makes Java become a portable language.
      4. Java Virtual Machine enables computers to run the program. It provides the runtime environment that executes Java bytecodes. JVM is platform-dependent, which means for each software and hardware, we have different JVM configurations. JVM doesn’t exist physically & is abstract in nature.
    • JRE
      JRE or Java Runtime Environment is the implementation of Java Virtual Machine or JVM. JRE renders a set of software tools that helps in building Java applications. It provides the runtime environment & contains a set of libraries & other files that JVM uses at runtime.
    • JDKJava Development Kit or JDK is a software development environment that facilitates Java applications & applets development. It physically exists & contains JRE development tools.JDK is an implementation of the following Java platforms released by Oracle Corporation:
      • Micro Edition Java Platform
      • Standard Edition Java Platform
      • Enterprise Edition Java Platform
  1. JDK or Java Development Kit is used for development purposes, while Java Virtual Machine or JVM is a part of JDK that executes Java program line. JDK provides all executables, binaries, & tools necessary for compiling, debugging & executing a Java Program. The execution of that Java program is then handled by JVM to provide machine independence.
  2. JRE or Java Runtime Environment is the implementation of Java Virtual Machine (JVM). JRE embodies JVM, Java binaries, & other classes to execute a program successfully. It doesn’t consist of any development tools such as a debugger or Java compiler. To execute any Java program, one needs to install a Java Runtime Environment.
  3. JDK refers to a software environment that develops Java programs & applications by providing a collection of libraries. JRE is a software environment that allows Java programs & applications to run, and JVM is an environment that converts Java programs into bytecode executables. Both JRE & JDK are platform-dependent, whereas JVM is platform-independent.
    • JVM: Java Virtual Machine (JVM) enables computer systems to run programs. The runtime environment of JVM helps in the execution of Java bytecode. It is platform-dependent; thus, for each hardware & software, we have different JVM configurations. JVM is abstract & doesn’t exist physically.
    • JRE: JRE means Java Runtime Environment. It contains all sets of Libraries that JVM uses at runtime. JRE is imperative to run any Java code. It is platform-dependent & exists physically.
    • JDK: JDK includes development tools like Javadoc, Compiler, & Debugger along with Java Runtime Environment. It is a complete kit for developing any type of Java application. You can run code & execute Java codes & launch your application with JDK.

Answer:

    • Class (Method) Area:It stores per-class structures like runtime constant pool, method data, fields, & the code for methods.
    • Heap: Heap is a runtime data area that allocates memory to the objects.
    • Stack:Java Stack stores frames which hold local variables & partial results. It plays a vital role in method invocation & return. Each thread has a private JVM stack, which is created at the same time as the thread.
    • Program Counter Register: It is a register that contains the address of the JVM instruction being executed currently.
    • Native Method Stack:It consists of all the native methods used in applications.
  1. ClassLoader, Program Counter Register, Class(Method) Area, Stack, Heap, & Native Method Stack.

Answer:

  1. Just-In-Time or JIT compiler helps to improve the performance of a Java application. It compiles parts of the bytecode having similar functionality, thus reduces the time needed for compilation. Here “compiler” implies a translator from the instruction set of JVM to the instruction set of a particular CPU.
  2. JIT compiler is enabled by default & activated when the Java method is called.
  3. JIT compiler stands for Just-In-Time compiler. It is a crucial part of the Java Runtime Environment that is used to improve performance. JIT compiles the code when needed, but not before runtime. Therefore, it reduces the amount of time required for compilation.

Answer:

  1. A platform is a software or hardware environment that runs an application or program. Mainly there are two types of platforms, i.e., software-based & hardware-based. Java renders a software-based platform. It is platform-independent, which means you can write Java codes on one platform & run them on another platform. For instance, a Java developer writes & compiles the code on windows, thereon generated bytecode on Linux or other supported platforms.
  2. Platform in Java is a collection of programs that facilitates programmers to efficiently build and run Java applications. It consists of a compiler, an execution engine, & a set of libraries.

Answer:

  1. Below are the key differences between the Java platform & other platforms:
    • Java is a software-based platform, whereas other platforms may be hardware-based or software-based.
    • Java runs on top of other hardware-based platforms, while the other platforms can only have the hardware only components.
  2. The key difference between the Java platform & other platforms is that the former is a software-only platform containing JVM & Java API where the API supports developers in writting Java files. It is platform-independent, so codes can be written & run on any device that has JVM. In contrast, other platforms do not provide such functionality & only have hardware components, nor are they platform-independent.

Answer:

  1. Java got its write once & run anywhere (WORA) feature from its bytecode. The compiler converts a Java program into bytecode, an intermediate language between machine code & source code. That bytecode is not platform-specific & could be executed on any computer system with the help of JVM.
  2. In Java, the programs are compiled & converted to a class file or bytecode, which is interpreted by Java Virtual Machine. Thus, the generated bytecode file can run anywhere or on any JVM.

Answer:

  1. ClassLoader is a subsystem of Java Virtual Machine, used to load class files. When JVM runs the Java program, it is first loaded by the ClassLoader. Java has three built-in ClassLoaders, namely: Bootstrap ClassLoader, Extension ClassLoader, & System or Application ClassLoader.
  2. Java ClassLoader is used to load bytecode or class file. When JVM runs a Java program, it is loaded first by the ClassLoader. The ClassLoader class uses a delegation model for searching for resources & classes.
  3. ClassLoader is a part of (JRE) Java Runtime Environment that loads bytecodes for classes.

Answer:

  1. It won’t make any difference if you write static public void instead of the public static void as the order of specifiers doesn’t matter & are interchangeable in Java. Moreover, your Java program will run & compile successfully.
  2. We can write static public void instead of the public static void as it doesn’t result in a runtime error.

Answer:

  1. The local variables have no default values in Java, meaning that they must be declared & assigned an initial value before the first use; else, the compiler will throw an error.
  2. The local variables aren’t initialized to any default value, primitives, or object references.
Answer:

    Access specifiers are the keywords in Java used to define the variable, class, or method’s access scope. There are four access specifiers in Java, which are as follows:

  • Public Specifier– It attains the highest level of accessibility. Any class, method, or field defined as Public is accessible from any Java program class.
  • Protected- Fields & methods declared as protected are accessible by the subclasses in other packages or any class within the protected members’ class package.
  • PrivateSpecifier– It obtains the lowest level of accessibility. Any class, field, or method defined as Private is accessible within the same class only.
  • Default– When no access modifier is specified, all the methods, classes, & fields are of default scope.

Answer:

  1. The static methods or variables are shared amongst all the objects of the class. Static is a part of the class & not a part of the object. The static variables are stored in the class area, eliminating the need to create the object to access such variables. Hence, static is used to define methods or variables common to all the objects of a class.
    For Instance, In the class simulating the total number of college students, the college’s name will be a common attribute to all the students. Thus, it will be considered static.
    • A Static method in Java belongs to a class & not to an object or instance. It can only access the static data & cannot access non-static data.
    • A static variable is initialized only one time during the start of the execution. Java variables belong to a class & are initialized first, before the initialization of any instance variables.

Answer:

  1. There are advantages of using Java packages, such as avoiding name clashes, renders easier access control, provides access protection & removes naming collision.
  2. Java packages provide ease of organization, maintenance & boosts collaboration amongst developers.

Answer:

    • (OO)paradigm follows the bottom-up approach in designing programs.
    • It focuses on data with methods to operate upon the object’s data.
    • The object-oriented paradigm consists of different concepts, such as Encapsulation & abstraction, that hide the complexities from the end-users & show only functionality.
    • OOP implements a real-time approach like abstraction or inheritance.
    • Some examples of the object-oriented paradigm are Python, Simula, C++, C#, etc.
  1. OOP or object-oriented programming is a paradigm that helps to design a program using objects or classes. It streamlines the process of software development.

Answer:

  1. These are basic differences between object-oriented languages & object-based languages:
    • An object-oriented language follows all OOP concepts, whereas an object-based language doesn’t follow every OOP concept, such as polymorphism & inheritance.
    • Object-oriented languages do not have an inbuilt object, whereas Object-based languages do have inbuilt objects like JavaScript has a window object.
    • Some popular examples of object-oriented programming are C#, Java, & Smalltalk, while the examples of Object-based languages are VBScript, JavaScript, etc.
  2. Object-Oriented Programming Language– This language supports all the features of OOPs, including polymorphism, inheritance & built-in objects. Java, C#, VB are some examples of OOP language.Object-Based Language-This language supports the use of encapsulation & object. Unlike OOP, it does not support polymorphism, inheritance, & build-in objects. VB, Java Script are some examples of object-based language.

Answer:

  1. The constructors are a special type of method in Java used to initialize an object. A constructor is called during class instantiation & memory allocation for the objects. Each time an object is created with the newkeyword, the class’s default constructor automatically invokes itself. The constructor name has to be identical to the class name. The constructor must also not have an explicit return type; thus, it must be called only once during its lifetime.
  2. A constructor in Java is a block of code that initializes the newly created object. It is similar to an instance method in Java; however, it is not a method since it doesn’t have a return type. Java constructor & method is different, yet it is often known as a special type of method.
  3. A Java constructor helps in the creation of an object that is an instance of a class. The constructor differs from a method in Java as it doesn’t return any value, but the methods can return a value. In case a class has no constructor, then the compiler creates a default constructor automatically.
  4. A constructor is a special member function of a class that initializes the newly created object. Its name is equivalent to the class name & doesn’t return any value. When we create an instance of a class using new keywords, thereon a constructor is called by default, which is implicitly known as default constructor.

Answer:

    • Default: It is a constructor with no arguments. Default or nullary constructor is generated whenever you don’t declare any constructor in a class; thus, the compiler creates a default one automatically.
    • Parameterized: A constructor with a specific no. of arguments & parameters is known as parameterized constructors.
  1. A default constructor enables you to initialize objects with the same data, while parameterized constructor helps you create different objects with different data.

Answer:

    • Static methods are not a part of an object; rather, they belong to a class.
    • It can be called without creating the object.
    • The static method is useful for accessing & changing the static variable’s value.
  1. The following points appropriately define the static method:
    • A static method can access & change the value of a static variable.
    • It isn’t necessary to create an object for calling the static method.
    • A static method is a component of a class, not an object.
  2. The static keyword helps to create methods that can exist independently of an instance created for the class. It does not use any instance variables of an object defined in the class.

Answer:

  1. Mainly, two major restrictions are applied to static methods, which are as follows:
    • The static method cannot directly call the non-static method or utilize a non-static data member.
    • Also, it cannot use “this and super” keywords in a static context as they are non-static.
  2. When you apply the static keyword to any method, it becomes the static method. The static method cannot directly invoke the non-static method or use non-static data members.