Stack memory in data structures is the amount of memory allocated to each individual programme. It is a fixed memory space. Heap memory, in contrast, is the portion that was not assigned to the Java code but will be available for use by the Java code when it is required, which is generally during the program’s runtime.
Author: saqibkhan
-
What are the Memory Allocations available in JavaJava?
Java has five significant types of memory allocations.
- Class Memory
- Heap Memory
- Stack Memory
- Program Counter-Memory
- Native Method Stack Memory
-
What is a ClassLoader?
A classloader in Java is a subsystem of Java Virtual Machine, dedicated to loading class files when a program is executed; ClassLoader is the first to load the executable file.
Java has Bootstrap, Extension, and Application classloaders.
-
What do you get in the Java download file? How do they differ from one another?
We get two major things along with the Java Download file.
JDK – Java Development Kit
JRE – Java Runtime Environment
JDK JRE Abbreviation for JavaDevelopment Kit Abbreviation for Java Runtime Environment JDK is a dedicated kit for solely software development JRE is a set of software and library designed for executing Java Programs Unlike JVM, JDK is Platform Dependent Unlike JVM, JRE is also Platform Dependent JDK package is a set of tools for debugging and Developing JRE Package is one that only supports files and libraries for a runtime environment JDK package will be provided with an installer file JRE Package does not get an installer but has only a runtime environment -
List the features of the Java Programming language?
A few of the significant features of Java Programming Language are:
Easy: Java is a language that is considered easy to learn. One fundamental concept of OOP Java has a catch to understand.
Secured Feature: Java has a secured feature that helps develop a virus-free and tamper-free system for the users.
OOP: OOP stands for Object-Oriented Programming language. OOP signifies that, in Java, everything is considered an object.
Independent Platform: Java is not compiled into a platform-specific machine; instead, it is compiled into platform-independent bytecode. This code is interpreted by the Virtual Machine on which the platform runs.
-
What are the differences between C++ and Java?
- Concept.
C++ is not platform-independent; the principle behind C++ programming is “write once, compile anywhere.”
In contrast, because the byte code generated by the Java compiler is platform-independent, it can run on any machine, Java programs are written once and run everywhere.
Also Read: Learn C++ Programming
- Languages Compatibility.
C++ is a programming language that is based on the C programming language. Most other high-level languages are compatible with C++.
Most of the languages of Java are incompatible. Java is comparable to those of C and C++.
- Interaction with the library.
It can access the native system libraries directly in C++. As a result, it’s better for programming at the system level.
Java’s native libraries do not provide direct call support. You can use Java Native Interface or access the libraries.
Characteristics.
C++ distinguishes itself by having features that are similar to procedural and object-oriented languages. The characteristic that sets Java apart is automatic garbage collection. Java doesn’t support destructors at the moment.
- The semantics of the type.
Primitive and object types in C++ have the same kind of semantics. The primitive and object and classes of Java, on the other hand, are not consistent.
- In the context of Compiler and Interpreter.
Java refers to a compiled and interpreted language. In contrast, C++ is only a compiled language.
In Java, the source code is the compiled output is a platform-independent byte code.
In C++, the source program is compiled into an object code that is further executed to produce an output.
-
Java Program to Calculate Simple Interest:
import java.util.Scanner; public class SimpleInterest { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print(“Enter principal amount: “); double principal = input.nextDouble(); System.out.print(“Enter rate of interest: “); double rate = input.nextDouble(); System.out.print(“Enter time period in years: “); double time = input.nextDouble(); double simpleInterest = (principal * rate * time) / 100; System.out.println(“Simple Interest: ” + simpleInterest); input.close(); }Output:
Enter principal amount: 5000 Enter rate of interest: 2.5 Enter time period in years: 3 Simple Interest: 375.0 -
Calculate Compound Interest in Java:
public class CompoundInterest { public static void main(String[] args) { double principal = 15000, rate = 5.5, time = 3; double compoundInterest = principal * (Math.pow((1 + rate / 100), time)) – principal; System.out.println(“Compound Interest: ” + compoundInterest); }Output:
Compound Interest: 2653.4375 -
Check Vowel or Consonant in Java:
public class VowelConsonant { public static void main(String[] args) { char ch = ‘A’; if (ch == ‘a’ || ch == ‘e’ || ch == ‘i’ || ch == ‘o’ || ch == ‘u’ || ch == ‘A’ || ch == ‘E’ || ch == ‘I’ || ch == ‘O’ || ch == ‘U’) { System.out.println(ch + ” is a vowel.”); } else { System.out.println(ch + ” is a consonant.”); } }Output:
A is a vowel. -
Check Leap Year in Java:
public class LeapYear { public static void main(String[] args) { int year = 2024; if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) { System.out.println(year + ” is a leap year.”); } else { System.out.println(year + ” is not a leap year.”); } }Output:
2024 is a leap year.