Java Overview: Evolution and Basics

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

In Java, you must compile a program using the javac compiler before it can be executed by the Java Virtual Machine.

True (A)

The process-oriented model revolves around data, characterizing a program as data acting on code.

False (B)

Encapsulation in Java ensures that data within a class is always directly accessible from any part of the program.

False (B)

The public keyword, when used in a class definition, restricts access to the class only to members within the same package.

<p>False (B)</p>
Signup and view all the answers

Inheritance aids code reusability by allowing a subclass to inherit methods and fields from a superclass but does not promote abstraction.

<p>False (B)</p>
Signup and view all the answers

Polymorphism enables one interface to be implemented with the same class of actions.

<p>False (B)</p>
Signup and view all the answers

Abstraction involves displaying all details, both essential and non-essential, to the user to provide full transparency.

<p>False (B)</p>
Signup and view all the answers

A Java package is primarily used to enforce strict naming conventions but does not offer any data encapsulation benefits.

<p>False (B)</p>
Signup and view all the answers

Subpackages are by default imported, so members of a subpackage always have access privileges to the parent packages.

<p>False (B)</p>
Signup and view all the answers

Checked exceptions in Java must be handled either with a try-catch block or declared with a throws clause in the method signature.

<p>True (A)</p>
Signup and view all the answers

Flashcards

What is an Applet?

A special kind of Java program that is designed to be transmitted over the Internet and automatically executed by a Java-compatible web browser.

What is a Servlet?

A small program that executes on the server. It dynamically extends the functionality of a web server, similar to how applets extend a web browser.

What is Java Bytecode?

Bytecode is a highly optimized set of instructions designed to be executed by the Java run-time system, which is called the Java Virtual Machine (JVM).

What is Object-Oriented Programming (OOP)?

A programming approach that organizes a program around its data and well-defined interfaces, focusing on data controlling access to the code.

Signup and view all the flashcards

What is Encapsulation?

Combines code and data, keeping them safe from external interference.

Signup and view all the flashcards

What is Polymorphism?

The ability to specify a general set of actions; the exact action is determined by the nature of the situation.

Signup and view all the flashcards

What is the Java Development Kit (JDK)?

A kit that provides an environment to develop and execute Java programs, including development tools and the JRE.

Signup and view all the flashcards

What is the Java Runtime Environment (JRE)?

An environment to only execute Java programs on your machine. It contains system class libraries and the JVM.

Signup and view all the flashcards

What is the Java Virtual Machine (JVM)?

Acts as a run-time engine to run Java applications. Also known as an interpreter.

Signup and view all the flashcards

What is a Package in Java?

A mechanism to encapsulate a group of classes, subpackages, and interfaces for preventing naming conflicts, making searching easier, and providing controlled access.

Signup and view all the flashcards

Study Notes

Java Overview

  • Java is for programming and applications, under course code EEE 32502.
  • Primary learning points include evolution, the basics, and the first program code.

Evolution of Java

  • Understanding Java's origins requires knowing the reasons behind its creation.
  • Computer language innovation stems from adapting to new environments and refining existing techniques.
  • Java incorporates influences from C and C++, inheriting much of its character from these languages.
  • Java derives its syntax from C, and its object-oriented features were influenced by C++.
  • Language design innovations solve fundamental problems that earlier languages couldn't.
  • C's, created in 1970, has a limit in handling complexity as program size increases.
  • C++ adds features that help programmers manage larger programs.
  • Bjarne Stroustrup invented C++ in 1979 at Bell Laboratories, originally naming it "C with Classes."
  • In 1983, "C with Classes" was renamed to C++.
  • C++ extends C with object-oriented features, maintaining C's original attributes and benefits.
  • C++ was meant as an improvement to the existing language instead of a complete rewrite.
  • The rise of the World Wide Web and the Internet triggered another programming revolution.
  • Java was conceived in 1991 at Sun Microsystems, Inc. by James Gosling and others.
  • It took 18 months to develop Java’s first working version.
  • Initially named "Oak", the language was renamed to "Java" in 1995.
  • Java's origin adapts to environmental changes and implements advances in programming art.
  • The need for platform-independent programs for distributing on the Internet prompted Java's creation.
  • Java refined object-oriented paradigms from C++, added multithreading support, and simplified Internet access with a library.
  • The Internet played a vital role in establishing Java's leadership in programming.
  • Java innovated the applet, a type of networked program for the Internet.
  • An applet is transmitted over the Internet and executed by a Java-compatible web browser.
  • Applets present security and portability concerns, so Java addressed these through built-in security and portability features.
  • Java is also useful on the server side, leading to the development of the servlet.
  • A servlet is a small server-side program, which extends web server functionality in the same way applets extend web browser functionality.
  • The Java compiler output is bytecode, an optimized set of instructions for the Java Virtual Machine (JVM).
  • Key design considerations include Java's simplicity, security, portability, object-orientation, robustness, multithreading, architecture-neutrality, interpreted nature, efficiency, distribution capabilities, and dynamic behavior.

Overview of Java

  • Object-oriented programming (OOP) is the core of Java.
  • All computer programs have code and data.
  • The two programming paradigms are the process-oriented model and object-oriented programming.
  • The process-oriented model sees programs as a sequence of linear steps, where code acts on data,
  • Procedural languages like C use the process-oriented model effectively.
  • Object-oriented programming organizes a program around data (objects) with well-defined interfaces.
  • In object-oriented programming, data controls access to code.
  • Abstraction is an essential element of object-oriented programming.
  • Hierarchical classifications manage abstraction successfully.
  • Abstraction can transform data from process-oriented programs into component objects.
  • Process steps become messages between objects
  • Each object has unique behavior.
  • Objects respond to messages, making them act as concrete entities; this is the core of object-oriented programming.
  • Object-oriented languages offer mechanisms to implement the object-oriented model, including encapsulation, inheritance, and polymorphism.
  • Encapsulation binds together code and data, protecting them from outside misuse.
  • Encapsulation is like a protective wrapper, using well-defined interfaces to allow tightly controlled data access.
  • In Java, a class forms the basis of encapsulation, defining the structure and behavior (data and code) that its objects will share.
  • Classes encapsulate complexity through private or public methods and variables.
  • The public interface provides external class users with information they need.
  • Only members of a class can access private methods and data.
  • Inheritance enables an object to acquire the properties of another, supporting hierarchical classification.
  • Subclasses inherit the attributes of encapsulated classes, along with any new specializations.
  • A new subclass inherits all attributes from ancestor classes.
  • Polymorphism is one interface can be used for a general class of actions, executing specific actions depending on the situation.
  • In Java, polymorphism allows specifying a general set of stack routines that share names, unlike non-object-oriented languages.
  • The combination of polymorphism, encapsulation, and inheritance allows programming environments to create robust, scalable programs

First Simple Program

  • Source file names are significant in Java.
  • The class name in the program matches name of program.
  • To compile a program, use the compiler, javac, which creates a file with a .class extension that contains program bytecodes.
  • Java bytecode is an intermediate representation of your program that instructs the Java Virtual Machine.
  • You must use the Java application launcher, java, to run a program.
  • Compiled Java classes are put into unique output files with the ".class" extension.
  • Matching Java source and class file names ensures correct execution with the java launcher.
  • When executed, Java launcher searches for class extension files that matches name
  • Code will only execute if the Java launcher finds .class extension file.
  • The first lines of the program are ignored by the compiler
  • Use the keyword class to declare a new class.
  • Class names are an identifier, such as Example.
  • The main() method uses the public access modifier to make class members visible.
  • A public member is accessible to code outside the class.
  • The opposite of public is private, which prevents code outside of the class from using that member.
  • Main() must be declared public to be called when program is started.
  • The static keyword allows main() to be called without instantiating the class.
  • The keyword void tells the compiler that main() does not return a value.
  • Java compiles classes without a main() method, but these classes cannot be run.
  • String args[] declares a parameter named args as an array of String class instances (collections of similar objects).
  • String type objects store character strings and receive command-line arguments when the program executes.
  • The programs output is accomplished by calling the built-in println()` method.
  • System is a predefined class that provides access to the system, and out is the output stream connected to the console.

Differences Between OOP and POP

  • In procedure-oriented programming (POP), large programs consist of smaller modules or parts.
  • The smaller modules or parts are known as functions or procedures.
  • In POP, each procedure contains a series of instructions to perform a precise task.
  • Throughout program execution, functions can be called by other functions.
  • Procedures are called by writing function names only.
  • Programmers focus more on the development of functions instead of data.
  • In POP, primary emphasis is placed on procedure instead of data.
  • In a multi-function program, important data items are global for all functions to access.
  • Global data is more susceptible to accidental change from functions.
  • It is difficult to identify what data is implemented in which part of the function in larger code.
  • C programming language is an example of POP programming.
  • Object-oriented programming (OOP) is an approach to programming treats data as an important element.
  • Primary emphasis is placed on data instead of the procedure during execution/function.
  • OOP ties data together closely with its associated functions, protecting this data from being accidently modified.
  • Problems can be resolved by an OOP programming language via objects, which creates data and function around it.
  • Data in an object can only be accessed using the assigned function; no other object can access the data outside objects.
  • The object-oriented programming (OOP) languages include C++, Java, Python, etc.

Java Development Kit (JDK), Java Runtime Environment (JRE), and the Java Virtual Machine (JVM)

  • The Java Development Kit (JDK) is a kit which provides the environment to develop and execute the Java program.
  • JDK consists of JRE and development tools.
  • JRE, Java Runtime Environment, enables to run and not develop machine onto machine.
  • JVM, Java Virtual Machine, is also known as an interpreter, runs run Java applications.

Encapsulation

  • Encapsulation wraps up data into a single unit.
  • Encapsulation binds code together with the data it utilizes.
  • Encapsulation serves as a security which prevents code accessed from the outside the class.
  • Encapsulation hides data by only declaring the variables and data of a class, and it can be accessed through the member function of the class.
  • With encapsulation, data is hidden by creating the members and methods as private, and the class can protect the end-user by using data hiding and abstraction.
  • Encapsulation can be done by declaring the variables as private and writing public methods to set the values of the variables.
  • Commonly defined by the setter and getter method.
  • The advantages to Encapsulation include data hiding, increased accessibility, reusability and easier to test.

Modifiers

  • Modifiers are divided into access modifiers and Non-access modifiers.
  • The access level is controlled by the access modifiers.
  • Non-access modifiers do not control the access level, but control the information about the functionalities.

Access Modifiers

  • The categories access modifiers include public and default.
  • With public modifier, the class can be accessed by many members.
  • Only modifiers in the same package can access the class under the default modifier.
  • Access modifiers for attributes, methods and constructors include public, private, default and protected
  • With the public modifier, the functions and attributes can be accessed through all classes.
  • With the private modifier, the code can only be accessed within the class.
  • The default modifier restricts code to be accessed in only the packages, specifically.
  • With the protected modifier, any subclass and code may be accessed from the same package.

Non-Access Modifiers

  • Classes can use the modifiers of final or abstract.
  • With the final modifier, a class cannot be inherited using any additional class.
  • Classes which cannot create any inherited objects utilize the abstract modifier.
  • Methods can utilize the attributes of final, static and abstract.
  • An attribute of the final modifier is that it cannot be overriden.
  • Instead of working off of objects, functions can inherit attributes through the tag of the modifier, static.
  • An attribute of code under the abstract modifier is they're used under abstract classes and methods, for example, abstract void run();.

Inheritance:

  • A new class is derived from the existing one, where an inherited class can reuse the methods.
  • Functions can add in new content and adjust new fields.
  • Coding becomes reusable due to inheritance.
  • Through reusability, there is less coding.

Abstraction

  • Inheritance makes it easy for a common interface with abstract classes.
  • With inheritance, the code is easily maintained and extendable.
  • A class hierarchy is created via inheritance.
  • Creating hierarchy makes code simpler due to real-world interaction.

Polymorphism:

  • Polymorphism provides several forms of code.
  • With Java, you can show one form with multiple coding.
  • The words, "poly" and "morphs" denote "many" and "forms", essentially many Forms.
  • Mainly, Polymorphism is divided into Compile-time polymorphism and Runtime Polymorphism.
  • Compile-Time Polymorphism is static, and it's achieved through overloading operators.
  • With Dynamic Code Dispatch, a function is resolved through its runtime with Runtime Polymorphism.

Abstraction:

  • Displaying only vital codes to the user, hides non vital codes.
  • Data Abstract hides unnecessary attributes.
  • Interfaces show the differences and grouping under classifying purposes.
  • To reach maximum isolation with interfaces, codes are achieved through interfaces and abstract classes

Encapsulation vs Data Abstraction.

  • Hiding data from the outside is encapsulation, while abstraction hides detailed information.
  • Data abstraction and encapsulation deals with exposing data while hiding implementation information.
  • Encapsulated codes follow data hiding and abstraction, and abstract classes help create isolated functions.
  • Abstraction takes place on a design-level and encapsulation is implemented on a procedural function, during implementation.

Summary OOP:

The major attributes of the object are:

  • Encapsulation
  • Data Hiding
  • Inheritance
  • Polymorphism
  • Abstraction

Packages:

  • Putting several classes that act as subclasses and interfaces in coding is known as "Packages".
  • Packages serve an array of different functions, but mainly handles different coding practices.
  • The main utilities handle codes from naming conflicts, searching, coding and general annotation/enumeration.
  • Packages are seen to be the same as data encapsulation and data hiding, and serves a role to allow protected members function in subclass and default packages.
  • All that's need to put together classes goes through putting packages together and importing current packages over.
  • To put a directory together with ease, save the java file and the code should be available.
  • All codes that are packages also have the roles to be in subpackages .
  • Some functions and data can't be accessed by any outside source other than the coding itself with functions such as Util inside Java due to lack of access.
  • Coding language has Built-in and user functions or code.

Exception Handling:

  • Exceptions may rise through user error, whether it be through incorrect documentation or a non-defined user file.
  • Coders should pre-determine issues that users may face.
  • Coders pre-determine coding that acts as safety and pre-caution measures to ensure the users do not run int to coding issues,

Idea:

  • Upon determining issues, an exception will immediately be deployed.
  • When an exception takes place, an error message or safety catch with try is dispatched.
  • try protocols exist to ensure that no error or safety issues arise during the usage.
  • When using try protocols, the program will try to identify existing issues, or will relay an error report to the user.
  • An exception comes down to whether a checked exception or unchecked exception exists.
  • Under Checked exception mode, the code must be included or marked.
  • With exception errors, a try/catch protocol exists.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Java's Lineage and Influences Quiz
10 questions

Java's Lineage and Influences Quiz

IndividualizedCatharsis avatar
IndividualizedCatharsis
Java Evolution: EEE 32502
40 questions

Java Evolution: EEE 32502

StylishSpessartine avatar
StylishSpessartine
Use Quizgecko on...
Browser
Browser