Academia.edu no longer supports Internet Explorer.
To browse Academia.edu and the wider internet faster and more securely, please take a few seconds to upgrade your browser.
…
751 pages
1 file
Introduction to Programming Using Java is a comprehensive, free textbook aimed at beginners in computer programming, leveraging Java as the primary teaching language. It covers fundamental and advanced programming concepts, structured in a way that facilitates both classroom learning and self-study, with an emphasis on procedural and object-oriented programming. The textbook includes programming exercises with detailed online solutions, making it a competitive alternative to traditional programming textbooks.
Foreword When planning a Java programming course in a school or even in a business context, the reduced number of hours available often has to be taken into account. A program that includes all aspects of the language is not feasible (for a much more extensive approach, from the syntactic point of view and for the topics dealt with, see note 3), but rather topics must be chosen with the aim of involving and also entertaining users, and hopefully encouraging to study the subject in greater depth in the future. Here we put forward a"possible method" (one of many) that has been repeatedly tested on many students. The method includes the advice to students to use the help and online help often (instructions on how to do this will be provided) to encourage autonomy in those who write programs from the outset. At the end, you will have learned to write some programs and be ready to start creating other projects (not exclusively in Java). The cognitive structures transmitted during the course are first and foremost linguistic structures. Noam Chomsky's Generative Transformational Grammar is the basic text from which the initial idea of the method started. In a 2001 interview, Dijkstra stated a desire for "elegance", whereby the correct approach would be to process thoughts mentally, rather than attempt to render them until they are complete. Here we can add that the constant correct use of formal language can contribute to the correct formulation of thoughts. If then, as in the case of Java, we are dealing with an object-oriented language, the syntactic structure contributes greatly to the organisation of thought. A linguistic model must therefore be proposed at the same time as the problem to be solved is presented, whether the problem is mathematical or otherwise. It is preferable to first analyse the algorithm in a discussion and then immediately formalise it in Java: no metalanguages or intermediate formal languages are needed as it could be misleading to isolate the problem from its final "linguistic solution". Finally, structured and functioning examples containing different linguistic constructs in relation to each other are analysed, and in this way more information is communicated to users than when single separate syntactic examples are used. Introduction From a technical point of view, every program in Java can be described as follows • It consists essentially of classes: the class is the linguistic unit that contains data (variables or properties) and operations (methods) on the data and it is recognisable because its name is preceded by the keyword class; • The classes are divided into packages, which group the classes according to their functionality (program start, graphics, mathematical or other operations and so on); • The classes are mutually related through two possible types of relationship: inheritance or composition; • Each class is given a constructor, a particular method that has the same name as the class, which is activated every time a class is created (with the instruction new) and contains all the instructions that must be executed first and only once each time the class is instantiated (created); • The call or activation of a class method by a method of another class can occur every time two classes are related (through inheritance or composition). If the method is public, the call can also be made from a class belonging to another package. Typically, when the program starts with a graphical interface (window), data is usually entered in the graphics package (frame) and this data is then processed by methods belonging to the classes of another package, whose name (mathematics, dictionaries, etc.) will be representative of the type of operations it contains; • At this point we provide the syntax tools that allow you to write any program as a set of classes in relation to each other, containing both data and operations on the data (see yes concept algebraic structure); • We provide information on the important concept of data encapsulation and introduce the use of the keyword private, thanks to which the data of a class are not directly accessible and modifiable by the operations of another class, for security reasons; • Use of get methods are introduced, followed by some setmethods. • We explain the fundamental concept of listener, which allows the program to interact with the operating system. • It should be noted that the language has many pre-defined class packages, which can be used by means of import instructions. • The imported classes that are often used include those that implement the basic data structures of computing: ArrayList, List, Hashmap, Map. In all the dictionaries created in the text examples, the HashMapis implemented, where the clear and constructive implementation of the function concept can be seen. Once the syntactic rules of language and the fundamental principles of object-oriented programminghave been learnt, with reference to examples written correctly in Java, the first step is to start writing programs by modifying or extending the available code, then, in the second step, code is created directly. The first step should not be omitted as, before starting to speak or write in a new language, it is essential to hear it spoken and see it written by those who have already mastered it. Learning syntactic rules is important but not sufficient, not even for a formal language. At the beginning the code writing method may involve a certain degree of automatism, for example a second button is created by observing how the first one was created, a class is instantiated and then a method is recalled, taking an example from a similar operation, and so on. It is in fact a constructive automatism, which helps to fix the essential basic linguistic models in the mind, which will then allow creative code to be generated later on. The correction of projects written by the students must be constant and immediate, in order to allow them to interact in a continuous manner with the code, which should lead to working programs as quickly as possible. When possible, hours of lectures can be reinforced by e-learning activities, thus using learning techniques in blended learning . Type 1 information containers For years we have called them e-books, even if the projects do not fully correspond to what is generally known as ebooks . Students create hundreds of them each year, choosing the multilingual, heterogeneous contents that most interest them . When they create these information containers that are interactive and can always be modified, they come into contact with very important aspects of language, including, not in order of importance: • Interfaces • Inheritance • XML files • String management • Redefinition of the paintComponent () method and use of the device context • Uploading images as wallpapers • Creation of multiple panels • Scroll management • HashMap, list, ArrayList and other Collections with parameterised types • The BufferedImage class and the getRGB () method with practical applications such as geographic maps (selection of a region by colour, etc.) • Use of the coordinates of an image to identify some of its parts (identification of planets and so on) • Links to websites through the URL and URI classes Finally arriving at the creation of a jar executable from any project, which can be run outside of an integrated environment and used on any computer on which the Java run-time has been installed. From a mathematical point of view, important concepts such as those of function and of algebraic structure can be seen applied in practice. As all this may be contained within a single program, we will be able to document it in detail. In any case, bringing together many significant aspects of language in one project helps to understand and remember them more easily.
These lecture notes are designed for use in the first year Computer Science modules at the University of KwaZulu-Natal. They provide an introduction to problem solving, programming, and the Java language. They are not intended to be complete in themselves but serve as a complement to the formal lectures, and students are urged to make use of the books referenced in addition to these notes.
Dr Ahmad, 2017
This introduction to programming places computer science in the core of a liberal arts education. Unlike other introductory books, it focuses on the program design process. This approach fosters a variety of skills--critical reading, analytical thinking, creative synthesis, and attention to detail--that are important for everyone, not just future computer programmers.
Solutions to the exercises in Programming with Mathematica: An Introduction are given here. The exercises to every section are listed first, followed by the solutions. Solutions are provided both as a PDF file and in notebook form at www.cambridge.org/wellin.
OOP concepts-Data abstraction-encapsulation-inheritance-benefits of inheritancepolymorphism-classes and objects-procedural and object oriented programming paradigm. Java programming -History of java-comments data types-variables-constants-scope and life time of variables-operators-operator hierarchy-expressions-type conversion and castingenumerated types-control flowblock scope-conditional statements-loops-break and continue statements-simple java stand alone programs-arrays-console input and output-formatting output-constructors-methods-parameter passing-static fields and methods-access control-this reference-overloading methods and constructors-recursion-garbage collection-building stringsexploring string class.
We have designed this third edition of Java, Java, Java to be suitable for a typical Introduction to Computer Science (CS1) course or for a slightly more advanced Java as a Second Language course. This edition retains the “objects first” approach to programming and problem solving that was characteristic of the first two editions. Throughout the text we emphasize careful coverage of Java language features, introductory programming concepts, and object-oriented design principles.
Loading Preview
Sorry, preview is currently unavailable. You can download the paper by clicking the button above.
ACM SIGCSE Bulletin, 1981