Java is an object-oriented programming language developed by James Gosling at Sun Microsystems in 1991. It derives much of its syntax from C and C++ but is designed to have as few implementation dependencies as possible so that applications written in Java can run on any device with a Java Virtual Machine (JVM). The JVM converts Java bytecode into machine code that can be executed by the device's processor. This allows Java programs to run on any platform that has a JVM without needing to be recompiled.
This document provides an overview of core Java concepts including:
- A brief history of Java's development from 1991 to today.
- Key Java features such as being object-oriented, platform independent, secure, and reliable.
- Object-oriented programming concepts in Java like classes, objects, inheritance, polymorphism.
- Common Java keywords, operators, data types, and variables.
- Additional topics covered include methods, inheritance, interfaces, exceptions, and strings.
This document provides an overview of variables and their scope in Java. It discusses the three types of variables in Java: local variables, instance variables, and class (static) variables.
Local variables are declared within methods, constructors, or blocks and can only be accessed within their declaration scope. Instance variables are declared within a class but outside of methods and can be accessed using an object reference. Class variables are declared with the static keyword, belong to the class itself rather than any object, and are accessed via the class name. The document provides examples and discusses default variable initialization.
This document provides an overview of the Java programming language and platform. It discusses Java's origins, characteristics, editions, and components like the JDK, JRE, and JVM. Java is introduced as a simple, secure, robust, and platform-independent language well-suited for client-server web applications and small devices. The document outlines Java's history and evolution from 1995 to present. Key aspects of Java like object-orientation, portability, and multi-threading are summarized.
Java is a widely used programming language that was created in 1991. It is an object-oriented language that is platform independent and runs on a virtual machine. Key features of Java include being simple, object-oriented, robust, secure, and portable. The Java runtime environment includes the Java virtual machine which executes Java bytecode. Common uses of Java include developing desktop and web applications, mobile apps, and embedded systems.
The document provides an agenda and introduction for a Java training over multiple days. Day 1 will cover an introduction to Java including its history, features, programming paradigm, sample program execution, JVM, data types, objects, classes, variables, and flow control statements. The training will cover key Java concepts like objects, classes, variables, different loops and conditional statements. Assignments are provided to practice the concepts covered.
The document provides an introduction and history of Java, outlining how it was developed in the 1990s as a platform-independent language by James Gosling at Sun Microsystems, and discusses some key advantages of Java like being object-oriented, portable, robust, and having built-in support for security and multithreading. It also describes the Java Development Kit (JDK) which contains tools for developing Java programs and the Java Runtime Environment (JRE) which allows running of Java applications and includes the Java Virtual Machine.
Java is an object-oriented programming language developed by James Gosling at Sun Microsystems in 1991. It derives much of its syntax from C and C++ but is designed to have as few implementation dependencies as possible so that applications written in Java can run on any device with a Java Virtual Machine (JVM). The JVM converts Java bytecode into machine code that can be executed by the device's processor. This allows Java programs to run on any platform that has a JVM without needing to be recompiled.
This document provides an overview of core Java concepts including:
- A brief history of Java's development from 1991 to today.
- Key Java features such as being object-oriented, platform independent, secure, and reliable.
- Object-oriented programming concepts in Java like classes, objects, inheritance, polymorphism.
- Common Java keywords, operators, data types, and variables.
- Additional topics covered include methods, inheritance, interfaces, exceptions, and strings.
This document provides an overview of variables and their scope in Java. It discusses the three types of variables in Java: local variables, instance variables, and class (static) variables.
Local variables are declared within methods, constructors, or blocks and can only be accessed within their declaration scope. Instance variables are declared within a class but outside of methods and can be accessed using an object reference. Class variables are declared with the static keyword, belong to the class itself rather than any object, and are accessed via the class name. The document provides examples and discusses default variable initialization.
This document provides an overview of the Java programming language and platform. It discusses Java's origins, characteristics, editions, and components like the JDK, JRE, and JVM. Java is introduced as a simple, secure, robust, and platform-independent language well-suited for client-server web applications and small devices. The document outlines Java's history and evolution from 1995 to present. Key aspects of Java like object-orientation, portability, and multi-threading are summarized.
Java is a widely used programming language that was created in 1991. It is an object-oriented language that is platform independent and runs on a virtual machine. Key features of Java include being simple, object-oriented, robust, secure, and portable. The Java runtime environment includes the Java virtual machine which executes Java bytecode. Common uses of Java include developing desktop and web applications, mobile apps, and embedded systems.
The document provides an agenda and introduction for a Java training over multiple days. Day 1 will cover an introduction to Java including its history, features, programming paradigm, sample program execution, JVM, data types, objects, classes, variables, and flow control statements. The training will cover key Java concepts like objects, classes, variables, different loops and conditional statements. Assignments are provided to practice the concepts covered.
The document provides an introduction and history of Java, outlining how it was developed in the 1990s as a platform-independent language by James Gosling at Sun Microsystems, and discusses some key advantages of Java like being object-oriented, portable, robust, and having built-in support for security and multithreading. It also describes the Java Development Kit (JDK) which contains tools for developing Java programs and the Java Runtime Environment (JRE) which allows running of Java applications and includes the Java Virtual Machine.
Java is an object-oriented programming language that is platform independent. It was developed by Sun Microsystems, now owned by Oracle. Java code is compiled into bytecode that runs on a Java Virtual Machine (JVM), allowing it to run on any device that supports a JVM. Java supports features like inheritance, polymorphism, and encapsulation. It is widely used for client-side applications like applets and server-side applications like servlets and Java Server Pages (JSP). The main Java editions are Java SE for desktop applications, Java EE for enterprise applications, and Java ME for mobile applications.
Java is an object-oriented programming language that is platform independent. It was developed by Sun Microsystems, now owned by Oracle. Java code is compiled into bytecode that runs on a Java Virtual Machine (JVM), allowing it to run on any device with a JVM. Java supports features like inheritance, polymorphism, and encapsulation. It is widely used for client-side applications like applets and server-side applications like servlets and Java Server Pages (JSP). The main Java editions are Java SE for desktop applications, Java EE for enterprise applications, and Java ME for mobile applications.
This document provides an overview of the Java programming language. It discusses what Java is, its platform independence, common applications, and key features such as being simple, object-oriented, robust, secure, portable, and high-performance. The document also covers Java variables, data types, operators, control statements, classes and objects, constructors, and static keywords. It provides examples of a first Java program and differences between JDK, JRE, and JVM.
The document provides an overview of the Java programming language, including its history, key characteristics, and major versions. It began as an object-oriented language created by Sun Microsystems in 1995 to control electronic devices. Java's main advantages are that it is simple, portable, robust, secure, high-performance, and can create distributed applications. It uses a virtual machine to run the same byte code on different operating systems. The document also discusses Java APIs, editions, and learning resources.
The document provides an overview of object-oriented programming in Java. It discusses that Java was created to be portable and platform independent due to issues with C/C++. It then covers the history and evolutions of Java, the different Java editions, and defines Java as a general-purpose, object-oriented language. The document compares Java to C/C++ by outlining features removed or added in Java. It also describes characteristics of Java like being simple, robust, secure, portable, and platform independent. Finally, it discusses the Java environment, an example Hello World program, input/output in Java, and primitive data types.
This document provides an introduction to Java programming concepts including:
1. Java was originally created by Sun Microsystems in 1991 for consumer electronics and later adapted for internet programming.
2. Java code is compiled to bytecode that can be run on any system with a Java Virtual Machine, making it platform independent.
3. Key characteristics of Java include being simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, multithreaded, and dynamic.
this slide contains about basic introduction of java.it will be helpful for a java beginner. it also useful for java lecture course in your versity.programming with java is very essential for every student.this silde may help you to progress your skill & lernt abc about java.
this slide is about java introductory.it will be helpful for you to know abc of jaba.it also be helpful for u in your versity java course.programming with java is very important for every student.java freshers can grabbed it easily
Java was developed by James Gosling at Sun Microsystems in 1991. It is a popular, object-oriented programming language that is robust, secure, portable, and high-performance. Java code is compiled to bytecode that runs on a Java Virtual Machine, allowing it to run on any platform. The document discusses Java naming conventions, data types, literals, and control statements. It also provides examples of Java code.
Java is an important programming language for three main reasons:
1) It allows for portability of programs across different operating systems and hardware with its write once, run anywhere capability.
2) The emergence of the World Wide Web in the 1990s demanded portable programs, which necessitated the invention of Java.
3) Java's portability and security features made it well-suited for developing applications for the web.
1. Java is a popular object-oriented programming language created by James Gosling at Sun Microsystems in 1991.
2. The Java Development Kit (JDK) provides tools for developing Java programs, and includes the Java Runtime Environment (JRE) which allows programs to run on any platform with a Java Virtual Machine (JVM).
3. Key features of Java include being platform independent, secure, robust, and multithreaded. Java code is compiled to bytecode that runs on a JVM, allowing the same code to run on different operating systems.
1. Java is a popular object-oriented programming language created by James Gosling at Sun Microsystems in 1991.
2. The Java Development Kit (JDK) provides tools for developing Java programs, and includes the Java Runtime Environment (JRE) which allows programs to run on various platforms.
3. The JRE contains the Java Virtual Machine (JVM) which interprets Java bytecode to execute programs consistently across different hardware and software environments.
Introduction To Java history, application, features.pptxsonalipatil225940
Java was developed by James Gosling at Sun Microsystems in 1995 and is now owned by Oracle. It is a high-level, robust, object-oriented programming language that can be used to create desktop applications, web applications, enterprise applications, mobile apps, and more. Some key features of Java include being platform independent, portable, secure, object-oriented, multithreaded, and robust. It supports distributed applications and is both compiled and interpreted.
The document discusses object oriented programming and Java. It provides a history of Java, describing how it was created at Sun Microsystems in the 1990s to be a simpler alternative to C++ that was architecture neutral, portable, distributed and secure. It then summarizes Java's key features including being object oriented, robust, simple, secure, portable and interpreted. It also describes Java's basic data types and how variables are declared and initialized in Java.
This document provides an overview of object-oriented programming and Java. It discusses the major programming paradigms including imperative, logical, functional and object-oriented. It then covers the key principles of object-oriented programming like encapsulation, inheritance, abstraction and polymorphism. The document also defines Java applications and applets and explains the processes of editing, compiling and interpreting Java code.
This document provides an introduction to Java programming. It outlines that Java is object-oriented, platform independent, strongly typed, and uses a compile and interpret process. It also notes that Java has an automatic garbage collector, supports multithreading, is secure by default, and provides robust exception handling. The document then briefly discusses how a Java program runs and the anatomy of Java before concluding with an overview of the main flavors of Java: J2SE for standalone apps, J2EE for enterprise apps, and J2ME for mobile apps.
Universal Java allows developers to write code once and run it anywhere, including on servers, desktops, mobiles, and IoT devices. Java code is portable because it compiles to bytecode that runs on the Java Virtual Machine (JVM), which exists for most platforms. Some key aspects that enable portability include:
1. Separating platform-independent business logic from platform-specific UI code
2. Using common language features and libraries for cross-platform code
3. Transpiling Java to other languages like JavaScript for web apps
4. Ahead-of-time compilation to native code for better performance on devices
The document discusses strategies for writing portable Java code and provides examples using shared business
The document provides an introduction to Java programming including:
- Java is an object-oriented language where programs are written as classes and allows "write once, run anywhere" functionality.
- Key features of Java include being simple, robust, secure, multi-threaded, and dynamically flexible.
- The Java architecture includes the compiler, JVM, JRE and JDK which work together to compile and execute Java code.
- Common Java applications include mobile apps, desktop apps, web apps, games, cloud apps, and IoT apps.
- A basic Java program structure includes documentation, packages, imports, classes, and a main method.
- The document provides an introduction to Java programming including an overview of Java, its history, platforms, architecture, components, applications, features, and setting up Java.
- It describes Java as a simple, general-purpose, object-oriented language that is architecture neutral, portable, robust and secure.
- The document outlines the key components of Java including the Java Virtual Machine (JVM), Java Runtime Environment (JRE), and Java Development Kit (JDK).
This document provides an overview of object-oriented programming concepts in Java including abstraction, encapsulation, inheritance, and polymorphism. It discusses key Java concepts like classes, objects, methods, and access specifiers. It also covers Java fundamentals like variables, data types, operators, control flow statements, comments, and arrays. Additionally, it describes the Java runtime environment, how to set up a Java development environment, compile and run a simple Java program. The document is intended as an introduction to object-oriented programming and the Java programming language.
Java is an object-oriented programming language that is platform independent. It was developed by Sun Microsystems, now owned by Oracle. Java code is compiled into bytecode that runs on a Java Virtual Machine (JVM), allowing it to run on any device that supports a JVM. Java supports features like inheritance, polymorphism, and encapsulation. It is widely used for client-side applications like applets and server-side applications like servlets and Java Server Pages (JSP). The main Java editions are Java SE for desktop applications, Java EE for enterprise applications, and Java ME for mobile applications.
Java is an object-oriented programming language that is platform independent. It was developed by Sun Microsystems, now owned by Oracle. Java code is compiled into bytecode that runs on a Java Virtual Machine (JVM), allowing it to run on any device with a JVM. Java supports features like inheritance, polymorphism, and encapsulation. It is widely used for client-side applications like applets and server-side applications like servlets and Java Server Pages (JSP). The main Java editions are Java SE for desktop applications, Java EE for enterprise applications, and Java ME for mobile applications.
This document provides an overview of the Java programming language. It discusses what Java is, its platform independence, common applications, and key features such as being simple, object-oriented, robust, secure, portable, and high-performance. The document also covers Java variables, data types, operators, control statements, classes and objects, constructors, and static keywords. It provides examples of a first Java program and differences between JDK, JRE, and JVM.
The document provides an overview of the Java programming language, including its history, key characteristics, and major versions. It began as an object-oriented language created by Sun Microsystems in 1995 to control electronic devices. Java's main advantages are that it is simple, portable, robust, secure, high-performance, and can create distributed applications. It uses a virtual machine to run the same byte code on different operating systems. The document also discusses Java APIs, editions, and learning resources.
The document provides an overview of object-oriented programming in Java. It discusses that Java was created to be portable and platform independent due to issues with C/C++. It then covers the history and evolutions of Java, the different Java editions, and defines Java as a general-purpose, object-oriented language. The document compares Java to C/C++ by outlining features removed or added in Java. It also describes characteristics of Java like being simple, robust, secure, portable, and platform independent. Finally, it discusses the Java environment, an example Hello World program, input/output in Java, and primitive data types.
This document provides an introduction to Java programming concepts including:
1. Java was originally created by Sun Microsystems in 1991 for consumer electronics and later adapted for internet programming.
2. Java code is compiled to bytecode that can be run on any system with a Java Virtual Machine, making it platform independent.
3. Key characteristics of Java include being simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, multithreaded, and dynamic.
this slide contains about basic introduction of java.it will be helpful for a java beginner. it also useful for java lecture course in your versity.programming with java is very essential for every student.this silde may help you to progress your skill & lernt abc about java.
this slide is about java introductory.it will be helpful for you to know abc of jaba.it also be helpful for u in your versity java course.programming with java is very important for every student.java freshers can grabbed it easily
Java was developed by James Gosling at Sun Microsystems in 1991. It is a popular, object-oriented programming language that is robust, secure, portable, and high-performance. Java code is compiled to bytecode that runs on a Java Virtual Machine, allowing it to run on any platform. The document discusses Java naming conventions, data types, literals, and control statements. It also provides examples of Java code.
Java is an important programming language for three main reasons:
1) It allows for portability of programs across different operating systems and hardware with its write once, run anywhere capability.
2) The emergence of the World Wide Web in the 1990s demanded portable programs, which necessitated the invention of Java.
3) Java's portability and security features made it well-suited for developing applications for the web.
1. Java is a popular object-oriented programming language created by James Gosling at Sun Microsystems in 1991.
2. The Java Development Kit (JDK) provides tools for developing Java programs, and includes the Java Runtime Environment (JRE) which allows programs to run on any platform with a Java Virtual Machine (JVM).
3. Key features of Java include being platform independent, secure, robust, and multithreaded. Java code is compiled to bytecode that runs on a JVM, allowing the same code to run on different operating systems.
1. Java is a popular object-oriented programming language created by James Gosling at Sun Microsystems in 1991.
2. The Java Development Kit (JDK) provides tools for developing Java programs, and includes the Java Runtime Environment (JRE) which allows programs to run on various platforms.
3. The JRE contains the Java Virtual Machine (JVM) which interprets Java bytecode to execute programs consistently across different hardware and software environments.
Introduction To Java history, application, features.pptxsonalipatil225940
Java was developed by James Gosling at Sun Microsystems in 1995 and is now owned by Oracle. It is a high-level, robust, object-oriented programming language that can be used to create desktop applications, web applications, enterprise applications, mobile apps, and more. Some key features of Java include being platform independent, portable, secure, object-oriented, multithreaded, and robust. It supports distributed applications and is both compiled and interpreted.
The document discusses object oriented programming and Java. It provides a history of Java, describing how it was created at Sun Microsystems in the 1990s to be a simpler alternative to C++ that was architecture neutral, portable, distributed and secure. It then summarizes Java's key features including being object oriented, robust, simple, secure, portable and interpreted. It also describes Java's basic data types and how variables are declared and initialized in Java.
This document provides an overview of object-oriented programming and Java. It discusses the major programming paradigms including imperative, logical, functional and object-oriented. It then covers the key principles of object-oriented programming like encapsulation, inheritance, abstraction and polymorphism. The document also defines Java applications and applets and explains the processes of editing, compiling and interpreting Java code.
This document provides an introduction to Java programming. It outlines that Java is object-oriented, platform independent, strongly typed, and uses a compile and interpret process. It also notes that Java has an automatic garbage collector, supports multithreading, is secure by default, and provides robust exception handling. The document then briefly discusses how a Java program runs and the anatomy of Java before concluding with an overview of the main flavors of Java: J2SE for standalone apps, J2EE for enterprise apps, and J2ME for mobile apps.
Universal Java allows developers to write code once and run it anywhere, including on servers, desktops, mobiles, and IoT devices. Java code is portable because it compiles to bytecode that runs on the Java Virtual Machine (JVM), which exists for most platforms. Some key aspects that enable portability include:
1. Separating platform-independent business logic from platform-specific UI code
2. Using common language features and libraries for cross-platform code
3. Transpiling Java to other languages like JavaScript for web apps
4. Ahead-of-time compilation to native code for better performance on devices
The document discusses strategies for writing portable Java code and provides examples using shared business
The document provides an introduction to Java programming including:
- Java is an object-oriented language where programs are written as classes and allows "write once, run anywhere" functionality.
- Key features of Java include being simple, robust, secure, multi-threaded, and dynamically flexible.
- The Java architecture includes the compiler, JVM, JRE and JDK which work together to compile and execute Java code.
- Common Java applications include mobile apps, desktop apps, web apps, games, cloud apps, and IoT apps.
- A basic Java program structure includes documentation, packages, imports, classes, and a main method.
- The document provides an introduction to Java programming including an overview of Java, its history, platforms, architecture, components, applications, features, and setting up Java.
- It describes Java as a simple, general-purpose, object-oriented language that is architecture neutral, portable, robust and secure.
- The document outlines the key components of Java including the Java Virtual Machine (JVM), Java Runtime Environment (JRE), and Java Development Kit (JDK).
This document provides an overview of object-oriented programming concepts in Java including abstraction, encapsulation, inheritance, and polymorphism. It discusses key Java concepts like classes, objects, methods, and access specifiers. It also covers Java fundamentals like variables, data types, operators, control flow statements, comments, and arrays. Additionally, it describes the Java runtime environment, how to set up a Java development environment, compile and run a simple Java program. The document is intended as an introduction to object-oriented programming and the Java programming language.
Similar to M251_Meeting 1(M251_Meeting 1_updated.pdf) (20)
The simplified electron and muon model, Oscillating Spacetime: The Foundation...RitikBhardwaj56
Discover the Simplified Electron and Muon Model: A New Wave-Based Approach to Understanding Particles delves into a groundbreaking theory that presents electrons and muons as rotating soliton waves within oscillating spacetime. Geared towards students, researchers, and science buffs, this book breaks down complex ideas into simple explanations. It covers topics such as electron waves, temporal dynamics, and the implications of this model on particle physics. With clear illustrations and easy-to-follow explanations, readers will gain a new outlook on the universe's fundamental nature.
it describes the bony anatomy including the femoral head , acetabulum, labrum . also discusses the capsule , ligaments . muscle that act on the hip joint and the range of motion are outlined. factors affecting hip joint stability and weight transmission through the joint are summarized.
Macroeconomics- Movie Location
This will be used as part of your Personal Professional Portfolio once graded.
Objective:
Prepare a presentation or a paper using research, basic comparative analysis, data organization and application of economic information. You will make an informed assessment of an economic climate outside of the United States to accomplish an entertainment industry objective.
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
How to Add Chatter in the odoo 17 ERP ModuleCeline George
In Odoo, the chatter is like a chat tool that helps you work together on records. You can leave notes and track things, making it easier to talk with your team and partners. Inside chatter, all communication history, activity, and changes will be displayed.
Main Java[All of the Base Concepts}.docxadhitya5119
This is part 1 of my Java Learning Journey. This Contains Custom methods, classes, constructors, packages, multithreading , try- catch block, finally block and more.
Azure Interview Questions and Answers PDF By ScholarHat
M251_Meeting 1(M251_Meeting 1_updated.pdf)
1. Meeting 1: Java Revision
Introduction to programming usingJava
Part 1
1
2. • Introduction
• Java background
• The system & Getting Java running
• Data types
• Statements and Scope and Operators
• Conditional processing
• Repetitive processing
2
3. 1. Introduction
• During the early daysof the internet, SunMicrosystems
introduced the Javalanguage, with great fanfare, in 1995.
Javaimmediately generated huge interest and excitement –
useof the language took off more rapidly than any computer
language before or since.
• Javais the language most identified with the internet and its
friendly face, theweb.
• Currently, Java is owned by Oracle.
• In this course, you will learn how Javaoriginated and how it is
usednowadays.
• you will learn the language used to build systemsthat power
somuch of the web inapplications ranging from e-commerce
to online games, downloadable music to online banking. 3
4. 1. Introduction
• Javaruns on servers, PCs,mobile phones and PDAs(personal
digital assistants).
• It canbe foundin
– TVset-topboxes,
– in embedded devices (forming part of larger systems suchascars,
robots or printers),
– in smart cards,and
– wearable computers.
Javareally is everywhere.
4
5. 2. Javabackground
The aims of the Java language
• Simple to learn, & Familiar and closely based on C++,but reduced in complexity.
• Object-oriented: java programs are structured aroundobjects
• Robust: Javaprograms are strictly checkedby software before theyrun
• Secure: Javaensures that programs running over networks cannot damageyour
computer files or introduceviruses.
• Portable: Javaprograms caneasily be transferred from one platform (e.g.
Windows) to run on another platform (e.g. Linux) with little or no change.
• High performance : Javaprograms canrun fast enough for whatis needed
• Interpreted: akey aspect of Javaportability.
• Threaded: allow aprogram todo several things at once.
• Dynamic: Javaprograms canadapt to changes in their environmenteven while
the program isrunning.
5
6. 2. Javabackground
Versions &Editions of Java
Versions of Java
• Thefirst publicly available version wasJava1.0.
• Now, Java2 is the standard language
– and there have been anumber of further versions (Java2 version 1.3,Java2
version 1.4, Java2 version 1.5 and soon), each introducing relatively minor
improvements
Editions of Java
• Why Javaeditions was introduced?
– tocater for the different needs of, say,large international business systems
to software running on mobile phones with very limited hardware
resources.
• Current editions:
• Java2 Standard Edition (J2SE) - focus of our study!
• Java2 Enterprise Edition (J2EE) - for large-scale systems
• Java2 Micro Edition (J2ME) - for mobile phones
6
8. 2. Javabackground
• Thefirst line of the program introduces aclass, calledHelloWalrus.
• When the program runs, the classgives rise to an object, which executes the code of the class.
• This classis defined aspublic, which means that objects ofthis classcan be freely accessed by
other objects in alargersystem.
• Thecurly bracket ‘{‘ on the line following HelloWalrus matches the closing bracket ‘}’ at the end
of the example, asthese enclose the whole classdefinition.
• The code in this classis in the form of a method, in this casea method called main.
• Thefirst line of the method is called the method header.
• Wedefer explaining the words static and void until later, but they are always used with main
methods like thisone.
• Themethod header defines the name of the method (in this case,main) and is followed by the
method body, which is enclosed in curly brackets.
• TheSystem.out.println method displays, in ascreen window, the exact text betweenthe
quotes.
• Eachof these two lines of code constitutes a statement, asingle command to be carried out.
• Eachstatement is terminated by asemicolon ‘;’.
8
9. 2. Javabackground
Using comments in Javaprograms
• Acomment is ignored by the computersystem
– Form 1: Block Comment. Textenclosed in the symbols /* and */
– Form 2: Line Comment or In-line Comment (using//)
• Line comment:
• In-line comment:
9
10. 3. The System & GettingJavarunning
Here we discuss the portability issue -> the way that programs written in
Java canbe run on many differentplatforms.
The conventional way
• source code is translated by acompiler to native
code (the baselanguage of the computer) which is
then executed.
• Thenative code that hasbeen generated can be
executed only by the particular type ofcomputer
that recognizesit.
In the case of Java
• source code is translated by acompiler to bytecode
(intermediate form) which is translated by an
interpreter into the native code of the computer it
runs on which is then executed.
• Theinterpreter is aprogram that translates
bytecode into the native code of the computer it
runs on
• Javainterpreters are available for many different
platforms.
10
11. 3. The System & GettingJavarunning
The JavaSoftware Development Kit (abbreviated asSDKorJDK)
• SDKtools are used for compiling and running Javaprograms on a
variety of platforms
• SDKtools are freely available from Oracle
• SDKtools include:
– TheJavacompiler (javac) translates Javasource into bytecode.
– TheJavainterpreter (java) translates and executes Javabytecode. Javainterpreters are
available for many different computersystems.
– Thedocument generator (javadoc) processes Javasource files to produceuseful
documentation, such asstandardized descriptions of components of Javacode.
– TheJavadebugger (jdb) helps to look for errors in programs.
– TheJavadisassembler (javap) reads bytecode files created using the Javacompiler
and displays the corresponding sourcecode.
– Theapplet viewer (appletviewer) allows you to run and debug Javaapplets without a
web browser (Javaapplets are explained in the nextslide)
11
12. 3. The System & GettingJavarunning
1. Javaprogrammers canproduce two types of software:
1. Applications are stand-alone programs, which can runindependently.
2. Applets are programs thatcan be included in web documents and are
run using abrowser.
2. Twowaysto develop and run Javasoftware:
– T
o useJavaSDK along with atext editor (mostly run fromcommand
line)
– T
ouse an Integrated Development Environment(IDE),
• IDEprovides asophisticated GUIand editor, with integrated facilities for
compiling, running and debuggingprograms.
• There are many IDEsavailable for Java,such as NetBeans and Eclipse.
12
13. • Introduction
• Java background
• The system & Getting Java running
• Data types
• Statements and Scope and Operators
• Conditional processing
13
14. 4. Datatypes
Strong typing
Javais astrongly typed language
– This means that every variable and expression has a type when the
program is compiled and that you cannot randomly assign values of
one type to another.
• There are two categories of data type in Java:
1. Primitive variables store datavalues.
2. Reference variables do not themselves store data values, butare
used to refer toobjects.
• Data type sizesin Javaare fixed
– to ensure portability across implementations of the language.
14
15. 4. Datatypes
Primitive DataTypes(Cont’d)
• Declaration and initialization:
we can reserve memory locations for storing values ofany primitive
type. Thosememory locations can then be made to contain values
that are legal for the particular type. This involves two steps.
1)Declaration: Create a variable of the type you want to use.
2)Initialization: This refers to when you first store something useful
in avariable's memorylocation.
Example:Declare two variables of type int and initialize them
int myInt;
int myOtherInt;
myInt =888;
myOtherInt =-2;
15
16. 4. Datatypes
Primitive DataTypes(Cont’d) –
• The integral types are called byte, short, int and long. All of these types are said
to be signed, meaning that they can hold positive or negative numbers. Eachhas
adifferent capacity with fixedsize.
16
18. 4. Datatypes
Primitive data types(Cont’d)
• Floating-point types: In order to represent numbers that may
include fractional parts, we use floating-point types. Thefloattype
has32 bits of spaceand double has64bits.
• Floating-point literals are denoted eitherby
– writing them asintegerpart.fractionalpart, asdouble x=23.8;
– using scientific notation, where the character e or E denotes
the fact that the number is to be multiplied by the power of
ten of the integer following the e orE,as
double y = 1.43E8, z = 1e-9;
18
20. 4. Datatypes
Casting
• There are occasions where we want to be able to convert from one type to
another. This canbe done either:
– Automatically: Javadoes it for usand knownaspromotion
– Bycasting: we have to specify atypeconversion.
• Bywriting the desired type of an expression in parentheses in front of the
expression; for example, write (int) in front of an expression if we wanted it to
be converted to anint.
– Note that the fractional parts of afloat data type are lost if casting to an
integral type. Becausevariables ofdifferent types occupy different amounts
of memory, this cancauseinformationloss
Ex.Casting a double to an int. Example: Casting an int toa char
c will have the value 60, which is the
61st character in the Unicode set. This
turns out to be the character '<'.
intVal will have the value of 2
20
21. 4. Datatypes
Casting(Cont’d)
• When is acast required?
– Acast is required if the type you are assigning (on the right-hand side of an
equals sign) occupies a larger spacein memory than the type you are
assigningto (on the left-hand side of an equals sign), or if you are trying to
assign (float or double) values to integral type.
– If you have not specified acast in acasewhere acast is required, the
compiler will produce a compilation error with the message that there is a
'possible loss of precision'.
21
22. 5. Statements and ScopeandOperators
Statements and Scope
• Astatement is aunit of executable code,usually
terminated by asemicolon.
• Codeblock includes agroup of statementsin
enclosed in curly brackets.
• Local variables: They are variables that are declared inside a code
block, and they are valid only inside the brackets. We say that the
variables' scope is the region enclosed by thebrackets
22
23. 5. Statements and ScopeandOperators
Operators
• All the primitive data types that are provided in Javaare associated with
sets of operators.
– EX.integers and floating-point types have addition and subtractionoperators.
• Operators canhave
– single arguments, in which casethey are known asunaryoperators;
– two arguments, in which casethey are known asbinaryoperators.
• Arithmetic operators: are used withfloating-point numbers and the various integral
types.All the standard arithmetic operations areavailable,
23
24. 5. Statements and ScopeandOperators
Operators
• The negation operator (-) unary operator
• The single argument for the negation operator appears to the right of the minus sign. It is
aprefix operator, which simply meansthat it appears before the value it takes asan
argument.
• Increment (++) and decrement (--)operators
• Thehave two forms: postfix andprefix
• The postfix returns the old value of the variable to which it is applied where as
the prefix form returns the new value.
• The ++operator increments the variable it is associated with by 1
• The -- operator decrements the variable it is associated with by 1
myInt would have the value 11
and x would have the value 10.
myInt would have the value 1 then 2
24
25. 5. Statements and ScopeandOperators
Operators
• Precedence of the arithmetic operators
• If an expression involves more than one operator, there is a clear order in which
operators are evaluated, determined by what is known asoperatorprecedence
3+4*5 evaluates to 23
• Weare deliberately not stating the precedence rules. Instead, you should ensure
aclear order of evaluation of an expression, using parentheses. Javawill
evaluate expressions in parenthesesfirst.
• 3+(4*5) evaluates to23
• (3+4) * 5 evaluates to 35
25
27. 5. Statements and ScopeandOperators
• Relational operators:
– Therelational operators tell you about relationships between values of thesametype.
– Their arguments can be integers, floating-point numbers, or characters. The'equal to'
and 'not equal to' operators can also be used with theboolean type
• An expression involving arelational operator is alogical expression, sohasa
boolean value either true of false . Evaluate the following expressions
1 <2
true !=false
0.5 >0.0
false ==false
2 ==2
'a' <'c‘
27
29. 5. Statements and ScopeandOperators
• Logical operators:
• Are used when we want to combine the results from several logical expressions
• Thearguments for alogical operator must be logicalexpressions.
Example:
• Thevariable eitherPositive is assignedthe value true, because a>0 is true and
therefore the whole expression is true (even though b >0 is false).
• Thevariable bothNegative is assignedthe value false because a<0 is false, and
• therefore the whole expression is false. Eventhough b<0 is true.
29
30. 6. Conditional processing
The boolean type
• Theflow control structures determine the way in which aJavaprogram is
executed, allowing different segments of code to be executed under different
circumstances.
• Conditional processing and Repetitive processing
• In Conditional processing (The Selection statements) give uswaysofspecifying
the conditions for changing the flow of control in aprogram.
• Variables of the boolean type can hold either the literal value true or false,
which are keywords in the Javalanguage.
• Theexpression that evaluates to aboolean value named alogicalexpression.
• Javadefines anumber of relational operators for booleantypes:
–Relational operators and Logical operators
Theif statement
•Thegeneral form of the firstconditional
processing statement is shownhere 30
31. 6. Conditional processing
Theif statement
• If the logical_expression within the parentheses
evaluates to true, then any statements in the following code block are executed.
• If the logical_expression is false, then any statements in the body of the if
statement are not executed.
• An if statement may cover several lines of code, (but it is just one statement ).
Asis usual when astatement hasabody in curly brackets, there is nosemicolon
at its end.
• It is better style to use curly brackets { }, to demarcate clearly the body of the
if statement .
• Thestyle of writing Javaprograms that includes indentation to indicate the
structure of a program. Indentation aids readability of code, but does not affect
the way the compiler interpretsit.
Variables of type boolean and ifstatements
• Aboolean variable is used when we want to store information about the truth
or falsity of some part of our program
31
32. 6. Conditional processing
The if ... else statement
•There is a more complicated form of
the statement that allows us to specify
code to be processed when thelogical
condition is false in addition to code to be processed when it is true.
– statementsA are executed if the logical_expression is true and
statementsB are executed if the expression isfalse.
•Example:
32
33. 6. Conditional processing
Nesting if statements
• Wecan write if statements within if statements, which we call nesting.An
example of this is shownbelow:
• Example:
Seethe advantage of using anindentation
style: the structure of the two if
statements is displayed and it becomes
clear which statements are going to be
executed when either of the twological expressions is true.
33
34. 6. Conditional processing
The switch ... case statement
Theargument is an expression of type int,char, short
or byte (usually just the name of a variable).
Eachselector is aconstant value (usually a literal)
compatible with the argumenttype.
Acode block enclosing the statements in eachcaseis
optional.
Thestatements are performed if the caseselector is
logically equal to the argument ; in other words, if
argument ==selector.
The break keyword causes the switch to terminate.
Failure to use a break statement results in control
'falling through' to the nextcase.
Adefault casemay be given to indicate processingto
take place when no selector ismatched.
34
36. 6. Conditional processing
The switch ... case statement Example:
for (inti=0; i<=10; i++){
switch ( i ){
case1: System.out.print("one ");
case2: System.out.print("two ");
case3: System.out.print("three "); break;
case4:
case5: System.out.print("four &five"); break;
case6: System.out.print("six"); break;
case7: System.out.print("seven ");
case8: System.out.print("eight ");break;
default: System.out.print("Not in the list");
}// switch
S
ystem.out.println();
}// for
Not in thelist
one two three
two three
three
four & five
four & five
six
seveneight
eight
Not in thelist
Not in thelist
36
37. 7. Repetitive processing
• Javaallow sections of code tobe executed repeatedly while
some condition is satisfied € iteration!
7.1 - The while statement
Meaning: While the logical_expression is true, the statements are executed. Thetruth of
the logical_expression is rechecked after each execution of the body of the while.
Example:
37
39. 7. Repetitive processing
7.2- The for statement
Meaning: Thecontrol variable is created and given its initial value in control_initializer. Next, the
logical_expression determines if the loop body is executed.After each time the statements are
executed, control_adjustment defines the new value of the control variable, and the
logical_expression is checked again. Theloop terminates when the logical_expression becomesfalse.
Note: The control_initializer is only executed once and is the first statement to be executed by the for.
Examples:
This sets all elements
of a[] to 10
Can you figure out how
this loop is executed??
39