Properties of Java

Java bytecode में compile होता है जिसे कोई भी JVM run कर सकता है, यही वजह है एक program हर machine तक travel करता है: write once, run anywhere, साथ ही Java की properties की classic exam list।

9 min read · 10 cards · 2 checks

Read in: English · हिन्दी · ગુજરાતી


Theory

वह Program जो Travel नहीं करता था

BCA104 में आपने college lab में एक C program compile किया। यह वहाँ perfectly चला। आपने इसे अपने friend के laptop पर copy किया और यह start होने से मना कर दिया: compiled file lab machine की language बोलती थी, laptop की नहीं।

इस semester आप BookBridge बनाते हैं, एक small library app। Librarian के पास एक old Windows PC है, आपका external examiner शायद Linux run करे, और आप अपने खुद के laptop पर test करते हैं। हर machine के लिए rewrite या recompile करना exactly वह pain है जिसे हटाने के लिए Java invent किया गया था।

Theory

Half-Cooked Meal Kit

एक C compiler एक fully cooked dish serve करता है: एक specific table के लिए perfect, कहीं और useless।

Java इसके बजाय एक meal kit pack करता है: recipe को एक standard, half-finished form (bytecode) में pre-process किया जाता है, और हर kitchen एक local chef (JVM) रखती है जो उस kitchen के लिए इसे finish करता है। Same kit, कोई भी kitchen। यही Java का famous promise है: write once, run anywhere।

Theory

Promise कैसे काम करता है

Java platform-independent है क्योंकि compilation 2 stages में होता है:

  • javac आपके .java source को bytecode (एक .class file) में compile करता है, एक standard instruction set जो किसी real machine का नहीं है।
  • हर computer पर JVM (Java Virtual Machine) उस bytecode को पढ़ता है और execute करता है, local machine की instructions में translate करते हुए।

तो एक BookBridge.class file Windows, Linux और macOS पर चलती है, जब तक हर एक के पास अपना खुद का JVM installed है।

At a glance

Java की Properties (Exam List)

Propertyइसका मतलब क्या है
SimpleC-family syntax pointers, operator overloading और अन्य sharp edges के बिना
Object-orientedसारा code classes के अंदर रहता है; objects real world model करते हैं
Platform-independentBytecode + JVM write once, run anywhere देते हैं
Portableकोई machine-dependent sizes नहीं: एक int हर जगह 4 bytes है
RobustGarbage collection, exception handling, strict compile-time checks
Secureकोई direct memory access नहीं; JVM run करने से पहले bytecode verify करता है
Multithreadedएक program एक साथ कई tasks कर सकता है (Unit 4)
High-performanceJIT compiler running के दौरान hot bytecode को native code में बदल देता है

Quiz

Java को exactly platform-independent क्यों कहा जाता है?

  1. javac source को bytecode में compile करता है, और किसी भी platform का JVM उसी bytecode को execute कर सकता है
  2. Compiler हर operating system के लिए एक अलग native .exe produce करता है
  3. Java programs बिना किसी compilation के सीधे source code से run होते हैं
  4. Java में pointers नहीं हैं, तो programs machine पर depend नहीं कर सकते
Show the answer

javac source को bytecode में compile करता है, और किसी भी platform का JVM उसी bytecode को execute कर सकता है

पूरी trick 2-stage design है: एक universal bytecode file, per-platform JVM से execute की गई। Option B C जैसी languages में cross-compiling describe करता है, opposite approach। Option C एक purely interpreted language describe करता है, पर Java compiled HAI (bytecode में)। Option D Java के बारे में एक true fact है फिर भी platform independence से कुछ लेना-देना नहीं रखता; exams इस true-fact-wrong-reason trap को पसंद करते हैं।

Theory

Robust और Secure, Concretely

दो properties एक answer में एक line से ज़्यादा deserve करती हैं।

Robust: C में, एक stray pointer silently memory corrupt कर सकता है। Java pointers हटाता है, automatically memory free करता है (garbage collection), और आपको exceptions (Unit 3) के ज़रिए errors face करने पर मजबूर करता है। Programs mysteriously नहीं बल्कि loudly और early fail होते हैं।

Secure: JVM के run करने से पहले bytecode एक verifier से गुज़रता है, और code raw memory addresses को touch नहीं कर सकता। यही वजह है banks और Android apps ने दशकों तक Java पर trust किया।

Think first

इसे C से Compare कीजिए

BCA104 में, marks.c compile करना एक ऐसी file produce करता था जिसे सिर्फ़ वह machine type run कर सकता था। Tap करने से पहले: BookBridge.java compile करना क्या produce करता है, और इसे कौन run करता है?

Show the answer

यह BookBridge.class produce करता है, एक bytecode file जो किसी real machine से bound नहीं है। एक JVM इसे run करता है: librarian के PC पर Windows JVM, examiner के laptop पर Linux JVM, हर एक same bytecode को अपने hardware के लिए translate करता है। C का output finished native program था; Java का output universal middle step है।

Watch out

वह Sentence जो Mark खोता है

Students लिखते हैं "JVM platform-independent है"। ग़लत, और यह mark खोता है।

Bytecode platform-independent है; JVM platform-specific है (Windows, Linux, macOS के लिए एक अलग JVM build है)। इसे इस तरह लिखिए: Java platform independence इसलिए achieve करता है क्योंकि platform-independent bytecode एक platform-specific JVM पर चलता है। वह एक sentence examiner को दिखाता है आप machinery समझते हैं।

Theory

आप पहले ही Java से मिल चुके हैं

BCA305-02 में आपने Android screens बनाने के लिए Java लिखा, तो syntax नई नहीं है। यह subject नीचे जाता है: WHY language इस तरह behave करती है, proper OOP (Unit 2), Strings और exceptions (Unit 3), threads (Unit 4) और hand-built linked lists (Unit 5), यह सब BookBridge के अंदर। और BCA304 का C++ mind में रखिए: आधे exam comparisons Java बनाम C++ हैं।

Summary

Key takeaways

  • Java 2 stages में compile होता है: javac source को bytecode (.class) में बदलता है, और एक JVM हर machine पर bytecode execute करता है।
  • Write once, run anywhere: एक bytecode file वहाँ चलती है जहाँ भी JVM exist करता है।
  • Bytecode platform-independent है; JVM platform-specific है। इन्हें कभी swap मत कीजिए।
  • Properties की exam list: simple, object-oriented, platform-independent, portable, robust, secure, multithreaded, high-performance (JIT)।
  • Robust = garbage collection + exceptions + strict checks; secure = bytecode verifier + कोई raw memory access नहीं।
  • Memory hook: meal kit travel करता है, chef घर पर रहता है।

Study this properly

This page is the lesson to read. In Gri-Learn the same topic is a graded deck: the self-checks are scored and your weak topics are tracked. Free to start.

Start this topic

Already have an account? Sign in

More from Introduction to Java

Gri-Learn · syllabus-mapped B.C.A. lessons in English, Hindi and Gujarati

Properties of Java · Java Programming Language · Gri-Learn