Library Home

Introduction to Programming Using Java - Eighth Edition

(6 reviews)

introduction to java programming assignments

David J. Eck, Hobart and William Smith Colleges

Copyright Year: 2015

Publisher: David J. Eck

Language: English

Formats Available

Conditions of use.

Attribution-NonCommercial-ShareAlike

Learn more about reviews.

Reviewed by Tanvir Irfan Chowdhury, Assistant Professor, Marshall University on 2/1/24

This book covers all the essential topics in Java development. It is not just for beginners; experienced programmers can also review the chapters for a quick reference. It can be used both as an introductory programming class using Java and also... read more

Comprehensiveness rating: 5 see less

This book covers all the essential topics in Java development. It is not just for beginners; experienced programmers can also review the chapters for a quick reference. It can be used both as an introductory programming class using Java and also as upper level class that covers GUI programming using Java.

Content Accuracy rating: 5

I haven't seen any example with an obvious error. Having the source code available online for practice is a nice feature.

Relevance/Longevity rating: 5

Java is updated regularly. Although it is hard to keep up with the updates, I still think the book is using a fairly new version of Java. The reader will not miss much with the used version and if they want to learn the latest version, they can do it easily.

Clarity rating: 4

The book is easy to follow and flows naturally from beginning to end. It introduces various concepts not generally seen in a programming language book, such as section 8.5, Analysis of Algorithms. While I appreciate the author's initiative, the example used in the first paragraph is rather exaggerated/dramatic ("..correct answer after ten thousand years...").

Consistency rating: 5

The book uses consistent terminology throughout. All the codes/code segments were formatted using the same style. While the authors provided an explanation for using the term "subroutine" in chapter 4, I personally still think using the name "method" would be more beneficial for the reader.

Modularity rating: 5

The book's modularity enables instructors of introductory Java programming courses to teach with ease. Instructors have the flexibility to select essential chapters while reserving more advanced topics for students at higher levels of proficiency.

Organization/Structure/Flow rating: 5

The book is organized in a logical fashion.

Interface rating: 5

Navigating the book is incredibly straightforward. The website provides various options such as online access, PDF downloads, and other convenient methods to explore its contents.

Grammatical Errors rating: 5

I did not notice any obvious grammatical errors in my reading.

Cultural Relevance rating: 5

While, I do not see examples of the inclusion of various races, ethnicities, and backgrounds. The most important thing is I also did not see any insensitive, or offensive content either. For the subject matter, I believe the book is perfectly fine.

Reviewed by Zhenguang Gao, Professor, Framingham State University on 6/15/21

The book covers all parts needed for a freshman course. It is can be used as one semester or one year book for Java programming. read more

The book covers all parts needed for a freshman course. It is can be used as one semester or one year book for Java programming.

The syntax explanations are precise. The Java examples are error free.

Relevance/Longevity rating: 4

The book doesn't use the most recent version of Java Environment. However, I do not think that is a problem. Beginners do not need the up-to-date new syntax to do well in a problem solving course.

Clarity rating: 5

The book is very concise, and easy to follow.

The book is very well organized in style. Similar formats are used from the beginning to the end.

Modularity rating: 4

The book follows the standard modularity for a first programming course. It begins with an introduction to computation, then followed by Java basics. It is a great book for a fast paced course. However, for some schools with a slow paced programming course, covering more basic programming skills and more examples could improve the learning experience.

Organization/Structure/Flow rating: 4

I feel the book should cover the basics in more details and more examples. The order of the some topics are not conventional. For example, "if" structure is covered after the looping structures; and programming environment is in the last section of Chapter 2, not in the first section.

The book is very easy to use. The website offers online, PDF, and other ways to navigate.

I do not see any grammatical errors.

Cultural Relevance rating: 4

The book doesn't not make use of a lot of examples relevant to races, ethnicity, or diversity. However, I did not see any culturally insensitive, or offensive content.

I'd recommend the book for any one looking for a first year programming course.

Reviewed by Eric Jiang, Professor, University of San Diego on 4/18/21

This book is quite comprehensive and it provides all foundational topics for beginners to learn the Java programming language. In addition, it offers a nice overview of Java programming environments and includes chapters on graphical user... read more

This book is quite comprehensive and it provides all foundational topics for beginners to learn the Java programming language. In addition, it offers a nice overview of Java programming environments and includes chapters on graphical user interfaces and programming with multi-threading. The book is suitable for a typical first programming course in Java and some of the book’s material can also be used for a subsequent programming course.

I did not find any technical errors or inaccuracies in the book.

The current 8th edition of the book is based on Java 8 and it uses JavaFX for GUI programming, so the book’s content is quite up-to-date. Of course, as more features are periodically added to the Java language, the book will need to be revised accordingly.

The book is extremely well-written and easy to follow. In fact, the author uses a conversational writing style and provides clear explanations of concepts and principles throughout the book. All of these make it a good text book for beginners.

The author uses consistent terminology internally. But the term “subroutine” introduced in the book would not be consistent with other Java sources including Oracle’s Java Documentation where the term “method” is used. This external term inconsistency may cause some confusions to readers.

The book is generally modular. One could cluster and rearrange some of its chapters or sections to fit an intro to Java class. However, the book’s modularity could be further enhanced by re-organizing its coverage of some topics. For instance, it would be good to separate the section on recursion from linked data structures and to consider expanding it to a chapter because the recursion concept and recursive algorithms are usually difficult to comprehend for many beginners.

The author does a good job presenting the material in a logical manner. The book starts basic language constructs and then covers methods, program design, classes, arrays and some more advanced topics. At the end of each chapter, it also includes programming exercises and quizzes. One suggestion I have for book’s organization is to delay the coverage of some class related topics including inheritance, polymorphism and interfaces to a later chapter. In addition, the coverage on data structures (stacks, queues and binary trees) may be expanded so the book could also be used in a second programming course in Java.

Interface rating: 4

The book’s interface is good and it is quite easy to navigate all book components. However, I feel the interface could be improved by adding a glossary and also an index.

This is a very well-edited book.

All examples and exercises from the book are very good and they are not culturally insensitive.

Overall, this is a great book for introducing Java programming. It has a very decent coverage of all important foundational topics and provides clear explanations and nice examples and exercises. Plus, it is freely accessible.

I will definitely consider using the book in some of my future classes.

Reviewed by Joey Cho, Professor, Colorado State University - Pueblo on 12/24/19

The book covers all important and necessary topics for beginners in 13 chapters. read more

The book covers all important and necessary topics for beginners in 13 chapters.

The content is very accurate but here's minor things: 1. On page 14, the word "but" was typed twice (...but but has recently been removed...) 2. In section 10.1.4, the abbreviation for Java Collection Framework should be JCF not JFC.

Content is very fresh with a full of good examples and exercises. The previous version describes Swing libraries for the graphical user interface but the current version describes the up-to-date JavaFX.

The text was written with very easy words and explains concepts clearly with appropriate examples and pictures.

The text has a very good flow with a consistent jargon and framework. For example, in section 3.8, the concept of Arrays is introduced and explained later in detail in chapter 7. Also, the GUI programming is introduced in section 3.9 as an appetizer and described fully in chapter 6 and 13 with consistency.

The text is consisted of 13 chapters and many sub sections to facilitate any instructor/user to reconstruct/reorganize the content without any difficulties.

The essential topics of Java programming are organized in a way for beginners to read and study easily.

Any interface issues are found. The PDF file that can be downloaded from the open book site provides bookmark links to specific topics of interest, and the table of contents are hyperlinked. Also, all of the name of example code listed in the text have a link to actual code.

No grammatical errors are found.

The text is full of good examples and exercises without having any bias culturally and ethnically.

The introduction to the Conway’s Game of Life and the Checkers in chapter 7, and the Towers of Hanoi and the Blob Counting in chapter 8 are very useful examples for students who are interested in game programming. Also, 3 network programming examples (a simple chat room, a networked Tic-tac-toe game, and a networked Poker game) in section 12.5 could attract a lot of student's attention.

In section 6.1.3, when a BorderPane is explained, it would be good to show a picture of a BorderPane of the 5 section as shown in section 6.5.2 or place a link to that section.

Reviewed by John McManus, Assistant Professor, Randolph-Macon College on 3/27/18

This textbook is comprehensive. It covers a significant amount of material in a well-thought out and logical manner. The text starts with basic programming concepts introducing variables, types and input and output. The author covers the basics... read more

This textbook is comprehensive. It covers a significant amount of material in a well-thought out and logical manner. The text starts with basic programming concepts introducing variables, types and input and output. The author covers the basics of a variety of programming environments including Eclipse, NetBeans, and the command line environment. The next section introduces control structures, exception handling, and introduces arrays and GUI programming. The early introduction of arrays and GUI program is a nice feature, allow students to add address slightly more complex problems. The book introduces objects and classes late, allowing introductory students to focus on syntax and basic problem solving before adding objects. I believe the text is well suited to a two-semester introductory sequence, or an upper level Software Design Course. The text includes quizzes at the end of each chapter, as well as programming exercises.

I did not see any technical errors or inaccuracies in the book.

The book uses the Swing library used to build GUI applications. Swing has been replaced with JavaFX. Swing is still widely used and okay for an introductory courses; the text should be updated to cover JavaFX.

The author uses an easy to read, conversational writing style and provides very thorough explanations. The flow is very logical, with sections building on the prior section.

The author uses consistent, and for the most part, modern terminology. The use of “subroutine” can be a confusing to students. The more correct term “methods” is also used and it’s not clear why “subroutines” is introduced. I appreciate the use of JavaDoc.

The text is as modular, and the order that the modules are introduced in is very logical. It is possible to re-order the modules to match your preferences for introducing specific topics.

I like the organization of the book for an introductory course, and for a course on software design. approach. Objects and classes are covered in chapter five, after the basic programming building blocks such as control structures and methods have been covered. This allows you to choose the depth that you cover topics, going slower in an introductory class, but faster in a course on Software design. I would recommend moving some sections around. I like to introduce arrays early, and I defer exceptions until a bit later.

I did not find any interface issues. The text includes PDF links in the table of contents, and also when the text makes a reference to another section. The author also includes links to the full code examples on the book's web site. Figures are easy to read and high resolution.

The text is well edited. I found a very small number of spelling or grammatical errors in the book. The book is “cleaner” that many professional edited textbooks.

I didn't notice any instances of the text being culturally insensitive. It is difficult to always find neutral examples or references. The sample problems are appropriate.

This is one of the best Java programming texts that I have reviewed. I am currently using a different text and plan to switch to this text next semester. It is very detailed. The author provides explanations of the core concepts and provides great examples. The modular approach allows it to be used in an introductory CS class, with Java as a first language; and in a software design class focusing on object-oriented design.

Reviewed by Ian Finlayson, Assistant Professor, The University of Mary Washington on 6/20/17

This textbook is remarkably comprehensive. It covers a tremendous amount of material, including nearly every facet of the Java programming language (such as anonymous inner classes, lambdas, variable arity methods etc.). It also includes a... read more

This textbook is remarkably comprehensive. It covers a tremendous amount of material, including nearly every facet of the Java programming language (such as anonymous inner classes, lambdas, variable arity methods etc.). It also includes a chapter covering basic data structures such as lists, stacks, queues and binary trees, as well as chapters on multi-threading and networking, in addition to its thorough and integrated coverage of graphical user interfaces. When using this text for a one semester CS 1 course, I use roughly half of the content. I would probably not use it for a non-major's CS 0 course, as it could be an overwhelming amount of material for students.

The book is excellent for self-study - many students love having all the extra material available even if we don't cover it in class.

One area where I would have like to have seen more content is in the books coverage of recursion. There is one section in chapter nine dealing with recursion which contains four examples. Recursion is also used for implementing lists and trees, but it would be nice to have a slightly longer treatment as it is a confusing topic for many beginning students.

The text does not include an index. The book itself also does not contain a glossary, but there is one on the companion web site. The text includes quizzes at the end of each chapter, as well as programming exercises.

I did not notice any technical errors or inaccuracies in the book.

The book mostly covers Java 7, with some treatment of Java 8 features, so as of now, the book is perfectly up to date. Future changes to Java likely won't necessitate major changes to the text, and the author has updated the text several times (currently on version 7).

The one area of slight concern is with the Swing library used to build GUI applications. Oracle has replaced Swing with JavaFX, which is the new preferred way of writing GUIs in Java. Still, Swing is widely used and a fine thing to use for introductory courses. Moreover, Swing will be a supported part of Java for a long time as it is still so widely used.

I think the clarity of writing is the best feature of this text. The author uses an easy to read, conversational writing style. The text is also very thorough in its explanations.

The author does a good job using consistent terminology. He explains new terms which are introduced and is very careful about phrasing in general. For instance when talking about objects he has this to say:

"It is certainly not at all true to say that the object is 'stored in the variable std.' The proper terminology is that 'the variable std refers to or points to the object".

Actually speaking about the terminology explicitly like this is really helpful.

The text does use the term "subroutine". While it is internally consistent about this, it is not really consistent with other sources which nearly always refer to them as "methods" in the context of Java. It is not a big point, but students may be confused because they are not called subroutines in other resources they may consult.

The text is as modular as any other introductory programming text book I have seen. It wouldn't be possible to make sense of the example programs in later chapters without a solid mastery of the material in earlier chapters, but that's expected with this type of text. That said, the book does a good job of being as modular as it can. For instance, several of the later sections in a chapter can be skipped over, and, as I describe below, I re-arrange the material slightly to fit my course.

One caveat to this is that many of the examples in later chapters make use of the GUI programming from chapter six. When considering this text, you should be aware that its use of graphics is pretty fundamental and not something you could easily skip over. I see this as a positive as it adds some interest to the example programs which are graphical.

I like the organization of the book quite a lot. It does not use the "objects first" approach. Objects and classes are covered in chapter five, after the basic programming building blocks such as control structures and methods. I did find that some of the later sections within a chapter were things I didn't want to introduce to students at that point. For instance I skip the section on exceptions at the end of chapter three, and the sections on interfaces and nested classes at the end of chapter five.

I do think that the putting off arrays until chapter seven is a mistake, mostly because it is just hard to give good assignments that don't use arrays. When teaching with this book, I cover chapter seven after chapter four.

Overall though, the book does a fine job of transitioning from one topic to the next as it covers not only the particulars of the Java programming language, but the art of programming itself.

I did not find any interface issues at all. The text includes helpful PDF links in the table of contents, and also when the text makes a reference to another section. When discussing the example programs, the author also includes links to the full code on the book's web site, which is helpful. Figures are easy to read and high resolution. One suggestion I would have to improve the interface would be to include syntax highlighting for code listings.

The text is remarkably well edited for its length. I only noticed a handful of spelling or grammatical errors in the book.

I didn't notice any instances of the text being culturally insensitive. The text did not refer to people very often at all. In the few times it mentions the user or programmer, the author uses male and female pronouns equally. For instance at one point the text will mention a guess the number program telling the user "he lost", and later on saying a blackjack program should quit when the user wants to or when "she runs out of money".

I think this book is superior to other introductory programming texts that I have used, even without considering the fact that it is open and free. It is very detailed and provides clear expositions and great examples on everything that can be included in an introductory course (and then some). The few criticisms I have for the book can be easily worked around.

Table of Contents

  • Chapter 1: Overview: The Mental Landscape
  • Chapter 2: Programming in the Small I: Names and Things
  • Chapter 3: Programming in the Small II: Control
  • Chapter 4: Programming in the Large I: Subroutines
  • Chapter 5: Programming in the Large II: Objects and Classes
  • Chapter 6: Introduction to GUI Programming
  • Chapter 7: Arrays and ArrayLists
  • Chapter 8: Correctness, Robustness, Efficiency
  • Chapter 9: Linked Data Structures and Recursion
  • Chapter 10: Generic Programming and Collection Classes
  • Chapter 11: Input/Output Streams, Files, and Networking
  • Chapter 12: Threads and Multiprocessing
  • Chapter 13: GUI Programming Continued

Ancillary Material

  • David J. Eck

About the Book

Welcome to the Eighth Edition of Introduction to Programming Using Java, a free, on-line textbook on introductory programming, which uses Java as the language of instruction. This book is directed mainly towards beginning programmers, although it might also be useful for experienced programmers who want to learn something about Java. It is not meant to provide complete coverage of the Java language.

The eighth edition requires Java 8 or later, and it uses JavaFX for GUI programming. Version 8.1 is a small update of Version 8.0. This version briefly covers some of the new features in Java 11 and makes it clearer how to use this book with Java 11 and later.

About the Contributors

David J. Eck Ph.D. is a Professor at Department of Mathematics and Computer Science at the Hobart and William Smith Colleges.

Contribute to this Page

  • Online Degree Explore Bachelor’s & Master’s degrees
  • MasterTrack™ Earn credit towards a Master’s degree
  • University Certificates Advance your career with graduate-level learning
  • Top Courses
  • Join for Free

University of Pennsylvania

Introduction to Java and Object-Oriented Programming

This course is part of Introduction to Programming with Python and Java Specialization

Taught in English

Some content may not be translated

Brandon Krakowsky

Instructor: Brandon Krakowsky

Financial aid available

31,448 already enrolled

Coursera Plus

(253 reviews)

Recommended experience

Beginner level

High school or college math.

“Introduction to Python Programming” Coursera course or equivalent prior knowledge of basic programming concepts.

What you'll learn

Identify core aspects of object-oriented programming and features of the Java language.

Use Eclipse for writing and running Java code.

Develop programs that use Java collections and apply core object-oriented programming concepts using classes, polymorphism, and method overloading.

Test code by applying principles of test-driven development using Java's unit testing framework.

Skills you'll gain

  • Unit Testing
  • Java Syntax
  • Java Programming
  • Object-Oriented Programming (OOP)

Details to know

introduction to java programming assignments

Add to your LinkedIn profile

See how employees at top companies are mastering in-demand skills

Placeholder

Build your subject-matter expertise

  • Learn new concepts from industry experts
  • Gain a foundational understanding of a subject or tool
  • Develop job-relevant skills with hands-on projects
  • Earn a shareable career certificate

Placeholder

Earn a career certificate

Add this credential to your LinkedIn profile, resume, or CV

Share it on social media and in your performance review

Placeholder

There are 3 modules in this course

This course provides an introduction to the Java language and object-oriented programming, including an overview of Java syntax and how it differs from a language like Python. Students will learn how to write custom Java classes and methods, and how to test their code using unit testing and test-driven development. Topics include basic data structures like Arrays and ArrayLists and overloading methods.

Module 1 : Introduction to Java, Classes, & Eclipse

Welcome to Java! This first module provides an introduction to the Java language and object-oriented programming. It includes an overview of Java syntax, in particular, how it differs from a language like Python. Topics will include variables and data types, loops and conditionals, printing to the console, scanning for user input, and code documentation. This module also explains the structure and inner-workings of a Java class and teaches you how to define your own custom classes and methods.

What's included

38 videos 9 readings 2 quizzes 2 app items

38 videos • Total 95 minutes

  • What to expect from this Course • 1 minute • Preview module
  • About the Instructor : Brandon Krakowsky • 1 minute
  • How to submit assignments in Codio • 6 minutes
  • Module 1 Introduction • 0 minutes
  • Java vs. Python • 1 minute
  • Java is compiled • 0 minutes
  • Popularity of Java vs. Python • 0 minutes
  • Installing & running Java • 0 minutes
  • Downloading & installing the Java Development Kit (JDK) • 0 minutes
  • Installing & configuring Eclipse • 0 minutes
  • Eclipse overview • 0 minutes
  • Simple introductory program • 0 minutes
  • Some general rules for Java • 1 minute
  • Variables & data types • 1 minute
  • Declaring variables • 0 minutes
  • Strings vs. chars • 0 minutes
  • Printing • 0 minutes
  • 'while' loops • 0 minutes
  • 'for' loops • 0 minutes
  • Getting input • 0 minutes
  • Java comments & Javadocs • 1 minute
  • Coding Demonstration : Creating my first java project • 0 minutes
  • Coding Demonstration : Creating my first class & using the main method • 1 minute
  • Coding Demonstration : Defining variables • 1 minute
  • Coding Demonstration : Strings and characters • 2 minutes
  • Coding Demonstration : Math operations • 3 minutes
  • Coding Demonstration : String operations • 1 minute
  • Coding Demonstration : Conditionals and loops • 7 minutes
  • Coding Demonstration : Casting • 7 minutes
  • Coding Demonstration : User input • 6 minutes
  • Coding Demonstration : Adding Javadocs • 1 minute
  • Java is class based • 0 minutes
  • Defining a class • 0 minutes
  • Defining fields in a class • 0 minutes
  • Defining a constructor for a class • 0 minutes
  • Defining a method in a class • 0 minutes
  • Creating an instance of a class • 0 minutes
  • Coding Demonstration : Banking project • 33 minutes

9 readings • Total 56 minutes

  • Course Layout & Syllabus • 10 minutes
  • Tips to succeed in this course • 10 minutes
  • Navigating Assignments using Codio • 10 minutes
  • Module 1 Resources (DOWNLOAD RELEVANT CODE AND/OR DATA FILES FOR THIS MODULE HERE) • 5 minutes
  • Installing & configuring Eclipse overview • 7 minutes
  • Math operators • 3 minutes
  • Casting • 3 minutes
  • 'char' operations • 3 minutes
  • Importing a Java Program into Eclipse • 5 minutes

2 quizzes • Total 34 minutes

  • Quiz 01 - Intro to Java & The Java Language • 20 minutes
  • Quiz 02 - Classes • 14 minutes

2 app items • Total 300 minutes

  • Practice Coding Assignment 1a: Hello World! • 120 minutes
  • Homework 1 : Simple Game • 180 minutes

Module 2 : Unit Testing, Arrays, & ArrayLists

In this module, you will be taught to test your code to get it working. The best way to do this is to write a set of unit tests that you can run against your program, at any time. In this module, we'll learn how to do unit testing in Java, and why we want to do it. We’ll also learn all about Java Arrays, which are collections of items, and ArrayLists, which are kind of like arrays, but much more flexible. These work just like lists in Python. ArrayLists are part of Java’s larger Collections Framework, which we’ll continue to reference throughout this course.

23 videos 5 readings 2 quizzes 2 app items

23 videos • Total 94 minutes

  • Module Introduction • 0 minutes • Preview module
  • Why unit test? • 0 minutes
  • Disadvantages & advantages • 0 minutes
  • JUnit • 0 minutes
  • Terminology • 0 minutes
  • Assert methods • 1 minute
  • Coding Demonstration : Counter project • 15 minutes
  • Testing for equality • 1 minute
  • Implementing the equals method • 0 minutes
  • Coding Demonstration : Comparing people • 8 minutes
  • Coding Demonstration : Banking project with unit testing • 23 minutes
  • Declaring & initializing arrays • 3 minutes
  • Initializing arrays in one line • 0 minutes
  • The length of an array • 0 minutes
  • Stepping through an array using a for loop or enhanced for loop • 1 minute
  • Nested arrays • 1 minute
  • Accessing values in nested arrays • 0 minutes
  • About the Collections Framework • 0 minutes
  • Creating an ArrayList • 0 minutes
  • The size of an ArrayList • 0 minutes
  • Printing primitives vs. Objects • 0 minutes
  • Implementing the toString method • 3 minutes
  • Coding Demonstration : Classroom project • 27 minutes

5 readings • Total 16 minutes

  • Module 2 Resources (DOWNLOAD RELEVANT CODE AND/OR DATA FILES FOR THIS MODULE HERE) • 5 minutes
  • More assert methods • 3 minutes
  • Even more assert methods • 2 minutes
  • Array methods • 3 minutes
  • ArrayList methods • 3 minutes

2 quizzes • Total 22 minutes

  • Quiz 03 - Unit Testing • 10 minutes
  • Quiz 04 - Arrays & ArrayLists • 12 minutes

2 app items • Total 240 minutes

  • Homework 2 : Custom String • 120 minutes
  • Homework 3 : Arrays & ArrayLists • 120 minutes

Module 3 : Static Variables, Methods, & Polymorphism Using Overloading

So far, we’ve been defining variables as instance variables in our Java classes. Instance variables are just variables defined inside a class, and every instance of a class can have a different value for an instance variable. In this module, we’ll look at defining static variables in our Java classes. Static variables are also defined as variables inside a class, but with the keyword 'static'. Static variables have the same value for every instance of a class. In fact, you don’t even need to create an instance of a class to use a static variable! We’ll also look at static methods. And just like static variables, you don’t need to create an instance of a class to use, or call, a static method. In this module, we’re also going to introduce polymorphism, which refers to overloading and overriding. We’ll focus on overloading, which is having two or more methods in the same class, with the same name.

21 videos 1 reading 2 quizzes 1 app item

21 videos • Total 88 minutes

  • Module 3 Introduction • 1 minute • Preview module
  • Instance variables vs. static variables • 1 minute
  • Creating static variables • 0 minutes
  • Referencing static variables • 0 minutes
  • Using static variables for hard-coded values • 1 minute
  • About static methods • 0 minutes
  • Static helper methods • 0 minutes
  • About Java’s main method • 0 minutes
  • When to use a static method • 0 minutes
  • Other use cases for static • 1 minute
  • Other rules for static • 0 minutes
  • Coding Demonstration : Customer tracking project • 24 minutes
  • Method signatures • 0 minutes
  • Polymorphism • 0 minutes
  • Overloading • 0 minutes
  • Why overload a method? • 1 minute
  • DRY (Don’t Repeat Yourself) principle of software development • 0 minutes
  • Legal vs. illegal variable assignments and method calls • 1 minute
  • Java uses the most specific method • 0 minutes
  • Multiple constructors • 8 minutes
  • Coding Demonstration : Dog project • 39 minutes

1 reading • Total 5 minutes

  • Module 3 Resources (DOWNLOAD RELEVANT CODE AND/OR DATA FILES FOR THIS MODULE HERE) • 5 minutes

2 quizzes • Total 20 minutes

  • Quiz 05 - Static Variables & Methods • 8 minutes
  • Quiz 06 - Polymorphism - Overloading • 12 minutes

1 app item • Total 180 minutes

  • Homework 4 : Custom Integer ArrayList • 180 minutes

Instructor ratings

We asked all learners to give feedback on our instructors based on the quality of their teaching style.

introduction to java programming assignments

The University of Pennsylvania (commonly referred to as Penn) is a private university, located in Philadelphia, Pennsylvania, United States. A member of the Ivy League, Penn is the fourth-oldest institution of higher education in the United States, and considers itself to be the first university in the United States with both undergraduate and graduate studies.

Recommended if you're interested in Software Development

introduction to java programming assignments

University of Pennsylvania

Inheritance and Data Structures in Java

introduction to java programming assignments

Introduction to Programming with Python and Java

Specialization

introduction to java programming assignments

Duke University

Java Programming: Solving Problems with Software

introduction to java programming assignments

Java Basics: Selection and Iteration

Why people choose coursera for their career.

introduction to java programming assignments

Learner reviews

Showing 3 of 253

253 reviews

Reviewed on Oct 25, 2021

This course has enlightened me on how to write and program tasks using JavaScript software. Of course, I had to learn certain methods mentioned in the homework assignments using external sources.

Reviewed on Apr 6, 2021

Cool course, a lot of pain through one of the homeworks!

Reviewed on May 29, 2022

A 10 out of 10 course. Very well designed and the assignments are great for enhancing learning and understanding.

New to Software Development? Start here.

Placeholder

Open new doors with Coursera Plus

Unlimited access to 7,000+ world-class courses, hands-on projects, and job-ready certificate programs - all included in your subscription

Advance your career with an online degree

Earn a degree from world-class universities - 100% online

Join over 3,400 global companies that choose Coursera for Business

Upskill your employees to excel in the digital economy

Frequently asked questions

How much math do i need to know to take this course.

The only math that learners will need for this Specialization is arithmetic and basic concepts in logic.

This course was fun. How can I learn more?

If you enjoyed this course, we recommend Courses 1, 2 and 4 in the series!

If you would like to learn the fundamentals of computer science beyond the basics of programming, consider applying to the Master of Computer and Information and Technology (MCIT) at the University of Pennsylvania, an Ivy League computer science master’s program for people without a computer science background. For an on-campus experience, explore here Opens in a new tab . If you prefer an online setting, apply to MCIT Online Opens in a new tab . In fact, the lectures in this series are also used in the online degree program! The Specialization certificate will be viewed favorably by the admissions committee, so be sure to mention it when you apply.

When will I have access to the lectures and assignments?

Access to lectures and assignments depends on your type of enrollment. If you take a course in audit mode, you will be able to see most course materials for free. To access graded assignments and to earn a Certificate, you will need to purchase the Certificate experience, during or after your audit. If you don't see the audit option:

The course may not offer an audit option. You can try a Free Trial instead, or apply for Financial Aid.

The course may offer 'Full Course, No Certificate' instead. This option lets you see all course materials, submit required assessments, and get a final grade. This also means that you will not be able to purchase a Certificate experience.

What will I get if I subscribe to this Specialization?

When you enroll in the course, you get access to all of the courses in the Specialization, and you earn a certificate when you complete the work. Your electronic Certificate will be added to your Accomplishments page - from there, you can print your Certificate or add it to your LinkedIn profile. If you only want to read and view the course content, you can audit the course for free.

What is the refund policy?

If you subscribed, you get a 7-day free trial during which you can cancel at no penalty. After that, we don’t give refunds, but you can cancel your subscription at any time. See our full refund policy Opens in a new tab .

Is financial aid available?

Yes. In select learning programs, you can apply for financial aid or a scholarship if you can’t afford the enrollment fee. If fin aid or scholarship is available for your learning program selection, you’ll find a link to apply on the description page.

More questions

introduction to java programming assignments

Search code, repositories, users, issues, pull requests...

Provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications

Introduction to JAVA and object oriented programming course in coursera by University of Pennsylvania

Khushi-Mattu/Intro-to-JAVA-and-OOP-coursera

Folders and files, repository files navigation, intro-to-java-and-oop-coursera.

This repo contains my answers for the assignments and projects of Introduction to Java and Object-Oriented Programming by University of Pennsylvania.

My certificate: https://www.coursera.org/account/accomplishments/verify/JL9D4DZ87WCV

introduction to java programming assignments

  • Java 100.0%

swayam-logo

Programming in Java

Note: This exam date is subjected to change based on seat availability. You can check final exam date on your hall ticket.

Page Visits

Course layout, books and references, instructor bio.

introduction to java programming assignments

Prof. Debasis Samanta

Course certificate.

  • Assignment score = 25% of average of best 8 assignments out of the total 12 assignments given in the course. 
  • ( All assignments in a particular week will be counted towards final scoring - quizzes and programming assignments). 
  • Unproctored programming exam score = 25% of the average scores obtained as part of Unproctored programming exam - out of 100
  • Proctored Exam score =50% of the proctored certification exam score out of 100

introduction to java programming assignments

DOWNLOAD APP

introduction to java programming assignments

SWAYAM SUPPORT

Please choose the SWAYAM National Coordinator for support. * :

Lambda Calculus

COMP 105 Assignment

Due Wednesday, April 17, 2019 at 11:59PM

Lambda calculus is not just a universal model of computation—it is also a language you can use to communicate with educated people around the world. In this assignment,

  • You use lambda calculus to write simple functions
  • You implement lambda calculus using substitution, reduction, and alpha-conversion

Substitution, reduction, and alpha-conversion are found all over programming-language semantics, not just in lambda calculus.

TL;DR: download the template solution and compile with compile105-lambda . Everything will be fine.

Behind the curtain: For the first part, coding in lambda calculus, you will code things from scratch. For the second part, implementing lambda calculus, you will extend an interpreter I’ve written. But because you can work with ML modules now, you won’t be stuck modifying a huge pile of code. Instead, you’ll define several modules, for both implementation and testing, and you’ll use several of my interfaces.

The ML module system is nice, but Moscow ML’s module bureaucracy is not at all nice. I’ve hidden the bureaucracy behind a shell script, compile105-lambda . This script lives in /comp/105/bin , and if you run use comp105 at the command line, you have access to it. But if something goes wrong, you may wish to know about the pieces of the assignment. Here are the source codes: 1

church.lam Your solutions to the first part solution.sml Your module implementing terms, substitution, and reduction client.sml Your module demonstrating term functions string-tests.sml Test cases for your classmates’ code subst-tests.sml Test cases for substitution link-lambda.sml Instructions for linking your code with mine link-lambda-a.sml More instructions for linking your code with mine link-lamstep.sml Even more instructions for linking your code with mine

Using these sources, the compile105-lambda script will create binaries:

./run-solution-unit-tests Runs some of your unit tests ./run-client-unit-tests Runs more unit tests ./run-string-tests Runs more unit tests ./run-subst-tests Runs the last of your unit tests ./linterp Runs your complete interpreter (normal-order reduction) ./lamstep Runs your interpreter, showing each reduction ./linterp-applicative Runs your complete interpreter (applicative-order reduction)

Learning about the lambda calculus

There is no book chapter on the lambda calculus. Instead, we refer you to these resources:

The edited version of Raúl Rojas’s “ A Tutorial Introduction to the Lambda Calculus ” is short, easy to read, and covers the same points that are covered in lecture:

  • Free and bound variables
  • Capture-avoiding substitution
  • Addition and multiplication with Church numerals
  • Church encoding of Booleans and conditions
  • The predecessor function on Church numerals
  • Recursion using the Y combinator

Rojas doesn’t provide many details, but he covers everything you need to know in 9 pages, with no distracting theorems or proofs.

When you want a short, easy overview to help you solidify your understanding, Rojas’s tutorial is your best source.

I have written a short guide to coding in Lambda calculus . It shows how to translate ML-like functions and data, which you already know how to program with, into lambda calculus.

When you are solving the individual programming problems, this guide is your best source.

Prakash Panangaden’s “ Notes on the Lambda-Calculus ” cover the same material as Rojas, but with more precision and detail. Prakash is particularly good on capture-avoiding substitution and change of bound variables, which you will implement.

Prakash also discusses more theoretical ideas, such as how you might prove inequality (or inequivalence) of lambda-terms. And instead of just presenting the Y combinator, Prakash goes deep into the ideas of fixed points and solving recursion equations—which is how you achieve recursion in lambda calculus.

When you are getting ready to implement substitution, Prakash’s notes are your best source.

I have also written a short guide to reduction strategies . It is more useful than anything that could be found online in 2018. As a bonus, it also explains eta-reduction , which is neglected by other sources.

When you have finished implementing substitution and are ready to implement reduction, this guide is your best source.

Wikipedia offers two somewhat useful pages: 2

The Lambda Calculus page covers everything you’ll find in Rojas and much more besides. (If you wish, you can read what Wikipedia says about reduction strategies and evaluation strategies. But do not expect to be enlightened.)

The Church Encoding page goes into more detail about how to represent ordinary data as terms in the lambda calculus. The primary benefit relative to Rojas is that Wikipedia describes more kinds of arithmetic and other functions on Church numerals.

You need to know that the list encoding used on Wikipedia is not the list encoding used in COMP 105 . In order to complete the homework problems successfully, you must use the list encoding described in the guide to coding in lambda calculus .

Introduction to the lambda interpreter

You will implement the key components of an interactive interpreter for the lambda calculus. This section explains how to use the interpreter and the syntax it expects. A reference implementation of the interpreter is available in /comp/105/bin/linterp-nr .

The syntax of definitions

Like the interpreters in the book, the lambda interpreter processes a sequence of definitions. The concrete syntax is very different from the “bridge languages” in the book. Every definition must be terminated with a semicolon. Comments are line comments in C++ style, starting with the string // and ending at the next newline.

The interpreter supports four forms of definition: a binding, a term, the extended definition “ use ”, and an extended definition “ check-equiv ”.

A binding is something like a val form in μ Scheme. A binding has one of two forms: either

In both forms, every free variable in the term must be bound in the environment—if a right-hand side contains an unbound free variable, the result is a checked run-time error. The first step of computation is to substitute for each of the free variables: each occurrence of each free variable is replaced by that variable’s definition.

In the first form, where noreduce appears, no further computation takes place. The substituted right-hand side is simply associated with the name on the left, and this binding is added to the environment.

The noreduce form is intended only for terms that cannot be normalized, such as

The noreduce form is also needed for definitions that use terms like bot  and  Y .

If noreduce is absent, the interpreter substitutes for free variables, then reduces the term on the right until there are no more beta-redexes or eta-redexes. (You will implement the two reduction strategies presented in class.) If reduction doesn’t terminate, the interpreter might loop.

Loading files with use

The use extended definition loads a file into the interpreter as if it had been typed in directly. It takes the form

Comparing normal forms with check-equiv

The check-equiv form immediately reduces two terms to normal form and compares them for equivalence. It has the form

And here are some examples:

Unlike the check-expect in the other interpreters, check-equiv is not “saved for later”—the given terms are normalized right away.

Terms as definitions

As in the book, a term can be entered at the read-eval-print loop, just as if it were a definition. Every free variable in the term is checked to see if it is bound in the environment; if so, each free occurrence is replaced by its binding. Free variables that are not bound in the environment are permissible; they are left alone. 3 The term is reduced to normal form (if possible) and the result is printed.

The syntax of terms

A lambda term can be either a variable, a lambda abstraction, an application, or a parenthesized lambda term. Precedence is as in ML.

A lambda abstraction abstracts over exactly one variable; it is written as follows:

Application of one term to another is written:

The lambda interpreter is very liberal about names of variables. A name is any string of characters that contains neither whitespace, nor control characters, nor any of the following characters: \ ( ) . = / . Also, the string use is reserved and is therefore not a name. But a name made up entirely of digits is OK; the lambda calculus has no numbers, and names like 105 have no special status.

As examples, all the following definitions are legal:

A short example transcript

A healthy lambda interpreter should be capable of something like the following transcript:

For more example definitions, see the predefined.lam file distributed with the assignment.

Software provided for you

Both capture-avoiding substitution and normal-order reduction can be tricky to implement. 4 So that you may have a solid foundation on which to write your lambda code, I provide an interpreter linterp-nr . Running use comp105 should give you access to that interpreter.

Even with a correct interpreter, lambda code can be hard to debug. So I also provide an interpreter called lamstep-nr , which shows every reduction step. Some computations require a lot of reduction steps and produce big intermediate terms. Don’t be alarmed.

All questions and problems

There are four problems on programming with Church numerals, which you’ll do on your own.

There are four problems on implementing the lambda calculus, which you can do with a partner. Your solutions will go into a Standard ML module, which you will link with the rest of the interpreter.

Reading comprehension

These problems will help guide you through the reading. We recommend that you complete them before starting the other problems below. You can download the questions .

(NOT ON THE READING.) Throughout the term, your code’s functional correctness has been assessed by automated testing. The automated test scripts are intended not only to assign a grade but to identify the most important fault in the code. Please answer these two questions:

How did you benefit from the feedback you received about functional correctness?

What were the drawbacks, if any, of the feedback you received about functional correctness?

Syntax of lambda terms . In this assignment, or in Rojas or Panangaden, read about the concrete syntax of lambda-terms . Now define, in Standard ML, an algebraic data type term that represents the abstract syntax of terms. Your data type should have one value constructor for a variable, one for a lambda abstraction, and one for an application.

You are ready for exercise 5, and you have a foundation for exercises 6 and 8.

Recognizing redexes . Read about redexes in Wikipedia . (You will then follow up with Panangaden .)

Wikipedia mentions two kinds of redex. What are their names?

In Panangaden, Definition 1.7 defines a redex. Which of the two redexes mentioned in Wikipedia is being defined here?

Your code will have to recognize redexes, and it starts with knowing the form of each kind. As of Spring 2019, both forms are shown in Wikipedia. But if Wikipedia changes, one form can be found in Panangaden; for the other, look in the last section of my guide to reduction strategies.

For each of the two kinds of redex, use the concrete syntax for our lambda interpreter ( see above ) to show what form every redex of that kind takes.

For each of the two kinds of redex, use your algebraic data type from the preceding question to write a pattern that matches every redex of that kind.

You are getting ready for exercise 8 (reductions).

Practicing reduction . Read about reduction on Wikipedia. Then in Panangaden , be sure you have an idea about each of these concepts:

Capture-avoiding substitution (Definition 1.3)

Reduction (Definition 1.5), including the example reduction (Example 1.3)

Redex , contractum , and normal form (Definitions 1.7 and 1.8)

Showing each reduction step, reduce the following term to normal form. At each step, choose a redex and replace the redex with its contractum. Do not expand or replace the names ZERO and NONZERO .

The term contains more than one redex, but no matter which redex you choose at each step, you should reach the normal form after exactly four reductions.

You are preparing to complete exercise 8.

Reduction: the general case . For each kind of redex, repeat the general form of the redex from question 2(c) 3(c) above, then show what syntactic form the redex reduces to (in just a single reduction step).

When to reduce . Read my handout on reduction strategies . Using the concrete syntax accepted by the interpreter (and defined above) , write a lambda term that contains exactly two redexes, such that normal-order reduction strategy reduces one redex, and applicative-order reduction strategy reduces the other redex.

You are (finally!) ready for exercise 8.

Understanding Church numerals . You may recognize the practice reduction above as a computation that tells if a Church numeral is zero. Read about Church numerals, either on pages 9 and 10 of Panangaden or in Section 2 of Rojas (“Arithmetic”). Then, say whether each of the following lambda-calculus terms is a Church numeral. If so, write the corresponding decimal representation. If not, write “not a Church numeral”.

Programming in the lambda calculus (individual problems)

These problems give you a little practice programming in the lambda calculus. Most functions must terminate in linear time , and you must do these exercises by yourself. You can use the reference interpreter linterp-nr .

Lambda-calculus programs work at the same intellectual level as assembly-language programs. Therefore, every new helper function must be well named and must be accompanied by a contract. Detailed guidance can be found below .

Helper functions listed in the assignment are exempt from the contract requirement, as are the helper functions in predefined.lam .

Complete all four problems below, and place your solutions in file church.lam .

Not counting code copied from the lecture notes, my solutions to all four problems total less than fifteen lines of code. And all four problems rely on the same related reading.

Related reading for lambda-calculus programming problems 1 to 4:

My guide Coding in Lambda Calculus should explain everything you need to know to write functional programs in lambda calculus. If not, or if the explanations there are a little too terse, consult the additional readings below.

Basic techniques can be found in Wikipedia on Church Encoding and in section 2 of Panangaden , which is titled “Computing with Lambda Calculus” (from page 8 to the middle of page 10). These basics are sufficient for you to tackle problems 1 and 2.

Another alternative is Section 2 of Rojas’s tutorial, entitled “arithmetic.” Rojas doesn’t mention Church numerals by name, but that’s what he’s working with. You may find the examples useful and the presentation more accessible than what you see from Panangaden.

On problems 3 and 4 only, if you have the urge to write a recursive function, you may use a fixed-point combinator. My guide ends with a few pages on recursion. You may also wish to consult the first paragraph under “Fixed-Point Combinators” on page 10 of Panangaden . This explanation is by far the best and simplest explanation available—but it is very terse. For additional help, consult the examples on page 11.

I recommend against the Wikipedia “main article” on fixed-point combinators: the article is all math all the time, and it won’t give you any insight into how to use a fixed-point combinator.

1. Church Numerals—parity . Without using recursion or a fixed-point combinator , define a function even? which, when applied to a Church numeral, returns the Church encoding of true or false , depending on whether the numeral represents an even number or an odd number.

Your function must terminate in time linear in the size of the Church numeral.

Ultimately, you will write your function in lambda notation acceptable to the lambda interpreter, but you may find it useful to try to write your initial version in Typed μScheme (or ML or μ ML or μScheme) to make it easier to debug.

Remember these basic terms for encoding Church numerals and Booleans:

You can load these definitions by typing use predefined.lam; in your interpreter.

2. Church Numerals—division by two . Without using recursion or a fixed-point combinator , define a function div2 which divides a Church numeral by two (rounding down). That is, div2 applied to the numeral for 2 n returns  n , and div2 applied to the numeral for 2 n  + 1 also returns  n .

We don’t know if this one can be done in linear time, but it is sufficient if your function terminates in time quadratic in the size of the Church numeral.

Hint : Think about function split-list from the Scheme homework , about the implementation of the predecessor function on natural numbers, and about the “window” example from recitation.

3. Church Numerals—conversion to binary. Implement the function binary from the Impcore homework . The argument and result must be Church numerals. For example,

For this problem, you may use the Y combinator. If you do, remember to use noreduce when defining binary , e.g.,

This problem, although not so difficult, may be time-consuming. If you get bogged down, go forward to the list-selection problem ( nth ), which can benefit from similar skills in recursion, fixed points, and Church numerals. Then come back to this problem.

Your function must terminate in time quadratic in the size of the Church numeral.

EXTRA CREDIT . Write a function binary-sym that takes three arguments: a name for zero, a name for one, and a Church numeral. Function binary-sym reduces to a term that “looks like” the binary representation of the given Church numeral. Here are some examples where I represent a zero by a capital  O  (oh) and a one by a lower-case  l  (ell):

It may help to realize that l l O l is the application (((l l) O) l) —it is just like the example E 1 E 2 E 3 … E n in the first section of Rojas’s tutorial .

Function binary-sym has little practical value, but it’s fun. If you write it, please put it in your church.lam file, and mention it in your README file.

4. Church Numerals—list selection . Write a function nth such that given a Church numeral n and a church-encoded list xs of length at least n +1, nth n xs returns the n th element of xs :

To get full credit for this problem, you must solve it without recursion. But if you want to define nth as a recursive function, use the Y combinator, and use noreduce to define nth .

Provided xs  is long enough, function  nth must terminate in time linear in the length of the list. Don’t even try to deal with the case where xs is too short.

Hint: One option is to go on the web or go to Rojas and learn how to tell if a Church numeral is zero and if not, and how to take its predecessor. There are other, better options.

Implementing the lambda calculus (possibly with a partner)

For problems 5 to 8 below, you may work on your own or with a partner. These problems help you learn about substitution and reduction, the fundamental operations of the lambda calculus. The first problem also gives you a little more practice in using continuation-passing to code an algebraic data type, which is an essential technique in lambda-land.

For each problem, you will implement types and functions described below. When you are done, the compile105-lambda script will link your code with mine to build a complete lambda interpreter. To simplify the configuration, most of the functions and types you must define will be placed in a module called SealedSolution , which you will implement in a single file called solution.sml . The module must be sealed with this interface:

You can download a template solution .

5 . Evaluation—Coding terms .

In your file solution.sml , create an ML type definition for a type term , which should represent a term in the untyped lambda calculus. Using your representation, define functions lam , app , var , and cpsLambda .

Compile this file by running compile105-lambda (with no arguments), then run any internal unit tests by running ./run-solution-unit-tests .

My solution is under 15 lines of ML code.

Related reading: The syntax of lambda terms in this homework.

6 . Evaluation—Substitution . In file solution.sml , implement capture-avoiding substitution on your term representation. In particular,

Define function freeIn of type string -> term -> bool , which tells if a given variable occurs free in a given term. (If you adapt your solution to the pair problem on the ML homework, or my model solution to that problem, acknowledge your sources!)

Define function freeVars of type term -> string list , which returns the variables free in a given term. The list must have no duplicates.

Define function subst of type string * term -> term -> term . Calling subst ( x , N ) M returns the term M [ x  ↦  N ] (“ M  with x goes to  N ”).

Function subst obeys these algebraic laws, 5 in which x  and  y stand for variables, and N  and  M stand for terms:

  • subst ( x , N ) x = N
  • subst ( x , N ) y = y , provided y is different from  x
  • subst ( x , N ) ( M 1 M 2 ) = ( subst ( x , N ) M 1 ) ( subst ( x , N ) M 2 )
  • subst ( x , N ) ( λ x . M ) = ( λ x . M )
  • subst ( x , N ) ( λ y . M ) = λ y .( subst ( x , N ) M ) , provided x  is not free in  M or y  is not free in  N , and also provided y is different from  x

If none of the cases above apply, then subst ( x , N )  M should return subst ( x , N )  M ′ , where M ′  is a term that is obtained from  M by renaming bound variables. Renaming a bound variable is called “alpha conversion.”

You need to rename bound variables only if you encounter a case that is like case (e), but in which x  is free in  M and y  is free in  N . In such a case, subst ( x ,  N )  ( λ y . M ) can be calculated only by renaming  y , which is bound in the lambda abstraction, to some new variable that is not free in M  or  N .

To help you implement subst , you may find it useful to define this helper function:

  • Function freshVar , which is given a list of variables and produces a variable that is different from every variable on the list

By using freshVar on the output of freeVars , you will be able to implement alpha conversion.

To test this problem, you have three possible approaches:

The next problem demands a minimal set of test cases. You can stick with this set and choose not to worry about further testing.

You can add Unit tests to your solution.sml file. You would then compile it by running compile105-lambda with no arguments, and run the binary ./run-solution-unit-tests that results.

You can also build and run the full interpreter ./linterp , again by running compile105-lambda without arguments. But be warned: you may see some alarming-looking terms that have extra lambdas and applications. This is because the interpreter uses lambda to substitute for the free variables in your terms. Here’s a sample:

Everything is correct here except that the code claims something is in normal form when it isn’t. If you reduce the term by hand, you should see that it has the normal form you would expect.

My solution to this problem is just under 40 lines of ML code.

Related reading:

Panangaden describes free and bound variables in Definition 1.2 on page 2. He defines substitution in Definition 1.3 on page 3. (His notation is a little different from our ML code, but the laws for subst are the same.)

In his Definition 1.3, case 6, plus Definition 1.4, Panangaden explains the “change of bound variables” that you need to implement if none of the cases for subst apply.

Page 470 of your book defines an ML function freshName which is similar to the function freshVar that you need to implement. The freshName on page 470 uses an infinite stream of candidate variables. You could copy all the stream code from the book, but it will probably be simpler just to define a tail-recursive function that tries an unbounded number of variables.

Don’t emulate function freshtyvar on page 517. It’s good enough for type inference, but it’s not good enough to guarantee freshness in the lambda calculus.

7 . Substitution tests . As shown in the previous problem, function subst has to handle five different cases correctly. It also has to handle a sixth case, in which none of the laws shown above applies, and renaming is required. In this problem, you create test cases for your subst function. They should go into a file subst-tests.sml , which should look like this:

To run these tests, run compile105-lambda without arguments, then run the resulting binary ./run-subst-tests .

8 . Evaluation—Reductions . In this problem, you use your substitution function to implement two different reduction strategies, called reduceN and reduceA .

A reduction strategy is a function that takes a term  M and produces a one of the following two values:

  • Reduction.DOESN'T_STEP , if it is not possible to reduce  M
  • Reduction.ONE_STEPS_TO  N , if  M  reduces to  N in a single step

The relation “ M  reduces to  N in a single step” is written M  →  N , and it is explained in the handout on reduction strategies as well as in many other sources on the lambda calculus.

Each function takes a term and tries to perform a single reduction step, using any rule that applies: Beta , Eta , Mu , Nu , or Xi . (The rules are shown in the handout on reduction strategies.) Each function is specified as follows:

Function reduceN implements normal-order reduction: it tries the leftmost, outermost redex first. In other words, it prefers Beta over Nu and Nu over Mu ).

Function reduceA implements applicative-order reduction: it uses the Beta rule only when the argument is normal form. In other words, it prefers Mu over Beta .

Both functions must also implement Eta reduction.

To compile and test this code, run compile105-lambda without arguments, then test using ./linterp (normal-order reduction), ./lamstep (normal-order reduction, showing each step), and ./linterp-applicative (applicative-order reduction). You may also wish to consult the hints below.

I’ve written two solutions to this problem. One solution uses only first-order functions: it implements reduceN and reduceA directly, by extensive case analysis. My first-order solution is about 30 nonblank lines of ML code. The other solution uses higher-order functions to define reduceN and reduceA . It implements each rule as its own function, then combines them using the >=> operator described below. My higher-order solution is about 25 nonblank lines of ML code.

Start with my guide, “ Reduction Strategies for Lambda Calculus .”

For implementation, read the Hints on the implementation of reduction section below.

Consider consulting Panangaden , who describes the reduction relation in Definition 1.5. Although he treats it as a mathematical relation, not a computational rule, you may find his definitions helpful. But some commentary is required:

Rules α  (change of variables) and ρ  (reflexivity) have no computational content and should therefore play no part in reduceN or reduceA . (Rule  α plays a part in subst .)

Rule τ  (transitivity) involves multiple reductions and therefore also plays no part in reduceN or reduceA .

The remaining rules are used in both reduceN and reduceA , but with different priorities.

Rule β is the key rule, and in normal-order reduction, rule  β is always preferred.

In applicative-order reduction, rule μ (reduction in the argument position) is preferred.

In normal-order reduction, rule ν (reduction in the function position) is preferred over rule  μ but not over rule  β .

Finally, Panangaden omits rule  η , which like rule  β is always preferred:

  • λ x . M x  →  M , provided x  is not free in  M

You must implement the η rule as well as the other rules.

If you want to know more, or you want a different formulation, go (cautiously) to Wikipedia. Wikipedia describes some individual reduction rules in the Reduction section of the lambda-calculus page. And it briefly describes applicative-order reduction and normal-order reduction, as well as several other reduction strategies, in the reduction strategies section of the lambda-calculus page.

Hints on the implementation of reduction

The return type of reduceA and reduceN is term Reduction.result , where Reduction.result is defined by this interface, which also defines some useful helper functions:

The helper functions rmap , nostep , and >=> are used to implement the second of two possible implementation options:

The first-order option is simply to take a term, break its representation down by cases, and in each case, define a right-hand side that combines all the rules for that case, including the Eta rule. The advantage of this option is it’s concrete, and the programming techniques are ones you’ve been using all along—break down the data by cases, apply the rules. The disadvantage is that there are a lot of cases, and the logic on the right hand side is complicated. Once you’ve written the code, it will be hard to understand and hard to debug. Students choosing this option often forget cases or botch cases.

The higher-order option is to define each rule as its own function, then to compose the functions using the >=> operator in the Reduction module. 6 The advantage of this option is that the construction of the reduction strategy makes it crystal clear what is going on and in what order—it becomes very hard to forget or botch a case. This option also makes it easy to implement and test one rule at a time. The disadvantage of this option is that it is abstract, and it is aggressively higher-order: you are using the >=> arrow to compose simple functions into more complex functions. Understanding the “reducer” abstraction well enough to implement it will take a little time.

Notes on the higher-order option

If you want to try the REDUCTION interface and the higher-order option, here are some notes:

The type called 'a reducer is really a partial reducer: a function of this type implements some sequence of rules. Function nostep implements no rules, and the composition arrow  >=> combines two functions to implement a combined sequence of rules. Your implementation task breaks down into two steps: first, define rule functions; second, compose them.

The rmap function is the classic mapping idea (called “homomorphic”) which you have already seen in List.map and Option.map . It is especially useful in conjunction with curry , as in

You may also find a use for flip .

The composition arrow is mean to be used as an infix operator. In your solution file, copy these definitions:

The most beautiful code emerges if you define functions beta , eta , nu , mu , and  xi , then compose them:

But there’s a problem here: the nu , mu , and xi rules all need the capability of doing general reduction on a subterm, which means they have to be mutually recursive with the reducer. Mutually recursion can be handled in several ways, but the easiest is to define the individual rule functions inside the reducer, in a let binding. This easy way does, however, duplicate code. If you want to avoid the duplication, you can do something like this:

Overall, I think the higher-order option is worth the extra effort needed to understand the reducer type and its composition: when you split each rule into its own function, it’s much, much easier to get them all right. And it’s easy to reuse the same functions in multiple reduction strategies.

Debugging support

As shipped, the lambda-calculus interpreter reduces each term repeatedly, until it reaches a normal form. But when you are debugging reduction strategies, you may find it helpful to see the intermediate terms. The compile105-lambda script should produce an executable program ./lamstep , which will show the results of every reduction step. You can compare this interpreter with the reference version, called lamstep-nr .

Even more debugging support

If the ./lamstep interpreter doesn’t provide enough information (or provides too much), here is a way to print a status report after every n reductions:

I have defined a status function size that prints the size of a term. You can print whatever you like: a term’s size, the term itself, and so on. Here is how I show the size of the term after every reduction. Some “reductions” make terms bigger!

More Extra Credit

Solutions to any of the extra-credit problems below should be placed in your README file. Some may be accompanied by code in your solution.sml file.

Extra Credit. Normalization. Write a higher-order function that takes as argument a reduction strategy (e.g., reduceA or reduceN ) and returns a function that normalizes a term. Your function should also count the number of reductions it takes to reach a normal form. As a tiny experiment, report the cost of computing using Church numerals in both reduction strategies. For example, you could report the number of reductions it takes to reduce “three times four” to normal form.

This function should be doable in about 10 lines of ML.

Extra Credit . Normal forms galore. Discover what Head Normal Form and Weak Head Normal Form are and implement reduction strategies for them. Explain, in an organized way, the differences between the four reduction strategies you have implemented. (If you choose the higher-order option for implementing reduction strategies, this extra credit is easy. Otherwise, not so much.)

Extra Credit . Typed equality. For extra credit, write down equality on Church numerals using Typed uScheme, give the type of the term in algebraic notation, and explain why this function can’t be written in ML. (By using the “erasure” theorem in reverse, you can take your untyped version and just add type abstractions and type applications.)

What and how to submit: Individual work

Using script submit105-lambda-solo , submit

  • The names of the people with whom you collaborated
  • Any extra credit you may have earned
  • File cqs.lambda.txt , containing your answers to the reading-comprehension questions
  • File church.lam containing your solutions to the Church-numeral problems, including possibly the binary-sym extra credit

As soon as you have the files listed above, run submit105-lambda-solo to submit a preliminary version of your work. Keep submitting until your work is complete; we grade only the last submission.

What and how to submit: Pair work

Using script submit105-lambda-pair , submit

README Collaborators, extra credit, and so on solution.sml Your module implementing terms, substitution, and reduction subst-tests.sml Test cases for substitution

As soon as you have the files listed above, and all the code compiles, run submit105-lambda-pair to submit a preliminary version of your work. Keep submitting until your work is complete; we grade only the last submission.

Avoid common mistakes

Common mistakes with church numerals.

Here are some common mistakes to avoid when programming with Church numerals:

Don’t forget names and contracts for helper functions.

Don’t forget a semicolon after each definition.

Don’t forget the question mark in the name of even? .

When using a fixed-point combinator to define a function, don’t forget to use noreduce in the definition form.

Don’t use the list representation or primitives from Wikipedia. We will test your code using the representation and primitives from Coding in Lambda Calculus , which you will also find in the file predefined.lam .

Don’t include any use directives in church.lam .

Don’t copy predefined terms from predefined.lam . We will load the predefined terms before running your code.

To make sure your code is well formed, load it using

If you want to build a test suite, put your tests in file test.lam and run

Common mistakes with the lambda interpreter

Here are some common mistakes to avoid in implementing the interpreter:

Don’t forget the Eta rule :

Here is a reduction in two eta steps:

Your interpreters must eta-reduce when possible.

Don’t forget to reduce under lambdas (the Xi rule).

Don’t forget that in an application M 1   M 2 , just because M 1 is in normal form doesn’t mean the whole thing is in normal form. If  M 1 doesn’t step, you must try to reduce  M 2 .

If you are using the first-order implementation option, don’t clone and modify your code for reduction strategies; people who do this wind up with wrong answers. The code should not be that long; use a clausal definition with nested patterns, and write every case from scratch.

Do make sure to use normal-order reduction, so that you don’t reduce a divergent term unnecessarily.

Don’t try to be clever about a divergent term; just reduce it. (It’s a common mistake to try to detect the possibility of an infinite loop. Mr. Turing proved that you can’t detect an infinite loop, so please don’t try.)

When implementing freshVar , don’t try to repurpose function freshTyvar from section 7.6. That function isn’t smart enough for your needs.

How your work will be evaluated

Your ML code will be judged by the usual criteria, emphasizing

  • Correct implementation of the lambda calculus
  • Names and contracts for helper functions
  • Structure that exploits standard basis functions, especially higher-order functions, and that avoids redundant case analysis

Your lambda code will be judged on correctness, form, naming, and documentation, but not so much on structure. In particular, because the lambda calculus is such a low-level language, we will especially emphasize names and contracts for helper functions .

This is low-level programming, and if you don’t get your code exactly right, the only way we can recognize and reward your learning is by reading the code. It’s your job to make it clear to us that even if your code isn’t perfect, you understand what you’re doing.

Try to write your contracts in terms of higher-level data structures and operations. For example, even though the following function does some fancy manipulation on terms, it doesn’t need much in the way of a contract:

Documenting lambda calculus is like documenting assembly code: it’s often sufficient to say what’s happening at a higher level of abstraction.

Although it is seldom ideal, it can be OK to use higher-level code to document your lambda code. In particular, if you want to use Scheme or ML to explain what your lambda code is doing, this can work only because Scheme and ML operate at much higher levels of abstraction. Don’t fall into the trap of writing the same code twice—if you are going to use code in a contract, it must operate at a significantly higher level of abstraction than the code it is trying to document.

In more detail, here are our criteria for names:

And here are our criteria for contracts:

Files link-lambda.sml and link-lambda-a.sml are copied into your directory by the compile105-lambda script. The others are created by you. ↩

They were more useful in 2017 then they are now—as always, Wikipedia pages are subject to change without notice. ↩

Try, for example, (\x.\y.x) A B; . ↩

I have botched capture-avoiding substitution multiple times. ↩

The laws, although notated differently, are identical to the laws given by Prakash Panangaden as Definition 1.3. ↩

This operator is an example of “Kleisli composition,” which is an advanced form of function composition. ↩

Notable Mathematicians

Henri lebesgue.

Henri Lebesgue was born on 28 June 1875 in Beauvais, Oise. Lebesgue's father was a typesetter and his mother was a school teacher. His parents assembled at home a library that the young Henri was able to use. His father died of tuberculosis when Lebesgue was still very young and his mother had to support him by herself. As he showed a remarkable talent for mathematics in primary school, one of his instructors arranged for community support to continue his education at the Collège de Beauvais and then at Lycée Saint-Louis and Lycée Louis-le-Grand in Paris.

Guido Fubini

Born in Venice, he was steered towards mathematics at an early age by his teachers and his father, who was himself a teacher of mathematics. In 1896 he entered the Scuola Normale Superiore di Pisa, where he studied under the notable mathematicians Ulisse Dini and Luigi Bianchi. He gained some early fame when his 1900 doctoral thesis, entitled Clifford's parallelism in elliptic spaces, was discussed in a widely read work on differential geometry published by Bianchi in 1902.

Nikolai Luzin

Nikolai Nikolaevich Luzin (also spelled Lusin; 9 December 1883 – 28 January 1950) was a Soviet/Russian mathematician known for his work in descriptive set theory and aspects of mathematical analysis with strong connections to point-set topology. He was the eponym of Luzitania, a loose group of young Moscow mathematicians of the first half of the 1920s. They adopted his set-theoretic orientation, and went on to apply it in other areas of mathematics.

Browse Course Material

Course info, instructors.

  • Adam Marcus

Departments

  • Electrical Engineering and Computer Science

As Taught In

  • Programming Languages
  • Software Design and Engineering

Learning Resource Types

Introduction to programming in java, assignment 4.

Problem set on building an electronic rental system for libraries with Java.

facebook

You are leaving MIT OpenCourseWare

IMAGES

  1. Java Programming Language: Beginner to Advanced Guide

    introduction to java programming assignments

  2. Read Introduction to Java Programming Online by Somasundaram and K.

    introduction to java programming assignments

  3. Introduction to Java Programming and Data Structures, Comprehensive

    introduction to java programming assignments

  4. PPT

    introduction to java programming assignments

  5. Introduction to Java Programming, Comprehensive Version, 10th Ed

    introduction to java programming assignments

  6. PART 1 Introduction to Java Programming

    introduction to java programming assignments

VIDEO

  1. Introduction to Programming in Java: Part 1

  2. PROGRAMMING IN JAVA WEEK 10

  3. NPTEL Week-8 || Java Programming || Programming Assignments || Solutions|| March 2024

  4. Assignment And Programming In Java Week 8 ,2024 All

  5. JAVA PROGRAMMING CLASS-01 (Introduction)

  6. Week 11 Programming Assignments Java

COMMENTS

  1. Introduction to Programming in Java · Computer Science

    Programming assignments. Creative programming assignments that we have used at Princeton. You can explore these resources via the sidebar at left. Introduction to Programming in Java. Our textbook Introduction to Programming in Java [ Amazon · Pearson · InformIT] is an interdisciplinary approach to the traditional CS1 curriculum with Java. We ...

  2. GitHub

    java computer-science javafx learning-by-doing java-programming programming-exercises programming-challenges core-java learning-java exercise-solutions introduction-to-programming algorithms-and-data-structures learning-resources practice-programming cs-fundamentals textbook-exercises introduction-to-java-programming learnjava

  3. Introduction to Programming Using Java

    Welcome to the Eighth Edition of Introduction to Programming Using Java, a free, on-line textbook on introductory programming, which uses Java as the language of instruction. This book is directed mainly towards beginning programmers, although it might also be useful for experienced programmers who want to learn something about Java. It is not meant to provide complete coverage of the Java ...

  4. Assignments

    Introduction to Programming in Java. Menu. More Info Syllabus Lecture Notes ... ASSN # ASSIGNMENTS SUPPORTING FILES 1 GravityCalculator GravityCalculator.java 2 FooCorporation 3 Marathon Marathon.java 4 Library Book.java . Library.java . 5 Graphics! initial.png ... assignment Programming Assignments. Download Course.

  5. Fundamentals of Java Programming

    Module 1 • 3 hours to complete. In the Java Fundamentals module, you will be introduced to the Java programming language, one of the most popular programming languages used for developing a wide range of applications. You will learn about the core components of the Java platform, including the Java Virtual Machine (JVM) and the Java class ...

  6. Introduction to Programming in Java

    This course is an introduction to software engineering, using the Java™ programming language. It covers concepts useful to 6.005. Students will learn the fundamentals of Java. The focus is on developing high quality, working software that solves real problems. The course is designed for students with some programming experience, but if you have none and are motivated you will do fine.

  7. PDF Introduction to Programming in Java

    plete Java programs and encourage readers to use them. We focus on programming by individuals, not library programming or programming in the large (which we treat briefly in an appendix). Use in the Curriculum This book is intended for a first-year college course aimed at teaching novices to program in the context of scientific applications.

  8. Introduction to Java

    The course will present you with a brief introduction to object-oriented programming that will help you delve deeper into the topic later. You will learn how to code Java and how to use one of the most popular development environments, Eclipse. The course will guide you so that, with both tools, you can begin to think about how to solve ...

  9. Introduction to Java and Object-Oriented Programming

    There are 3 modules in this course. This course provides an introduction to the Java language and object-oriented programming, including an overview of Java syntax and how it differs from a language like Python. Students will learn how to write custom Java classes and methods, and how to test their code using unit testing and test-driven ...

  10. Introduction to Programming in Java

    This is an interactive course in Java for first time programmers. It offers a scaffolding approach to learning, starting with the basics of computing and gradually progressing to fairly sophisticated problem solving such as binary search and insertion sort. All through this learning path, there are many assessment quizzes and programming ...

  11. Creative Programming Assignments

    Below are links to a number of creative programming assignments that we've used at Princeton. Some are from COS 126: Introduction to Computer Science; others are from COS 226: Data Structures and Algorithms . The main focus is on scientific, commercial, and recreational applications. The assignments are posed in terms of C or Java, but they ...

  12. Introduction to JAVA and object oriented programming course in coursera

    This repo contains my answers for the assignments and projects of Introduction to Java and Object-Oriented Programming by University of Pennsylvania.

  13. java

    I periodically teach an introduction to programming course using Java.I want to give my students some exciting assignments that they can relate to or find interesting.At the very least, I want assignments that make sense and have an internal cohesion (for example, some very bad programming exercises seem contrived just so that you have to use the most recent programming construct covered).

  14. Assignments

    Introduction to Programming in Java. Menu. More Info Syllabus Lecture Notes Assignments Related Resources Assignments. file. 1 kB Book. file. 2 kB BouncingBox. file ... assignment Programming Assignments. Download Course. Over 2,500 courses & materials Freely sharing knowledge with learners and educators around the world.

  15. Programming in Java

    Course layout. Week 1 : Overview of Object-Oriented Programming and Java. Week 2: Java Programming Elements. Week 3: Input-Output Handling in Java. Week 4: Encapsulation. Week 5: Inheritance. Week 6: Exception Handling. Week 7: Multithreaded Programming. Week 8: Java Applets and Servlets.

  16. Assignment 1

    Introduction to Programming in Java. Menu. More Info Syllabus Lecture Notes Assignments Related Resources Assignments. Assignment 1. Description: Problem set to create a Java program that computes the distance an object will fall in Earth's gravity. Resource Type: Assignments ... assignment Programming Assignments. Download Course.

  17. Lambda Calculus

    Programming in the lambda calculus (individual problems) These problems give you a little practice programming in the lambda calculus. Most functions must terminate in linear time, and you must do these exercises by yourself. You can use the reference interpreter linterp-nr.. Lambda-calculus programs work at the same intellectual level as assembly-language programs.

  18. PDF Met Cs 521

    development using the Python programming language. It includes a detailed discussion of programming concepts starting with the fundamentals of data types, control structures methods, classes, arrays and strings, and proceeding to advanced topics such as inheritance and polymorphism, creating user interfaces, exceptions and streams.

  19. Department of System Programming

    E-mail: [email protected]. Website: sp.cmc.msu.ru. Phone number: +7 (495) 939-18-77. Other contact information. The Department was founded in 1970 simultaneously with the CMC Faculty. The position of the head of Department was hold by the Distinguished Professor of the Moscow State University, Academician of the Russian Academy of Natural Sciences ...

  20. Assignment 5

    Introduction to Programming in Java. Menu. More Info Syllabus Lecture Notes ... Related Resources Assignments. Assignment 5. Description: Problem set on programming in Java, building software with objects, Java's built-in graphics, containers, and animation. Resource Type: ... assignment Programming Assignments. Download Course.

  21. Assignment Solution for Module 2

    Nikolai Luzin. Nikolai Nikolaevich Luzin (also spelled Lusin; 9 December 1883 - 28 January 1950) was a Soviet/Russian mathematician known for his work in descriptive set theory and aspects of mathematical analysis with strong connections to point-set topology. He was the eponym of Luzitania, a loose group of young Moscow mathematicians of the ...

  22. Assignment 3

    Introduction to Programming in Java. Menu. More Info Syllabus Lecture Notes Assignments Related Resources Assignments. Assignment 3. Description: Problem set on writing a Java method that takes as input an array of integers and returns the index corresponding to the lowest. ... assignment Programming Assignments. Download Course. Over 2,500 ...

  23. Assignment 4

    Introduction to Programming in Java. Menu. More Info Syllabus Lecture Notes Assignments Related Resources Assignments. Assignment 4. Description: ... assignment Programming Assignments. Download Course. Over 2,500 courses & materials Freely sharing knowledge with learners and educators around the world.