This document covers fundamentals of Java syntax, errors, and debugging. It discusses Java language elements like variables, data types, expressions, and methods. It also describes different types of errors like syntax errors and logic errors. Finally, it discusses graphics and GUIs, including drawing shapes and text using a coordinate system.
CIS 1403 lab 3 functions and methods in JavaHamad Odhabi
This lab discusses and provides examples of both built-in and user-defined functions. In Java function are referred to as methods. Therefore, in the rest of this lab, the term methods will be used to refer to functions. The lab will cover the type of methods, naming of functions, the scope of variables and recursion.
The skeletal implementation pattern is a software design pattern consisting of defining an abstract class that provides a partial interface implementation. However, since Java allows only single class inheritance, if implementers decide to extend a skeletal implementation, they will not be allowed to extend any other class. Also, discovering the skeletal implementation may require a global analysis.
Java 8 enhanced interfaces alleviate these problems by allowing interfaces to contain (default) method implementations, which implementers inherit. Java classes are then free to extend a different class, and a separate abstract class is no longer needed; developers considering implementing an interface need only examine the interface itself.
In this talk, I will argue that both these benefits improve software modularity, and I will discuss our ongoing work in developing an automated refactoring tool that would assist developers in taking advantage of the enhanced interface feature for their legacy Java software.
Raffi Khatchadourian is an Assistant Professor in the Department of Computer Systems Technology (CST) at New York City College of Technology (NYCCT) of the City University of New York (CUNY) and an Open Educational Resources (OER) Fellow for the Spring 2016 semester. His research is centered on techniques for automated software evolution, particularly those related to automated refactoring and source code recommendation systems. His goal is to ease the burden associated with correctly and efficiently evolving large and complex software by providing automated tools that can be easily used by developers.
Raffi received his MS and PhD degrees in Computer Science from Ohio State University and his BS degree in Computer Science from Monmouth University in New Jersey. Prior to joining City Tech, he was a Software Engineer at Apple, Inc. in Cupertino, California, where he worked on Digital Rights Management (DRM) for iTunes, iBooks, and the App store. He also developed distributed software that tested various features of iPhones, iPads, and iPods.
Ideal for learning the basics of java, and can also be used as a school project for class 10 and 12. The document contains illustrative pictures, and carefully selected information to make the basics of java strong. Pls ignore small spelling mistakes made.
Let's explore some other fundamental programming concepts
Chapter 2 focuses on:
character strings
primitive data
the declaration and use of variables
expressions and operator precedence
data conversions
Object Oriented Programming Lab Manual Abdul Hannan
Object oriented programing Lab manual for practicing and improve the coding skills of object oriented programming.
Published by Mohammad Ali Jinnah University Islamabad.
Introducing to data types, identifiers, variable declarations, constants, comments, program output, and simple arithmetic operations, and the conventions of programming style and console input with the Scanner class and with dialog boxes using JOptionPane.
Md Mofijul Haque
Student
Infrastructure University Kuala Lumpur.
In this page, we will learn about the basics of OOPs. Object-Oriented Program...Indu32
In this page, we will learn about the basics of OOPs. Object-Oriented Programming is a paradigm that provides many concepts, such as inheritance, data binding, polymorphism, etc.
CIS 1403 lab 3 functions and methods in JavaHamad Odhabi
This lab discusses and provides examples of both built-in and user-defined functions. In Java function are referred to as methods. Therefore, in the rest of this lab, the term methods will be used to refer to functions. The lab will cover the type of methods, naming of functions, the scope of variables and recursion.
The skeletal implementation pattern is a software design pattern consisting of defining an abstract class that provides a partial interface implementation. However, since Java allows only single class inheritance, if implementers decide to extend a skeletal implementation, they will not be allowed to extend any other class. Also, discovering the skeletal implementation may require a global analysis.
Java 8 enhanced interfaces alleviate these problems by allowing interfaces to contain (default) method implementations, which implementers inherit. Java classes are then free to extend a different class, and a separate abstract class is no longer needed; developers considering implementing an interface need only examine the interface itself.
In this talk, I will argue that both these benefits improve software modularity, and I will discuss our ongoing work in developing an automated refactoring tool that would assist developers in taking advantage of the enhanced interface feature for their legacy Java software.
Raffi Khatchadourian is an Assistant Professor in the Department of Computer Systems Technology (CST) at New York City College of Technology (NYCCT) of the City University of New York (CUNY) and an Open Educational Resources (OER) Fellow for the Spring 2016 semester. His research is centered on techniques for automated software evolution, particularly those related to automated refactoring and source code recommendation systems. His goal is to ease the burden associated with correctly and efficiently evolving large and complex software by providing automated tools that can be easily used by developers.
Raffi received his MS and PhD degrees in Computer Science from Ohio State University and his BS degree in Computer Science from Monmouth University in New Jersey. Prior to joining City Tech, he was a Software Engineer at Apple, Inc. in Cupertino, California, where he worked on Digital Rights Management (DRM) for iTunes, iBooks, and the App store. He also developed distributed software that tested various features of iPhones, iPads, and iPods.
Ideal for learning the basics of java, and can also be used as a school project for class 10 and 12. The document contains illustrative pictures, and carefully selected information to make the basics of java strong. Pls ignore small spelling mistakes made.
Let's explore some other fundamental programming concepts
Chapter 2 focuses on:
character strings
primitive data
the declaration and use of variables
expressions and operator precedence
data conversions
Object Oriented Programming Lab Manual Abdul Hannan
Object oriented programing Lab manual for practicing and improve the coding skills of object oriented programming.
Published by Mohammad Ali Jinnah University Islamabad.
Introducing to data types, identifiers, variable declarations, constants, comments, program output, and simple arithmetic operations, and the conventions of programming style and console input with the Scanner class and with dialog boxes using JOptionPane.
Md Mofijul Haque
Student
Infrastructure University Kuala Lumpur.
In this page, we will learn about the basics of OOPs. Object-Oriented Program...Indu32
In this page, we will learn about the basics of OOPs. Object-Oriented Programming is a paradigm that provides many concepts, such as inheritance, data binding, polymorphism, etc.
The basics of the Java programming language. This is the first Powerpoint Richard Styner used when teaching AP Computer science. It is all the basics to begin learning how to program, just the background.
A project I did during my masters program at CSU Fullerton where I mentored a veteran teacher to help her introduce student blogging into her classroom, by Richard Styner
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
Normal Labour/ Stages of Labour/ Mechanism of LabourWasim Ak
Normal labor is also termed spontaneous labor, defined as the natural physiological process through which the fetus, placenta, and membranes are expelled from the uterus through the birth canal at term (37 to 42 weeks
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
This slide is special for master students (MIBS & MIFB) in UUM. Also useful for readers who are interested in the topic of contemporary Islamic banking.
Introduction to AI for Nonprofits with Tapp NetworkTechSoup
Dive into the world of AI! Experts Jon Hill and Tareq Monaur will guide you through AI's role in enhancing nonprofit websites and basic marketing strategies, making it easy to understand and apply.
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...Levi Shapiro
Letter from the Congress of the United States regarding Anti-Semitism sent June 3rd to MIT President Sally Kornbluth, MIT Corp Chair, Mark Gorenberg
Dear Dr. Kornbluth and Mr. Gorenberg,
The US House of Representatives is deeply concerned by ongoing and pervasive acts of antisemitic
harassment and intimidation at the Massachusetts Institute of Technology (MIT). Failing to act decisively to ensure a safe learning environment for all students would be a grave dereliction of your responsibilities as President of MIT and Chair of the MIT Corporation.
This Congress will not stand idly by and allow an environment hostile to Jewish students to persist. The House believes that your institution is in violation of Title VI of the Civil Rights Act, and the inability or
unwillingness to rectify this violation through action requires accountability.
Postsecondary education is a unique opportunity for students to learn and have their ideas and beliefs challenged. However, universities receiving hundreds of millions of federal funds annually have denied
students that opportunity and have been hijacked to become venues for the promotion of terrorism, antisemitic harassment and intimidation, unlawful encampments, and in some cases, assaults and riots.
The House of Representatives will not countenance the use of federal funds to indoctrinate students into hateful, antisemitic, anti-American supporters of terrorism. Investigations into campus antisemitism by the Committee on Education and the Workforce and the Committee on Ways and Means have been expanded into a Congress-wide probe across all relevant jurisdictions to address this national crisis. The undersigned Committees will conduct oversight into the use of federal funds at MIT and its learning environment under authorities granted to each Committee.
• The Committee on Education and the Workforce has been investigating your institution since December 7, 2023. The Committee has broad jurisdiction over postsecondary education, including its compliance with Title VI of the Civil Rights Act, campus safety concerns over disruptions to the learning environment, and the awarding of federal student aid under the Higher Education Act.
• The Committee on Oversight and Accountability is investigating the sources of funding and other support flowing to groups espousing pro-Hamas propaganda and engaged in antisemitic harassment and intimidation of students. The Committee on Oversight and Accountability is the principal oversight committee of the US House of Representatives and has broad authority to investigate “any matter” at “any time” under House Rule X.
• The Committee on Ways and Means has been investigating several universities since November 15, 2023, when the Committee held a hearing entitled From Ivory Towers to Dark Corners: Investigating the Nexus Between Antisemitism, Tax-Exempt Universities, and Terror Financing. The Committee followed the hearing with letters to those institutions on January 10, 202
2. Fundamentals of Java
2
Objectives
Construct and use numeric and string literals.
Name and use variables and constants.
Create arithmetic expressions.
Understand the precedence of different
arithmetic operators.
Concatenate two strings or a number and a
string.
3. Fundamentals of Java
3
Objectives (cont.)
Know how and when to use comments in a
program.
Tell the difference between syntax errors,
run-time errors, and logic errors.
Insert output statements to debug a program.
4. Fundamentals of Java
4
Objectives (cont.)
Understand the difference between Cartesian
coordinates and screen coordinates.
Work with color and text properties.
8. Fundamentals of Java
8
Language Elements
Every language, including Java has:
– Vocabulary: Set of all of the words and
symbols in the language
– Syntax: Rules for combining words into
sentences (statements)
– Semantics: Rules for interpreting the meaning
of statements
10. Fundamentals of Java
10
Language Elements (cont.)
Programming vs. natural languages
– Programming languages have small
vocabularies and simple syntax and semantics.
– Programming language syntax must be
absolutely correct.
– Programming language statements are
interpreted literally.
Every detail must be present.
11. Fundamentals of Java
11
Basic Java Syntax and Semantics
Two categories of data types:
– 1. Primitive data types: Numbers, characters,
and Booleans
– 2. Objects
Syntax for manipulating primitive data types
differs than for objects
– Primitive data types are combined in expressions
with operators.
– Objects are sent messages.
12. Fundamentals of Java
12
Basic Java Syntax and
Semantics (cont.)
Objects must be instantiated before use.
– Unlike primitives
– String objects are a little different.
Six numeric data types
– int and double are most commonly used
Also short, long, byte, and float
– Each uses a different number of bytes for
storage.
Each represents a different range of values.
14. Fundamentals of Java
14
Basic Java Syntax and
Semantics (cont.)
Literals: Items whose values do not change.
– The number 5.0 or the string “Java”
Variable is a named location in memory.
– Changing a variable’s value is equivalent to
replacing the value at the memory location.
– A variable’s data type cannot change.
16. Fundamentals of Java
16
Basic Java Syntax and
Semantics (cont.)
Variable declaration statement: Declares
the identifier and data type for a variable
– int age; (declares one int variable)
– int a, b, c; (declares three int variables)
– double d = 2.45; (declares and initializes
a variable)
Constants are variables whose value cannot
change.
– final double PI = 3.14;
17. Fundamentals of Java
17
Basic Java Syntax and
Semantics (cont.)
Assignment statements:
– <variable> = <expression>;
– Value of expression assigned to variable
Arithmetic expressions:
– Multiplication and division have higher
precedence than addition and subtraction.
– Operators of same precedence evaluated from
left to right.
– Parentheses are used to change evaluation order.
19. Fundamentals of Java
19
Basic Java Syntax and
Semantics (cont.)
The semantics of division (/) differ for
integers and floating-point operators.
– int / int yields an int.
– double / double yields a double.
The modulus operator (%) yields a remainder.
– 11 % 3 yields 2.
21. Fundamentals of Java
21
Basic Java Syntax and
Semantics (cont.)
Arithmetic overflow: Assigning a value to a
variable that is outside of the ranges of
values that the data type can represent
Mixed-mode arithmetic: Expressions
involving integer and floating-point values
– Lower-precision data types (int) temporarily
converted to high-precision data types
(double)
22. Fundamentals of Java
22
Basic Java Syntax and
Semantics (cont.)
Type casting: Temporarily converting one
data type to another
– Can type cast a single variable or an entire
expression
– Place the desired data type within parentheses
before the variable or expression that will be
cast to another data type.
int x = (int)(d + 1.6);
23. Fundamentals of Java
23
Basic Java Syntax and
Semantics (cont.)
String concatenation: Append a String
or value to another String
– Use the + operator
– String s = “string1” + “string2”;
– String s2 = “String1” + intVariable1;
Escape character (): Used in codes to
represent characters that cannot be directly
typed into a program
– “t” is a tab character
24. Fundamentals of Java
24
Basic Java Syntax and
Semantics (cont.)
The String class’s length method gives
the number of characters in a String.
Classes implement methods, and objects are
instances of classes.
– Objects can respond to a message only if their
class implements the method.
Must implement a method with a matching
signature
25. Fundamentals of Java
25
Basic Java Syntax and
Semantics (cont.)
Method signature:
– Method name
– Number and data types of method parameters
Method and variable names are user
defined symbols.
– Cannot use Java keywords (reserved words)
Packages: Used to organize related classes
into a single unit for distribution
29. Fundamentals of Java
29
Comments
Explanatory sentences inserted in a program
Compiler ignores them
Purpose is to make program more readable
Two varieties:
– End of line comments: All text following a
double slash (//) on a single line
– Multiline comments: All text occurring
between a /* and a */
30. Fundamentals of Java
30
Comments (cont.)
Typical uses of comments:
– Begin a program with a statement of its purpose
– Explain the purpose of a variable declaration
– Explain the purpose of a major segment of code
– Explain the workings of complex or tricky
sections of code
31. Fundamentals of Java
31
Programming Errors
Three types of programming errors:
– Syntax errors: When a syntax rule is violated
Detected during compilation
Compiler helps identify error
– Run-time errors: Occurs during execution
Dividing by 0
Detected when program runs
JVM indicates type of error and location
32. Fundamentals of Java
32
Programming Errors (cont.)
Three types of programming errors (cont.):
– Logic errors (design errors or bugs):
Incorrect logic implemented in the program
Code may be correct in every other way, but
does not do what it is supposed to do.
Must thoroughly test and debug the program
when an error is found.
– Desk checking: Examine code immediately after
it is written
33. Fundamentals of Java
33
Debugging
One debugging method is to add extra lines
of code to print values of selected variables
at strategic points in the program.
34. Fundamentals of Java
34
Graphics and GUIs: Drawing
Shapes and Text
Defining a specialized graphics panel: Define
a new class that extends the JPanel class
– Inherits all of the properties and methods of a
JPanel, but can add additional instance
variables and methods
36. Fundamentals of Java
36
Graphics and GUIs: Drawing
Shapes and Text (cont.)
Every graphics application uses a
coordinate system.
– Positions of items on a window specified in
terms of two-dimensional points
– Java uses the screen coordinate system:
The origin (point with coordinates (0,0)) located
at upper-left corner of a panel or frame
Every window, frame, or other type of window
has own coordinate system
38. Fundamentals of Java
38
Graphics and GUIs: Drawing
Shapes and Text (cont.)
Graphics class: Used to draw on a panel
– Every panel maintains an instance of this class.
The graphics context
– Shapes drawn on a panel by the Graphics
class have a foreground color.
Change color via the setColor() method.
40. Fundamentals of Java
40
Graphics and GUIs: Drawing
Shapes and Text (cont.)
Table 3-9: Common method in the Graphics class (cont.)
41. Fundamentals of Java
41
Graphics and GUIs: Drawing
Shapes and Text (cont.)
Table 3-9: Common method in the Graphics class (cont.)
42. Fundamentals of Java
42
Graphics and GUIs: Drawing
Shapes and Text (cont.)
Every panel instance has a
paintComponent() method
– Called by the JVM when the panel needs to be
drawn on the screen
– Contains instructions for how to draw the panel
– For custom panels, can write own
paintComponent() method, but must also
call the superclass’s paintComponent()
method
43. Fundamentals of Java
43
Graphics and GUIs: Drawing
Shapes and Text (cont.)
Example 3.6: Colored panel containing a
red text message in a blue rectangle
45. Fundamentals of Java
45
Graphics and GUIs: Drawing
Shapes and Text (cont.)
The width and height of a panel can be found
using the getWidth() and getHeight()
methods, respectively.
Font class: Information about a specific font
– Font name, size, and style
– Font font = new Font(“Arial”,
Font.BOLD, 10);
46. Fundamentals of Java
46
Summary
Use the int data type for whole numbers
and double for floating-point numbers.
Variable and method names consist of a
letter followed by additional letters or digits.
Keywords cannot be used as names.
Final variables behave as constants; their
values cannot change after they are
declared.
47. Fundamentals of Java
47
Summary (cont.)
Arithmetic expressions are evaluated
according to precedence.
Some expressions yield different results for
integer and floating-point operands.
Strings may be concatenated.
The compiler catches syntax errors.
The JVM catches run-time errors.
48. Fundamentals of Java
48
Summary (cont.)
Logic errors, if caught, are detected by the
programmer or user at run-time.
Can find and remove logic errors by inserting
debugging output statements to view the
values of variables.
The programmer can modify the color with
which images are drawn and the properties
of text fonts for a given graphics object.
49. Fundamentals of Java
49
Summary (cont.)
Java uses a screen coordinate system to
locate the positions of pixels in a window or
panel.
– Origin is the upper-left corner of the drawing
area.
– x and y axes increase to the right and
downward.