Skip to content

gopalepic/Java-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java

  • Java is a platform independent language
  • Javac compiles the program to form a bytecode or .class file .
  • JVM mush be on the device in OS for furthur execution of the byte code

Features of JAVA

  • Simpicity
  • Platform independent
  • Interpreted: Java is intepreted as well as a compiler-based language.
  • Robust Language: features like garbage collection,exception handling ,etc that make the language robust
  • Object Oriented Language(OOPS)
  • High Performance
  • Dynamic: Supports dynamic loading of classes and interfaces
  • Multithreaded: deal with multiple tasks at once by defining multiple threads

JVM(JAVA VIRTUAL MACHINE)

JVM is a java interpreter , reponsible for loading,verifying, and executing the bytecode created in Java.

JIT(Just - In - Time)

Jit compiler is a part of JRE(JAVA RUNTIME ENVIRONMENT), used for better performance of java applications during runtime

Use of JIT step by step

  • Source code is compiled with javac to form bytecode

  • Bytecode is further passed on to JVM

  • JIT is a part of JVM, JIT is responsible for compiling bytecode into natice machine code at run time.

  • When a method (a block of code) is invoked (called) for the first time, the JIT compiler kicks in. It compiles the method into machine code, which is much faster to execute. This compilation step happens just in time, hence the name Just-In-Time compiler. alt text

Memory Storages with JVM

  • Class(Method) Area: Class Area is a memory in JVM that storeds information about classes and methods.

  • Heap : Objects are created or objects are stored. Used to Allocate memory to objects during run time.

  • Stack :Stores data and partial results

  • Program Counter Register: The PCR ensures that the JVM knows exactly where it is in the program and what instruction to execute next. This allows the JVM to run the program correctly and efficiently.

  • Native method stack : The Native Method Stack stores native methods (code written in languages like C or C++) used in a Java application, allowing the JVM to interact with the operating system, hardware, or external systems when needed.

Class Loader

ClassLoader is a part of JRE, during the execution of the bytecode or created .class file CLASSLOADER is responsible for dynamically loading the java classes and interfaces to JVM.Because of classloaders java run time system does not need to know about files and file system.

Difference between JVM , JRE and JDK

JVM

  • Type of interpreter responsible for converting bytecode into machine-readable code.
  • JVM itself is platform dependent but it interprets the bytecode which is the platform-independent reason why java is platform-independet

JRE

  • An installation package that provides an environment to run the java program or application on any machine

JDK

  • Java development kit which provides the environment to develop and execute java programs.
  • JDK provdies two things
  1. Development tools to provide an envirnoment to develop you java programs
  2. JRE to execute java programs or applications alt text

C++ vs Java: Key Differences

=====================================

Platform

C++ Java
Platform Dependence Dependent Independent

Programming Focus

C++ Java
Main Use Case System Programming Application Programming

Hardware Interaction

C++ Java
Hardware Interaction Nearer to hardware Not so interactive with hardware

Scope

C++ Java
Global Scope Supported Not Supported
Namespace Scope Supported Not Supported

Functionality

Supported in Java but not in C++

Functionality
Thread Support
Documentation Comment
Unsigned Right Shift (>>>)

Supported in C++ but not in Java

Functionality
Goto
Pointers
Call by Reference
Structures and Unions
Multiple Inheritance
Virtual Functions
OOPS

Object-Oriented Programming

C++ Java
Object-Oriented Language Yes Yes
Inheritance Hierarchy Multiple roots Single root (java.lang.Object)

Inheritance Tree

C++ Java
Inheritance Tree Creates a new tree Uses a single inheritance tree

public static void main()

  • public : Tells who can access the element or the method and what is the limit.
  • static :

Data types in Java

  • Primitive Data type : boolean , char , int , short , byte , long , float and double

Primitive means : basic building blocks of data manipulation

  • Non primitive means : memory address of a variable will be stored,because the reference types won't stores the variable value directly in memory.

  • Non - Primitive Data type :String , array

Java variables

  • Variable : Data cointainer that save the data values during java program execution

Key note , Java programs are first compiled to an intermediate form , then interpreted by the interpreter.

// Sigle line comments /* Multi line comments */

Operators

  • Arithemetic Operator

This operations includes + , - , * , / and %

  • Unary Operator

Java unary operators are he types that need only one operand to perform any operation like increment , decrement and negation etc.

  1. Unary minus(-)

Converts a positive value to a negative value or vice versa

  1. Not (!)

Converts true to false or vice versa

  1. Increment (++) & Decrement (--)

    Post Increment (num++) and Pre Increment (++num) & Post Decrement (num--) and Post Decrement (--num)

  2. Bitwise Complement(~)

Returns on's complement representation of the input value or operand

  • Assignment Operator

= , += , -= , *= , /= , %=

  • Relational Operators

== , != , > , < ,<= , >=

  • Logical Operators

AND operator (&&) OR operator (||) NOT operator (!)

  • Ternary Operator

variable = expression1 ? expression2 : expression3

  • Bitwise Operators
  1. Bitwise OR(|)

this is binary operator, denoted by "|".

eg: if either of the bits is 1, it gives 1, else it shows 0.

  1. Bitwise And(&)

this is binary operator. if both bits are 1 , then it gives 1 , else shoes 0

  1. Bitwise XOR(^)

this is binary operator if corresponstings bits are different , then it gives 1 else gives 0

  1. Bitwise Complement (~)

this is unary operator makes 1 to 0 and 0 to 1

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages