Core Java

What is Programming Language?

At first what is language. Language means through which we can interact with people you can communicate with each other share thought with each other. Suppose there are two people one knows Hindi and other knows English, so they cannot communicate and understand each other, so for there communication they require one person who knows both languages Hindi and English, so he can translate it and transfer it to other person so they can communicate with each other

Same apply in Programming language, if a person has to communicate or use the computer then for that it require a programming language through which it gives instructions, command to computer like open this folder, play that video. For computer we use language like C, C++, Java Python, Ruby. In programming language we have syntax. Syntax means the way you write, like in English grammar it is compulsory to use full stop, comma. Similarly in programming we have set of rules in all the programming languages which we have to follow. In Programming language we have compiler which convert programming language into binary code(means in 0 or 1 format).

Person——→Programming language——Syntax——>Computer

History

Java is developed by company Sun Microsystem . The father of java is James Gosling, when first is developed then it name was Project green and the first version is launch in 1996 and its code name is Oak.

Comparison between C++ and Java

C++ is a Static language(static means the variable gets a place in compile time when the class load ) and Java is a dynamic language(dynamic means the variable gets a place in runtime). C, C++ is a preprocessor language. Java loads all the things during runtime. About static and dynamic we know in details in next blog

C and C++ Code Execution

Generated image

  • Preprocessor: Handles #include, #define, removes comments.

  • Compiler: Analyzes and converts code to intermediate form and optimizes.

  • Assembler: Converts intermediate code to machine-level object code.

  • Linker: Links all object files and libraries into a final .exe or a.out.

  • Loader: Loads the program into memory for execution.

  • Execution: CPU runs the machine code instructions.

Java Code Execution

Generated image

Before Java code goes to the computer, it first goes to the compiler, and then it goes to the computer.

Preprocessing

in Java, "preprocessing" is not a separate phase like it is in C or C++. However, things like annotations, import statements, comment removal, and lexical analysis happen before or during the compilation process — so you can loosely refer to them as preprocessing in Java.

C and C++ is platform dependent

C & C++ is a platform dependent. If prog language allows its application to perform compilation on the same operating system then that programming language is called platform dependent. C is a platform dependent language because after compilation you get a .exe file in windows but that .exe file you cannot run in other OS like Linux, Mac because it run on Windows. When you run that windows .exe file in other OS it say i am not able to execute it you have to compile again in this OS then it gives you machine code. Machine code is different for all other OS in C, C++. In C, C++ you get a machine code depend on the platform what you use for Mac you get a different machine code and for Linux you get a different machine code

Suppose you have C code when you run it in code editor then its first step is it do compilation and the machine in which that compilation is done it have window OS then it converted it into byte code(.exe) then after that it do execution and after then it gives output, .exe file contains directly executable code, it is generated as per windows OS representation only. In C, C++ you give direct executable code.

Java is platform independent

You have a java file and you run that in code editor then its first step is it does compilation after compilation java code converted it into .class file and this .class file is not platform dependent you can execute that .class file in any other system with different OS. (.class) file is a platform independent but actually java is a platform dependent but it’s .class file is platform independent. In java you give .class file then JVM convert it into executable code.

Difference between .exe and .class

Feature.exe (C/C++).class (Java)
Full FormExecutable FileClass File (Bytecode)
LanguageC / C++Java
Generated ByC/C++ CompilerJava Compiler (javac)
PlatformPlatform Dependent (works only on specific OS)Platform Independent (runs on JVM)
Run ByDirectly by Operating SystemJava Virtual Machine (JVM)
ContentMachine Code (specific to OS/CPU)Bytecode (JVM-readable code)
Portability❌ Not portable✅ Highly portable (runs anywhere with JVM)
Exampleprogram.exe (for Windows)Hello.class

for checking the version of JVM

used command in command prompt java --version

0
Subscribe to my newsletter

Read articles from Khelendra Kumar Thakur directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Khelendra Kumar Thakur
Khelendra Kumar Thakur