Programming in Java: Organising Your Code. Last delivered in 2016. All educational material listed or linked to on these pages in relation to King's College London may be provided for reference only, and therefore does not necessarily reflect the current course content.
In programming languages, a closure (also lexical closure or function closure) is a function or reference to a function together with a referencing environment as a block
This document contains 21 JavaScript interview questions related to topics such as:
1. The difference between undefined and not defined.
2. Examples testing output for functions, closures, and object properties.
3. Private methods, emptying arrays, checking array types, and function hoisting.
4. Operator behavior, typeof, delete, and instanceof.
5. Calculating the length of an associative array.
The document encourages checking answers and provides links to detailed explanations for each question.
The document discusses Java programming concepts such as classes, methods, strings, comments, and identifiers. It provides examples of Java code that declare classes with a main method and static methods that are called from main. It explains how to write comments to document code and describes syntax rules for identifiers, keywords, and strings. The document is intended to teach programmers how to write, compile, and run basic Java programs.
This begins your journey to java as a very beginner. Prerequisite of the audience is strong understanding of basic language fundamentals of C or C++ or C# .
This shows how one can use XMPP in one's Java coding to make an IM communication. It'd be really amusing to see your Facebook or Google chat in action with your own code.
The document discusses inheritance and polymorphism in Java programming. It covers key concepts like subclasses, superclasses, overriding methods, abstract classes, interfaces, and composition. Inheritance allows subclasses to inherit attributes and behaviors from superclasses. Polymorphism allows treating an object of a subclass as an object of its superclass, enabling late binding through overriding methods. The document provides examples and explanations of these object-oriented programming concepts in Java.
The document discusses interfaces in Java. It defines an interface as a syntactically similar to a class but lacking instance variables and having methods declared without bodies. Interfaces are defined using the interface keyword. A class implements an interface by providing implementations for all the interface's methods. Variables can be declared with an interface type and refer to any class that implements the interface, allowing polymorphic calls through interfaces.
In programming languages, a closure (also lexical closure or function closure) is a function or reference to a function together with a referencing environment as a block
This document contains 21 JavaScript interview questions related to topics such as:
1. The difference between undefined and not defined.
2. Examples testing output for functions, closures, and object properties.
3. Private methods, emptying arrays, checking array types, and function hoisting.
4. Operator behavior, typeof, delete, and instanceof.
5. Calculating the length of an associative array.
The document encourages checking answers and provides links to detailed explanations for each question.
The document discusses Java programming concepts such as classes, methods, strings, comments, and identifiers. It provides examples of Java code that declare classes with a main method and static methods that are called from main. It explains how to write comments to document code and describes syntax rules for identifiers, keywords, and strings. The document is intended to teach programmers how to write, compile, and run basic Java programs.
This begins your journey to java as a very beginner. Prerequisite of the audience is strong understanding of basic language fundamentals of C or C++ or C# .
This shows how one can use XMPP in one's Java coding to make an IM communication. It'd be really amusing to see your Facebook or Google chat in action with your own code.
The document discusses inheritance and polymorphism in Java programming. It covers key concepts like subclasses, superclasses, overriding methods, abstract classes, interfaces, and composition. Inheritance allows subclasses to inherit attributes and behaviors from superclasses. Polymorphism allows treating an object of a subclass as an object of its superclass, enabling late binding through overriding methods. The document provides examples and explanations of these object-oriented programming concepts in Java.
The document discusses interfaces in Java. It defines an interface as a syntactically similar to a class but lacking instance variables and having methods declared without bodies. Interfaces are defined using the interface keyword. A class implements an interface by providing implementations for all the interface's methods. Variables can be declared with an interface type and refer to any class that implements the interface, allowing polymorphic calls through interfaces.
Get More on http://www.ManzoorTheTrainer.com
This eBook contains 109 important interview questions along with answers that any web developer looking for a job on MS.Net platform needs to know. This eBook starts with two articles one of which talks about why most of the engineers are jobless and the other say the solution for it. As a technical part I have covered the following MS.Net technologies ASP.Net, C#.Net & ADO.Net and MS SQL Server.
Second edition is also on the way with focus on at least one real time example on each question.
Key features: Point to point | Simple language
This document discusses abstract classes and interfaces in Java. It begins by defining an interface and how to declare methods in an interface. It then discusses how to implement an interface in a class. The document notes that unlike abstract classes, interfaces can only contain abstract methods and constants. It explains that interfaces allow for multiple inheritance in Java while abstract classes do not. The key differences between abstract classes and interfaces are summarized. Finally, it provides some guidelines on class design and recommends next steps for learning additional Java topics after understanding object-oriented programming fundamentals.
This document provides an introduction to basic Java programming concepts such as programs, programming languages, compiling and running Java programs, and Java syntax. It explains that a Java program consists of a class containing a main method with print statements. Various Java concepts are defined, such as identifiers, keywords, strings, escape sequences, and syntax errors. Examples of Java print statements and their output are provided.
Templates and Exception Handling in C++Nimrita Koul
This document discusses templates and exception handling in C++. It provides an overview of templates, including why they are used for generic programming and how to define function and class templates. Exception handling in C++ uses try, catch, and throw blocks. The try block contains code that may throw exceptions, catch blocks handle specific exceptions, and throw explicitly throws an exception. The document contains examples of templates, exception handling, and derived class exceptions. It also discusses opportunities available at the School of CIT at Reva University.
Programming in Java: Storing Data. Last delivered in 2016. All educational material listed or linked to on these pages in relation to King's College London may be provided for reference only, and therefore does not necessarily reflect the current course content.
Polymorphism in Java allows an object to take on multiple forms. There are two types of polymorphism: compile-time polymorphism (method overloading) and runtime polymorphism (method overriding). Method overloading involves methods with the same name but different parameters, while method overriding involves subclasses providing their own implementation of a superclass method. Runtime polymorphism determines which version of a method to call based on the object's actual type at runtime. Abstraction in Java allows hiding implementation details and showing only essential functionality through the use of abstract classes and methods.
Inheritance and polymorphism are key object-oriented programming concepts supported in C#. Inheritance allows a child class to inherit properties and behaviors from a parent class. Polymorphism refers to classes having different implementations of the same method, allowing the method to behave differently depending on the object that calls it. Virtual methods allow subclasses to override behaviors of parent classes, while the new keyword is used to hide inherited methods instead of overriding them.
in this tutorial we will discuss about
exception handling in C#
Exception class
creating user-defined exception
throw keyword
finally keyword
with examples'
Programming in Java: Why Object-Orientation?Martin Chapman
Programming in Java: Why Object-Orientation? Last delivered in 2016. All educational material listed or linked to on these pages in relation to King's College London may be provided for reference only, and therefore does not necessarily reflect the current course content.
This document provides an introduction to basic Java programming concepts such as programs, programming languages, compiling and running Java programs, and key elements like classes, methods, and print statements. It explains Java features like data types, variables, operators, conditional statements, and loops. Examples of simple Java programs are provided to demonstrate printing output and using strings, escape sequences, and comments.
This document provides an introduction to Java programming concepts such as data types, variables, operators, input/output, control flow, methods, and classes. It explains what computer science and programming are, gives examples of basic Java programs using print statements, and discusses programming fundamentals like program structure, naming conventions, comments, and static methods. Methods are introduced as a way to organize code and eliminate redundancy. Overall, the document orients the reader to fundamental Java programming concepts.
This document provides an introduction to Java programming. It discusses what computer science and programming are, and introduces basic Java concepts like classes, methods, and print statements. It also covers data types, variables, operators, and control structures that allow programmers to write algorithms and programs. The document uses examples like simple print programs and a cookie baking algorithm to demonstrate core Java programming concepts.
This document provides an overview of creating and running a simple "Hello World" Java program. It explains the anatomy of a Java class, including the need for every program to have a public static void main method. It demonstrates how to name, save, compile, and run a Java file containing a main method that prints output. Key concepts covered include Java syntax like semicolons, comments, and variable declaration. The document also introduces control structures like if/else statements and while loops. Homework assigned is to practice writing pseudocode and experimenting with a first Java program in Eclipse.
The document discusses methods in Java programming. It explains that methods can be used to divide large blocks of code into smaller, more manageable pieces by grouping related lines of code into reusable functions. This improves readability and maintainability of programs. The document provides examples of using methods without and with parameters and return values. It also covers defining your own methods and using methods from Java library classes.
This document provides an overview of the steps to create a basic Java program. It discusses:
1) Using a text editor or IDE to write Java code in a .java file, compiling it to bytecode with the Java compiler, and running the bytecode with the Java interpreter.
2) The main() method signature including access modifiers, return type, name, and string array parameter.
3) Example code of a simple Java program in Notepad++ including the class name, main method, and use of System.out.println to print output.
The document provides code examples for several Java programming concepts:
1. A program that takes command line arguments, calculates the sum and average of the numbers passed, and displays the results.
2. A Student class with member functions to read and display student details like name and age.
3. A Square class with data members for length, area, and perimeter, and member functions to read, compute values, and display details.
The document contains 10 additional examples covering topics like inheritance, packages, exceptions, threads, and GUI programming.
1. The document discusses library classes and methods in the String class in Java.
2. It explains that Strings are immutable class objects, not primitive types, and the Java Virtual Machine can optimize memory usage by sharing String objects between variables when the literal is the same.
3. When comparing Strings for equality, the equals method should be used instead of the == operator, as == checks for reference equality rather than value equality of Strings.
This document provides an introduction to Java programming concepts including:
- Java is both a programming language and platform that is simple, architecture neutral, object-oriented, and portable.
- Java source code is written in .java files and compiled into .class files by javac before being executed by the Java Virtual Machine (JVM).
- The JVM allows Java programs to run on any platform without recompilation, providing platform independence.
- Key Java concepts covered include objects, classes, methods, variables, data types, operators, control flow, and arrays.
- Examples demonstrate how to write, compile, and run simple Java programs to illustrate these core programming concepts.
Desing pattern prototype-Factory Method, Prototype and Builder paramisoft
The document discusses three design patterns: Factory Method, Prototype, and Builder. Factory Method defines an interface for creating objects but lets subclasses decide which class to instantiate. Prototype specifies the kinds of objects to create using a prototypical instance that new objects can be cloned from. Builder separates the construction of a complex object from its representation so that the same construction process can create different representations.
Objectives Assignment 09 Applications of Stacks COS.docxdunhamadell
The document provides instructions for Assignment 09, which involves implementing four functions that use a stack data structure:
1. doParenthesisMatch() checks if a string of parentheses is properly matched and returns a boolean.
2. decodeIDSequence() decodes a string of 'I's and 'D's into a minimum number string without repeated digits.
3. insertItemOnSortedStack() inserts an item into a sorted stack.
4. sortStack() sorts an unsorted stack recursively.
Students are provided header and implementation files for a Stack ADT and tests, and must implement the functions in the given files while following style guidelines. The assignment evaluates correct implementation of the functions and stack usage,
you will learn how to create your own methods with or without return values, invoke a method with or without parameters, and apply method abstraction in the program design.
This document discusses code refactoring. It defines code refactoring as restructuring existing code without changing its external behavior. Reasons for refactoring include improving code design and reducing technical debt. Techniques include extracting methods, generalizing types, and moving code between classes. Tools like IDEs can assist with automated refactoring. Refactoring is often done in conjunction with test-driven development to iteratively improve code quality and extensibility.
Get More on http://www.ManzoorTheTrainer.com
This eBook contains 109 important interview questions along with answers that any web developer looking for a job on MS.Net platform needs to know. This eBook starts with two articles one of which talks about why most of the engineers are jobless and the other say the solution for it. As a technical part I have covered the following MS.Net technologies ASP.Net, C#.Net & ADO.Net and MS SQL Server.
Second edition is also on the way with focus on at least one real time example on each question.
Key features: Point to point | Simple language
This document discusses abstract classes and interfaces in Java. It begins by defining an interface and how to declare methods in an interface. It then discusses how to implement an interface in a class. The document notes that unlike abstract classes, interfaces can only contain abstract methods and constants. It explains that interfaces allow for multiple inheritance in Java while abstract classes do not. The key differences between abstract classes and interfaces are summarized. Finally, it provides some guidelines on class design and recommends next steps for learning additional Java topics after understanding object-oriented programming fundamentals.
This document provides an introduction to basic Java programming concepts such as programs, programming languages, compiling and running Java programs, and Java syntax. It explains that a Java program consists of a class containing a main method with print statements. Various Java concepts are defined, such as identifiers, keywords, strings, escape sequences, and syntax errors. Examples of Java print statements and their output are provided.
Templates and Exception Handling in C++Nimrita Koul
This document discusses templates and exception handling in C++. It provides an overview of templates, including why they are used for generic programming and how to define function and class templates. Exception handling in C++ uses try, catch, and throw blocks. The try block contains code that may throw exceptions, catch blocks handle specific exceptions, and throw explicitly throws an exception. The document contains examples of templates, exception handling, and derived class exceptions. It also discusses opportunities available at the School of CIT at Reva University.
Programming in Java: Storing Data. Last delivered in 2016. All educational material listed or linked to on these pages in relation to King's College London may be provided for reference only, and therefore does not necessarily reflect the current course content.
Polymorphism in Java allows an object to take on multiple forms. There are two types of polymorphism: compile-time polymorphism (method overloading) and runtime polymorphism (method overriding). Method overloading involves methods with the same name but different parameters, while method overriding involves subclasses providing their own implementation of a superclass method. Runtime polymorphism determines which version of a method to call based on the object's actual type at runtime. Abstraction in Java allows hiding implementation details and showing only essential functionality through the use of abstract classes and methods.
Inheritance and polymorphism are key object-oriented programming concepts supported in C#. Inheritance allows a child class to inherit properties and behaviors from a parent class. Polymorphism refers to classes having different implementations of the same method, allowing the method to behave differently depending on the object that calls it. Virtual methods allow subclasses to override behaviors of parent classes, while the new keyword is used to hide inherited methods instead of overriding them.
in this tutorial we will discuss about
exception handling in C#
Exception class
creating user-defined exception
throw keyword
finally keyword
with examples'
Programming in Java: Why Object-Orientation?Martin Chapman
Programming in Java: Why Object-Orientation? Last delivered in 2016. All educational material listed or linked to on these pages in relation to King's College London may be provided for reference only, and therefore does not necessarily reflect the current course content.
This document provides an introduction to basic Java programming concepts such as programs, programming languages, compiling and running Java programs, and key elements like classes, methods, and print statements. It explains Java features like data types, variables, operators, conditional statements, and loops. Examples of simple Java programs are provided to demonstrate printing output and using strings, escape sequences, and comments.
This document provides an introduction to Java programming concepts such as data types, variables, operators, input/output, control flow, methods, and classes. It explains what computer science and programming are, gives examples of basic Java programs using print statements, and discusses programming fundamentals like program structure, naming conventions, comments, and static methods. Methods are introduced as a way to organize code and eliminate redundancy. Overall, the document orients the reader to fundamental Java programming concepts.
This document provides an introduction to Java programming. It discusses what computer science and programming are, and introduces basic Java concepts like classes, methods, and print statements. It also covers data types, variables, operators, and control structures that allow programmers to write algorithms and programs. The document uses examples like simple print programs and a cookie baking algorithm to demonstrate core Java programming concepts.
This document provides an overview of creating and running a simple "Hello World" Java program. It explains the anatomy of a Java class, including the need for every program to have a public static void main method. It demonstrates how to name, save, compile, and run a Java file containing a main method that prints output. Key concepts covered include Java syntax like semicolons, comments, and variable declaration. The document also introduces control structures like if/else statements and while loops. Homework assigned is to practice writing pseudocode and experimenting with a first Java program in Eclipse.
The document discusses methods in Java programming. It explains that methods can be used to divide large blocks of code into smaller, more manageable pieces by grouping related lines of code into reusable functions. This improves readability and maintainability of programs. The document provides examples of using methods without and with parameters and return values. It also covers defining your own methods and using methods from Java library classes.
This document provides an overview of the steps to create a basic Java program. It discusses:
1) Using a text editor or IDE to write Java code in a .java file, compiling it to bytecode with the Java compiler, and running the bytecode with the Java interpreter.
2) The main() method signature including access modifiers, return type, name, and string array parameter.
3) Example code of a simple Java program in Notepad++ including the class name, main method, and use of System.out.println to print output.
The document provides code examples for several Java programming concepts:
1. A program that takes command line arguments, calculates the sum and average of the numbers passed, and displays the results.
2. A Student class with member functions to read and display student details like name and age.
3. A Square class with data members for length, area, and perimeter, and member functions to read, compute values, and display details.
The document contains 10 additional examples covering topics like inheritance, packages, exceptions, threads, and GUI programming.
1. The document discusses library classes and methods in the String class in Java.
2. It explains that Strings are immutable class objects, not primitive types, and the Java Virtual Machine can optimize memory usage by sharing String objects between variables when the literal is the same.
3. When comparing Strings for equality, the equals method should be used instead of the == operator, as == checks for reference equality rather than value equality of Strings.
This document provides an introduction to Java programming concepts including:
- Java is both a programming language and platform that is simple, architecture neutral, object-oriented, and portable.
- Java source code is written in .java files and compiled into .class files by javac before being executed by the Java Virtual Machine (JVM).
- The JVM allows Java programs to run on any platform without recompilation, providing platform independence.
- Key Java concepts covered include objects, classes, methods, variables, data types, operators, control flow, and arrays.
- Examples demonstrate how to write, compile, and run simple Java programs to illustrate these core programming concepts.
Desing pattern prototype-Factory Method, Prototype and Builder paramisoft
The document discusses three design patterns: Factory Method, Prototype, and Builder. Factory Method defines an interface for creating objects but lets subclasses decide which class to instantiate. Prototype specifies the kinds of objects to create using a prototypical instance that new objects can be cloned from. Builder separates the construction of a complex object from its representation so that the same construction process can create different representations.
Objectives Assignment 09 Applications of Stacks COS.docxdunhamadell
The document provides instructions for Assignment 09, which involves implementing four functions that use a stack data structure:
1. doParenthesisMatch() checks if a string of parentheses is properly matched and returns a boolean.
2. decodeIDSequence() decodes a string of 'I's and 'D's into a minimum number string without repeated digits.
3. insertItemOnSortedStack() inserts an item into a sorted stack.
4. sortStack() sorts an unsorted stack recursively.
Students are provided header and implementation files for a Stack ADT and tests, and must implement the functions in the given files while following style guidelines. The assignment evaluates correct implementation of the functions and stack usage,
you will learn how to create your own methods with or without return values, invoke a method with or without parameters, and apply method abstraction in the program design.
This document discusses code refactoring. It defines code refactoring as restructuring existing code without changing its external behavior. Reasons for refactoring include improving code design and reducing technical debt. Techniques include extracting methods, generalizing types, and moving code between classes. Tools like IDEs can assist with automated refactoring. Refactoring is often done in conjunction with test-driven development to iteratively improve code quality and extensibility.
This document discusses methods in Java programming. It defines a method as a block of code that performs a specific task, similar to a function. There are standard library methods provided by Java and user-defined methods that programmers can create. The document provides examples of calling methods and how they can accept arguments and return values. It also discusses the advantages of using methods such as code reusability.
TypeScript - Silver Bullet for the Full-stack DevelopersRutenis Turcinas
TypeScript lets you write JavaScript the way you really want to Its a typed superset of JavaScript that compiles to plain JavaScript. Any browser. Any host. Any OS. Open Source. Enjoy writing JavaScript.
import java.util.Scanner;Henry Cutler ID 1234 7202.docxwilcockiris
import java.util.Scanner;
/*
Henry Cutler ID 1234 7/20/2015
Assignment #5, 3 features in 1 program
Solution
for Assignment#5 COP2800
Pseudocode:
Program has three features, all in a single program that are user selectable.
Prompt with options and get user choice inside a while statement ( true )
If 1 is entered:
Using a while and for loop, print out the ASCII table from ! to ~.
If 2 is entered:
Prompt the user for number of times to flip for head or tails using the random method. Count number of each and when the request times are done, print out the results.
If 3 is entered:
Prompt the user for a strings and print back the count of vowels and letters
Any other input entered program will exit using a break statement, otherwise loops back to prompt user for feature selection.
*/
public class Module5 {
public static void main(String[] args) {
// prompt the user
System.out.println("Welcome to Henry\'s 3 in 1 Programming Assignment for Module 5\n");
// create Scanner Object
Scanner input = new Scanner(System.in);
// loop until break
while(true){
// new lines for readability
System.out.print("\n");
// Prompt user for choices
System.out.print("Enter 1 for ASCII Table \nEnter 2 for Heads or Tails\nEnter 3 for Count Vowels & Letters\nAny other input will exit");
int choice = input.nextInt();
// Consume newline left-over
input.nextLine();
// first feature
if(choice == 1){
// start value is !
int value = (int) '!';
// newline for formating
System.out.println("You Selected ASCII Table!\n");
// start at ~ which is 33 decimal
while( value <= '~')
{
// print out 20 in a line
for( int count = 0; count < 20; count ++ ){
if( value <= '~'){
// print single value
System.out.print( (char) value++ );
}
else {
// break when we are at last char to print
break;
}
}
// New line every 10
System.out.print("\n");
}
// New line at exit
System.out.print("\n");
}
else if(choice == 2){
// Prompt user
System.out.println("You Selected Head or Tails!");
System.out.println("\nHow many flips would you like to try?");
// get value
int count = input.nextInt();
// clear
input.nextLine();
int headCount = 0;
int tailCount = 0;
// run for a count provided by user
for (int i = 0; i < count; i++) {
// get random number
if (Math.random() > 0.5){
// increment heads
headCount++;
}
else {
// increment tails
tailCount++;
}
}
System.out.println("Head count: " + headCount + " tail count: " + tailCount);
}
else if(choice == 3){
// Prompt user
Sys.
1. The document discusses getting started with programming in Java, including compiling and running a simple "Hello World" Java program. It explains that a Java program is written as source code in a .java file, then compiled using the javac compiler into a .class file, which is run by the Java Virtual Machine (java).
2. It provides the code for a simple "Hello World" Java program consisting of a main method that prints the text, and explains some key aspects like class and file names.
3. It describes using the terminal to navigate directories and run the javac compiler and java programs, as well as downloading the Java Development Kit for the compiler and JVM.
1) The document provides an introduction to programming with the maXbox tool. It explains the interface and how to load sample code.
2) The sample code checks if numbers are prime by using a function called checkPrim() within a procedure called TestPrimNumbers(). It saves the results to a file.
3) The main routine calls TestPrimNumbers(), saves the output list to a file, loads the file, and displays the results along with performance times. This demonstrates functions, procedures, file I/O, and other basic programming concepts.
Similar to Programming in Java: Organising Your Code (20)
Principles of Health Informatics: Artificial intelligence and machine learningMartin Chapman
Principles of Health Informatics: Artificial intelligence and machine learning. Last delivered in 2024. All educational material listed or linked to on these pages in relation to King's College London may be provided for reference only, and therefore does not necessarily reflect the current course content.
Principles of Health Informatics: Clinical decision support systemsMartin Chapman
Principles of Health Informatics: Clinical decision support systems. Last delivered in 2024. All educational material listed or linked to on these pages in relation to King's College London may be provided for reference only, and therefore does not necessarily reflect the current course content.
Mechanisms for Integrating Real Data into Search Game Simulations: An Applica...Martin Chapman
This document describes using search game models to explore complex public health issues like winter health service pressures. It discusses integrating real demographic and behavioral data into search game simulations to more accurately model these issues. An example application looks at modeling family resource acquisition challenges during winter and evaluating government intervention strategies to reduce pressures and inequalities. Integrating multiple real datasets allows configuring the search game model to replicate observed winter trends and assess intervention performance. The results suggest advising families is most effective at reducing health service utilization and disparities.
Technical Validation through Automated TestingMartin Chapman
The document discusses applying automated testing tools to the development of phenotypes to help ensure they operate correctly. It outlines how testing can be used at different stages of phenotype development: (1) during authoring by testing computable phenotype definitions, (2) during implementation by integrating testing frameworks, and (3) during validation as an additional validation technique through test cases. The document argues there is potential for more widespread use of automated testing in phenotype development similar to software development.
Scalable architectures for phenotype librariesMartin Chapman
The document discusses different architectural considerations for building phenotype libraries that are accessible at a large scale. It covers software architecture, definition structure, and distribution mechanisms. For software architecture, it advocates for a microservices approach to allow components to be built with different technologies and scaled independently. For definition structure, it presents Phenoflow's model that standardizes definitions and generates computable forms. For distribution, it notes the benefits of hosting definitions in version control systems like GitHub to improve discoverability. The overall goal is to make definitions easily located, downloaded, and interpreted by many users through careful library design.
Using AI to autonomously identify diseases within groups of patientsMartin Chapman
This FYP presentation discusses using AI to autonomously identify diseases within patient groups. The main functions are using a workflow to identify diseases, validating results with gold/silver standards, and using machine learning algorithms to generate silver standards from electronic health record data. The standard workflow requires installing tools like Cwltool and docker and providing test cases and gold references, while unsupervised learning algorithms generate silver standards from provided EHR data without supervision. Supervised learning additionally needs test cases, gold references, and unclassified data.
Using AI to understand how preventative interventions can improve the health ...Martin Chapman
Using AI and large UK datasets, the author digitally mimicked household environments of children and young people from different backgrounds to simulate preventative policy interventions and predict their effectiveness at improving health and reducing winter pressures on the NHS. The simulations found that issuing continued government advice during winter months could potentially reduce health utilization and disparities between socio-economic groups.
Principles of Health Informatics: Evaluating medical softwareMartin Chapman
Principles of Health Informatics: Evaluating medical software. Last delivered in 2023. All educational material listed or linked to on these pages in relation to King's College London may be provided for reference only, and therefore does not necessarily reflect the current course content.
Principles of Health Informatics: Usability of medical softwareMartin Chapman
Principles of Health Informatics: Usability of medical software. Last delivered in 2023. All educational material listed or linked to on these pages in relation to King's College London may be provided for reference only, and therefore does not necessarily reflect the current course content.
Principles of Health Informatics: Social networks, telehealth, and mobile healthMartin Chapman
Principles of Health Informatics: Social networks, telehealth, and mobile health. Last delivered in 2023. All educational material listed or linked to on these pages in relation to King's College London may be provided for reference only, and therefore does not necessarily reflect the current course content.
Principles of Health Informatics: Communication systems in healthcareMartin Chapman
Principles of Health Informatics: Communication systems in healthcare. Last delivered in 2023. All educational material listed or linked to on these pages in relation to King's College London may be provided for reference only, and therefore does not necessarily reflect the current course content.
Principles of Health Informatics: Terminologies and classification systemsMartin Chapman
Principles of Health Informatics: Terminologies and classification systems. Last delivered in 2023. All educational material listed or linked to on these pages in relation to King's College London may be provided for reference only, and therefore does not necessarily reflect the current course content.
Principles of Health Informatics: Informatics skills - searching and making d...Martin Chapman
This document discusses principles for searching for data and making decisions based on data from an informatics perspective. It covers search strategies for finding specific data within large datasets, using logical inference like deduction, abduction and induction to determine implications of new data, and using Bayes' theorem to update probabilities of outcomes when receiving new data while accounting for prior probabilities and sample sizes. Decision trees are presented as a way to combine multiple probabilities and include preferences through utilities to determine the highest utility decision.
Principles of Health Informatics: Informatics skills - communicating, structu...Martin Chapman
Principles of Health Informatics: Informatics skills - communicating, structuring, and questioning. Last delivered in 2023. All educational material listed or linked to on these pages in relation to King's College London may be provided for reference only, and therefore does not necessarily reflect the current course content.
Principles of Health Informatics: Models, information, and information systemsMartin Chapman
Principles of Health Informatics: Models, information, and information systems. Last delivered in 2023. All educational material listed or linked to on these pages in relation to King's College London may be provided for reference only, and therefore does not necessarily reflect the current course content.
Using AI to understand how preventative interventions can improve the health ...Martin Chapman
Living in cold, damp homes can lead to poor health in children such as chest conditions and mental health problems in adolescents. With energy costs rising and wages not keeping pace with inflation, health issues for children and young people may worsen due to families' inability to afford home heating. An AI model was used to simulate how government advice and interventions could potentially reduce health care utilization and disparities between socioeconomic groups, though further validation is needed before implementing related policies.
Using Microservices to Design Patient-facing Research SoftwareMartin Chapman
Using microservices allows patient-facing research software to address challenges in software development, modularity, and processing time. The microservices architecture separates a system into individual communicating services, each providing a single functionality. This allows different languages to be used, logic to be replaced with minimal impact, and long execution times to be isolated. The CONSULT system demonstrates these benefits through its use of microservices to integrate data from various sources and provide decision support for stroke patients.
Using CWL to support EHR-based phenotypingMartin Chapman
This document describes a new Common Workflow Language (CWL)-based model for structuring electronic health record (EHR)-based phenotype definitions. Phenotype definitions are complex and lack standardization. The proposed model addresses this by representing definitions as workflows with abstract, functional, and computational layers. Non-standard definitions can be parsed and automatically generated as CWL workflows using the Phenoflow architecture. This standardizes definitions and makes them portable and reproducible.
Leveraging Generative AI to Drive Nonprofit InnovationTechSoup
In this webinar, participants learned how to utilize Generative AI to streamline operations and elevate member engagement. Amazon Web Service experts provided a customer specific use cases and dived into low/no-code tools that are quick and easy to deploy through Amazon Web Service (AWS.)
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...Diana Rendina
Librarians are leading the way in creating future-ready citizens – now we need to update our spaces to match. In this session, attendees will get inspiration for transforming their library spaces. You’ll learn how to survey students and patrons, create a focus group, and use design thinking to brainstorm ideas for your space. We’ll discuss budget friendly ways to change your space as well as how to find funding. No matter where you’re at, you’ll find ideas for reimagining your space in this session.
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPRAHUL
This Dissertation explores the particular circumstances of Mirzapur, a region located in the
core of India. Mirzapur, with its varied terrains and abundant biodiversity, offers an optimal
environment for investigating the changes in vegetation cover dynamics. Our study utilizes
advanced technologies such as GIS (Geographic Information Systems) and Remote sensing to
analyze the transformations that have taken place over the course of a decade.
The complex relationship between human activities and the environment has been the focus
of extensive research and worry. As the global community grapples with swift urbanization,
population expansion, and economic progress, the effects on natural ecosystems are becoming
more evident. A crucial element of this impact is the alteration of vegetation cover, which plays a
significant role in maintaining the ecological equilibrium of our planet.Land serves as the foundation for all human activities and provides the necessary materials for
these activities. As the most crucial natural resource, its utilization by humans results in different
'Land uses,' which are determined by both human activities and the physical characteristics of the
land.
The utilization of land is impacted by human needs and environmental factors. In countries
like India, rapid population growth and the emphasis on extensive resource exploitation can lead
to significant land degradation, adversely affecting the region's land cover.
Therefore, human intervention has significantly influenced land use patterns over many
centuries, evolving its structure over time and space. In the present era, these changes have
accelerated due to factors such as agriculture and urbanization. Information regarding land use and
cover is essential for various planning and management tasks related to the Earth's surface,
providing crucial environmental data for scientific, resource management, policy purposes, and
diverse human activities.
Accurate understanding of land use and cover is imperative for the development planning
of any area. Consequently, a wide range of professionals, including earth system scientists, land
and water managers, and urban planners, are interested in obtaining data on land use and cover
changes, conversion trends, and other related patterns. The spatial dimensions of land use and
cover support policymakers and scientists in making well-informed decisions, as alterations in
these patterns indicate shifts in economic and social conditions. Monitoring such changes with the
help of Advanced technologies like Remote Sensing and Geographic Information Systems is
crucial for coordinated efforts across different administrative levels. Advanced technologies like
Remote Sensing and Geographic Information Systems
9
Changes in vegetation cover refer to variations in the distribution, composition, and overall
structure of plant communities across different temporal and spatial scales. These changes can
occur natural.
How to Fix the Import Error in the Odoo 17Celine George
An import error occurs when a program fails to import a module or library, disrupting its execution. In languages like Python, this issue arises when the specified module cannot be found or accessed, hindering the program's functionality. Resolving import errors is crucial for maintaining smooth software operation and uninterrupted development processes.
Main Java[All of the Base Concepts}.docxadhitya5119
This is part 1 of my Java Learning Journey. This Contains Custom methods, classes, constructors, packages, multithreading , try- catch block, finally block and more.
A review of the growth of the Israel Genealogy Research Association Database Collection for the last 12 months. Our collection is now passed the 3 million mark and still growing. See which archives have contributed the most. See the different types of records we have, and which years have had records added. You can also see what we have for the future.
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...PECB
Denis is a dynamic and results-driven Chief Information Officer (CIO) with a distinguished career spanning information systems analysis and technical project management. With a proven track record of spearheading the design and delivery of cutting-edge Information Management solutions, he has consistently elevated business operations, streamlined reporting functions, and maximized process efficiency.
Certified as an ISO/IEC 27001: Information Security Management Systems (ISMS) Lead Implementer, Data Protection Officer, and Cyber Risks Analyst, Denis brings a heightened focus on data security, privacy, and cyber resilience to every endeavor.
His expertise extends across a diverse spectrum of reporting, database, and web development applications, underpinned by an exceptional grasp of data storage and virtualization technologies. His proficiency in application testing, database administration, and data cleansing ensures seamless execution of complex projects.
What sets Denis apart is his comprehensive understanding of Business and Systems Analysis technologies, honed through involvement in all phases of the Software Development Lifecycle (SDLC). From meticulous requirements gathering to precise analysis, innovative design, rigorous development, thorough testing, and successful implementation, he has consistently delivered exceptional results.
Throughout his career, he has taken on multifaceted roles, from leading technical project management teams to owning solutions that drive operational excellence. His conscientious and proactive approach is unwavering, whether he is working independently or collaboratively within a team. His ability to connect with colleagues on a personal level underscores his commitment to fostering a harmonious and productive workplace environment.
Date: May 29, 2024
Tags: Information Security, ISO/IEC 27001, ISO/IEC 42001, Artificial Intelligence, GDPR
-------------------------------------------------------------------------------
Find out more about ISO training and certification services
Training: ISO/IEC 27001 Information Security Management System - EN | PECB
ISO/IEC 42001 Artificial Intelligence Management System - EN | PECB
General Data Protection Regulation (GDPR) - Training Courses - EN | PECB
Webinars: https://pecb.com/webinars
Article: https://pecb.com/article
-------------------------------------------------------------------------------
For more information about PECB:
Website: https://pecb.com/
LinkedIn: https://www.linkedin.com/company/pecb/
Facebook: https://www.facebook.com/PECBInternational/
Slideshare: http://www.slideshare.net/PECBCERTIFICATION
This slide is special for master students (MIBS & MIFB) in UUM. Also useful for readers who are interested in the topic of contemporary Islamic banking.
2. To understand how to organise code
• In the same file
• Into different files
ORGANISING YOUR CODE: OBJECTIVES
2
3. Each file can only contain one public class.
The name of this class must match the name of the file in
which the class resides.
Therefore, at this stage, we will consider classes to be
roughly equivalent to files.
• One file for each class.
• Later on in the course, we’ll see that this isn’t strictly
true.
REMEMBER: CLASSES AND FILES
3
5. REMEMBER: A SLIGHTLY MORE COMPLEX PROGRAM
5
public class MartinPrinter {
public static void main(String[] args) {
System.out.println("+------+");
System.out.println("|Martin|");
System.out.println("+------+");
}
}
When we have more than one line in a program, the program
is executed line-by-line.
MartinPrinter.java
6. Being self-centred, I want to print my name three times to
the terminal.
Cool.
CODE REPETITION (1)
6
public class MartinPrinter {
public static void main(String[] args) {
System.out.println("+------+");
System.out.println("|Martin|");
System.out.println("+------+");
System.out.println("+------+");
System.out.println("|Martin|");
System.out.println("+------+");
System.out.println("+------+");
System.out.println("|Martin|");
System.out.println("+------+");
}
} MartinPrinter.java
8. System.out.println("+------+");
System.out.println("|Martin|");
System.out.println("+------+");
It would be useful if we could somehow label our print statement code,
it wouldn’t execute until we specifically said to, and we could call it as
many times as we like (3 times, for example).
LABELLING CODE (1)
8
`Print Martin’:
Go to `Print Martin’
Go to `Print Martin’
Go to `Print Martin’
We would still have to reference the label
(later, we’ll see how we can address this
issue), but the reference is simpler, it
would reduce the lines we need by a third,
and we would only have to write the print
code once.
9. These steps are not yet in a language that the computer can
understand.
We’re expressing or designing the solution we want using
written English.
We call this pseudocode.
There is no particular standard pseudocode syntax
(although efforts have been made to construct a standard
language), but personal consistency is important.
You will be expected to write pseudocode for your
assignment documentation (see KEATS).
ASIDE: PSEUDOCODE
9
10. 🙈
If we were to be able to do the below, we would no longer be
executing our code line-by-line. We would start at the arrow,
and then:
EXECUTION ORDER
10
System.out.println("+------+");
System.out.println("|Martin|");
System.out.println("+------+");
`Print Martin’:
Go to `Print Martin’
Go to `Print Martin’
Go to `Print Martin’
The arrow returns to the next `go to’
statement after each Martin is printed
because the JVM must execute all of
our requested lines of code.
11. Fortunately, we can do just this in Java by creating something called a method.
METHODS
11
public class MartinPrinter {
public static void printMartin() {
System.out.println("+------+");
System.out.println("|Martin|");
System.out.println("+------+");
}
public static void main(String[] args) {
printMartin();
printMartin();
printMartin();
}
}
We’ve already
seen a main
method.
This is now one of our
own methods and we can
have as many as we like.
MartinPrinter.java
12. Methods provide us with the labels we saw in the previous example in
the form of named sections of code.
METHODS: AN EXAMPLE (1) (LABELS)
12
public class MartinPrinter {
public static void printMartin() {
System.out.println("+------+");
System.out.println("|Martin|");
System.out.println("+------+");
}
public static void main(String[] args) {
printMartin();
printMartin();
printMartin();
}
}
`Print Martin’:
Go to `Print Martin’
Go to `Print Martin’
Go to `Print Martin’
MartinPrinter.java
The methods in a
class can be
called by any
other method in
that class
(usually).
13. 🙈
We block off our code accordingly, so it is clear where these sections are.
METHODS: AN EXAMPLE (1) (BLOCKED OFF CODE)
13
public class MartinPrinter {
public static void printMartin() {
System.out.println("+------+");
System.out.println("|Martin|");
System.out.println("+------+");
}
public static void main(String[] args) {
printMartin();
printMartin();
printMartin();
}
}
Note the merit of
indentation once
multiple
methods are
introduced.
Everything is
still within
the same
class (the
same file).
MartinPrinter.java
14. 🙈
When we want to run the code within a method, we write the name of the method
(including the brackets) and Java matches the correct place for execution to move to.
METHODS: AN EXAMPLE (1) (CALLING A METHOD)
14
public class MartinPrinter {
public static void printMartin() {
System.out.println("+------+");
System.out.println("|Martin|");
System.out.println("+------+");
}
public static void main(String[] args) {
printMartin();
printMartin();
printMartin();
}
}
Like matching method names, much of Java’s
control structure is about matching labels.
The location of
the target
method in the
class (before or
after) is
unimportant.
Unlike class names,
which are typically
nouns, methods names
are typically verbs
because they do
something.
MartinPrinter.java
We’ll discuss
the function of
the brackets
after the name
of the method
shortly.
As such, for now, we will implement methods
with unique names to avoid match conflicts.
15. 🙈
Thus, the program runs as seen previously:
METHODS: AN EXAMPLE (1) (EXECUTION ORDER)
15
public class MartinPrinter {
public static void printMartin() {
System.out.println("+------+");
System.out.println("|Martin|");
System.out.println("+------+");
}
public static void main(String[] args) {
printMartin();
printMartin();
printMartin();
}
} MartinPrinter.java
Even though the
JVM is asked to
move to a different
place in the
program to execute
code, it cannot just
ignore other
statements that
have been entered
into our main
method. Thus, it
moves back to
execute them.
17. 😴
It’s true that by labelling our code, we are able to facilitate the alteration of the
execution order of our program.
• Currently this allows us to call the same code multiple times within the
same class.
• I always aim to show you what certain syntax gives us in practice.
But also, more abstractly, when we label our code, we split our code into
distinct sections.
• This allows us to separate functionality in our class.
• Each method should perform a specific task.
• Thus, methods may only be used once.
We will see examples of this when we look at larger pieces of code.
METHODS AS A TOOL FOR CODE ORGANISATION (1)
17
18. Let’s write a class called , which contains a
method that prints the result of the second
millionth prime number (32452843) minus the first millionth
prime number (15485863).
Let’s call our method twice.
The syntax for subtraction is available in Topic 2.
LECTURE EXERCISE: LARGE PRIMES (1)
18
LargePrimes
subtractPrimes
19. LECTURE EXERCISE: LARGE PRIMES (2)
19
public class LargePrimes {
public static void subtractPrimes() {
System.out.println(32452843 - 15485863);
}
public static void main(String[] args) {
subtractPrimes();
subtractPrimes();
}
}
20. 😴
We still aren’t really in a position to talk about public or static.
METHODS: AN EXAMPLE (1) (PUBLIC AND STATIC)
20
public class MartinPrinter {
public static void printMartin() {
System.out.println("+------+");
System.out.println("|Martin|");
System.out.println("+------+");
}
public static void main(String[] args) {
printMartin();
printMartin();
printMartin();
}
}
But, for now, it’s important to know that
any method called from a static method
must also be static.
MartinPrinter.java
21. But we can talk about void.
METHODS: AN EXAMPLE (1) (RETURN TYPES)
21
public class MartinPrinter {
public static void printMartin() {
System.out.println("+------+");
System.out.println("|Martin|");
System.out.println("+------+");
}
public static void main(String[] args) {
printMartin();
printMartin();
printMartin();
}
} MartinPrinter.java
22. I mentioned earlier that much of Java’s control structure
works with matching labels.
When something can be matched it can also be substituted (if
possible).
• e.g. Y = X, X = 7
• We can match X, substitute it for 7, and end up with Y = 7.
• Let’s code this…
METHOD RETURN VALUES (SUBSTITUTION) (1)
22
23. 🙈
METHOD RETURN VALUES (SUBSTITUTION) (2)
23
Y = X, X = 7 so Y = 7
public class Substitutor {
public static void X() {
return 7;
}
public static void main(String[] args) {
int y = X();
System.out.println(y);
}
} (This will not compile)
X = 7Y = X Y = 7
?
?
24. 🙈
METHOD RETURN VALUES (THE RETURN KEYWORD)
24
public class Substitutor {
public static void X() {
return 7;
}
public static void main(String[] args) {
int y = X();
System.out.println(y);
}
} (This will not compile)
When we use the
keyword return in
a method, any
matched
references to that
method will be
substituted by the
value given after
the return
statement.
The method
becomes the value
it returns.
7;
Return almost
always has to
be the last
action in a
method.
25. We noted previously that Java forces us to declare the type of
variables.
METHOD RETURN VALUES (RETURN TYPES) (1)
25
This allows assignment errors to be caught at compile time, and
increases the readability of our code.
The same is true of methods: we must specify which type of value will
be substituted if we call that method.
• This allows Java to check that we are doing sensible things with
the returned values, like not assigning them to unreasonable
types.
• From the previous example:
return 7; int y = X();
int myFirstIntegerVariable
7.07.0;
26. METHOD RETURN VALUES (RETURN TYPES) (2)
26
public class Substitutor {
public static void X() {
return 7;
}
public static void main(String[] args) {
int y = X();
System.out.println(y);
}
} (This will not compile)
So in reality, this
code will not work
if we continue to
use void.
Void means we do
not intend to
return anything,
which is clearly not
true in this case.
27. 🙈
METHOD RETURN VALUES (RETURN TYPES) (3)
27
public class Substitutor {
public static int X() {
return 7;
}
public static void main(String[] args) {
int y = X();
System.out.println(y);
}
} (This will compile; Substitutor.java)
Instead we need to
change void to the
type of data we
intend to return.
In this case int.
28. 🙈
METHODS: FLOW OF DATA
28
public class Substitutor {
public static int X() {
return 7;
}
public static void main(String[] args) {
int y = X();
System.out.println(y);
}
} Substitutor.java
It might be useful
to think about the
return value
following a path
back to the place
in which it was
called.
7
29. public class MartinPrinter {
public static void printMartin() {
System.out.println("+------+");
System.out.println("|Martin|");
System.out.println("+------+");
}
public static void main(String[] args) {
printMartin();
printMartin();
printMartin();
}
} MartinPrinter.java
Back in MartinPrinter however, it is perfectly acceptable to write void
as we do not have a return statement.
SUBSTITUTION DOESN’T ALWAYS OCCUR
29
Moreover, the
method’s function
does not necessitate
a return value.
Thus, there is no real substitution
in this instance.
30. 🤐
ASIDE: WHAT HAPPENS WHEN YOU CALL A METHOD
30
All the storage elements pertinent to a method are pushed onto
an abstract stack structure, and then popped off once the method
finishes, and we return to where we started.
main
printMartin
31. Let’s alter the operation of so that it
instead returns the result of subtracting two prime numbers,
rather than simply printing the result.
We can then print inside the main method (twice).
LECTURE EXERCISE: LARGE PRIMES (3)
31
subtractPrimes
32. LECTURE EXERCISE: LARGE PRIMES (4)
32
public class LargePrimes {
public static int subtractPrimes() {
return 67867967 - 49979687;
}
public static void main(String[] args) {
System.out.println(subtractPrimes());
System.out.println(subtractPrimes());
}
}
33. 😴
WE’RE STARTING TO BUILD UP A TEMPLATE FOR METHODS
33
public static int X() {
return 7;
}
Methods, so
far, have to be
public and
static.
We specify the
return type We give our
method a name
What about these
brackets?
34. So far we have considered what methods output (return).
METHODS: INPUT AND OUTPUT
34
System.out.println("+------+");
System.out.println("| |");
System.out.println("+------+");
?
return 7;
What about method input?
What if I didn’t just want to print `Martin’ in a box to the
screen, but any number, an arbitrary number of times?
35. AIM: BOXED NUMBERS
35
I don’t just want to reuse the same code, I want to alter its
operation, in some small way.
36. 🙈
It would be useful if we could not only label the code, but
also provide placeholders for information to be filled in later.
LABELLING CODE (2)
36
System.out.println("+------+");
System.out.println("| |");
System.out.println("+------+");
`Print number’:
<NUM>
Go to `Print number’ set NUM = 1
Go to `Print number’ set NUM = 2
Go to `Print number’ set NUM = 3
123
38. Fortunately, we can do just this in Java.
METHODS: AN EXAMPLE (2)
38
public class NumberPrinter {
public static void printNumber(int num) {
System.out.println("+------+");
System.out.println("|" + num + "|");
System.out.println("+------+");
}
public static void main(String[] args) {
printNumber(1);
printNumber(2);
printNumber(3);
}
}
`Print number’:
Go to `Print number’
Go to `Print number’
Go to `Print number’
<NUM>
set NUM = 1
set NUM = 2
set NUM = 3
NumberPrinter.java
39. 😴
Whenever a piece of text (e.g. ) is added, using the plus symbol,
to a variable (or another piece of text), and then printed to the
terminal, they will appear side-by-side.
This is known as concatenation (loosely).
Open questions:
• Where else does concatenation occur?
• Is this the only way in which the `+’ symbol is used?
• How is a variable converted to text?
ASIDE: CONCATENATION (1)
39
"|"
In this example, you will see the following syntax:
System.out.println("|" + num + "|");
41. METHODS: AN EXAMPLE (2) (BRACKETS)
41
public class NumberPrinter {
public static void printNumber(int num) {
System.out.println("+------+");
System.out.println("|" + num + "|");
System.out.println("+------+");
}
public static void main(String[] args) {
printNumber(1);
printNumber(2);
printNumber(3);
}
}
Let’s talk about the brackets.
NumberPrinter.java
42. We use the brackets at the end of a method to define our
placeholders (e.g. <NUM>).
• These are variable declarations, of a form you should be
familiar with from Topic 2.
PARAMETERS
42
• We call these placeholder variable declarations parameters.
Once defined, these parameters (placeholders) can be referenced
anywhere inside the method.
If we want to replace our parameters with values (like replacing
<NUM> with the values 1, 2 and 3 previously) we have to assign
values to these parameters.
printNumber(int num) {
43. METHODS: AN EXAMPLE (2) (PASSING DATA) (1)
43
public class NumberPrinter {
public static void printNumber(int num) {
System.out.println("+------+");
System.out.println("|" + num + "|");
System.out.println("+------+");
}
public static void main(String[] args) {
printNumber(1);
printNumber(2);
printNumber(3);
}
}
To assign a parameter, we have to call the method
with a value written in brackets next to it.
NumberPrinter.java
44. 🙈
Remember that changing Java execution order, for simple method
calls, relies on matching labels; we have to match the method name
(and the brackets) in order to call the method and alter the flow of
the program.
MATCHING LABELS
44
public static void printName() {
printName();
public static void printNumber(int number) {
printNumber(1);
This same is true for methods with parameters: we have to match
the name, the existence of a parameter and the type of the
parameter in order to call the method.
The format of a method is often
referred to as its signature.
45. METHODS: AN EXAMPLE (2) (PASSING DATA) (2)
45
public class NumberPrinter {
public static void printNumber(int num) {
System.out.println("+------+");
System.out.println("|" + num + "|");
System.out.println("+------+");
}
public static void main(String[] args) {
printNumber(1);
printNumber(2);
printNumber(3);
}
}
When this line is executed, the method will be matched (name, brackets, value and type),
and any data in the brackets will be pushed to the waiting parameters of the method.
NumberPrinter.java
46. METHODS: AN EXAMPLE (2) (PASSING DATA) (3)
46
public class NumberPrinter {
public static void printNumber(int num = 1) {
System.out.println("+------+");
System.out.println("|" + num + "|");
System.out.println("+------+");
}
public static void main(String[] args) {
printNumber(1);
printNumber(2);
printNumber(3);
}
}
Thus we effectively transform the parameter into an assigned variable.
(Not real Java code.)
47. 🙈
METHODS: AN EXAMPLE (2) (PASSING DATA) (4)
47
public class NumberPrinter {
public static void printNumber(1) {
System.out.println("+------+");
System.out.println("|" + 1 + "|");
System.out.println("+------+");
}
public static void main(String[] args) {
printNumber(1);
printNumber(2);
printNumber(3);
}
}
As such, we effectively transform all references to this parameter into the
value that is pushed.
(Not real Java code.)
3
3
2
2
1
1
We then repeat for the
remaining calls, and receive
the desired output…
49. 🙈
METHODS AND PARAMETERS: FLOW OF DATA
49
Again, It can be helpful to think about data flowing through the program.
public class NumberPrinter {
public static void printNumber(int num) {
System.out.println("+------+");
System.out.println("|" + num + "|");
System.out.println("+------+");
}
public static void main(String[] args) {
printNumber(1);
printNumber(2);
printNumber(3);
}
}
1
NumberPrinter.java
We will show data
flow like this again.
50. 😴
So we now know that methods offer us (within the same
class) the ability to:
• Use the same code multiple times.
• Separate functionality.
• Use the same code in different ways.
METHODS AS A TOOL FOR CODE ORGANISATION (2)
50
51. 😴
A further matching constraint: the number of parameters must
be the same and the types must be in the same order.
The parameter syntax gives us a lot of freedom.
We can write a method with as many parameters as we like.
MULTIPLE PARAMETERS
51
But we can only ever return one thing (not equivalent to value).
• Otherwise, which returned entity would we substitute the
call to the method with?
public static void printNumber(int num1, double num2) {
printNumber(1, 1.0);
53. Let’s evolve the functionality from our class
into a new class that contains a method which
allows us to subtract any two numbers from each other.
Then, let’s subtract 15485863 from 32452843 again, and then
go ahead and subtract 49979687 from 67867967.
LECTURE EXERCISE: SUBTRACTION (1)
53
LargePrimes
Subtractor
54. LECTURE EXERCISE: SUBTRACTION (2)
54
public class Subtractor {
public static void subtract(int firstOperand, int secondOperand) {
System.out.println(firstOperand - secondOperand);
}
public static void main(String[] args) {
subtract(32452843, 15485863);
subtract(67867967, 49979687);
}
}
Anytime we now want to perform a subtraction in our class, we can simply
call the subtract method (because we’re lazy).
Open question: Should we
print the result, or return it
for printing?
55. 😴
So far, we’ve only passed literal values to our methods, but
there’s no reason we can’t pass variables instead, as the
matching rules relating to type are still maintained.
PASS BY REFERENCE VS. PASS BY VALUE (1)
55
When we do this, a natural question to ask is, if we change
the passed variable inside the method, does the original
value change?
int numberOne = 1;
printNumber(numberOne);
printNumber(1);
56. 🖥
Caveat: This is quite a weak example, more to come.
PASS BY REFERENCE VS. PASS BY VALUE (2)
56Topic3-1
public class NumberChanger {
public static void changeNumber(int changeMe) {
changeMe = 2;
}
public static void main(String[] args) {
int numberOne = 1;
changeNumber(numberOne);
System.out.println(numberOne);
}
}
Will the print
statement print 1 or
2?
Does Java pass the
variable itself (the
reference) or a copy
of the value held in
the variable?
Try this out in the
lab.NumberChanger.java
57. We now know a little bit more about main.
• We know that main can never return anything (where would it go
anyway?)
• This is a parameter, so main must accept some information.
• But unfortunately, we still aren’t in a position to discuss what is
passed to the main method.
• And of course poor old public and static are neglected again.
BACK TO MAIN
57
public static void main(String[] args) {
58. 🖥
Type out all the method syntax we have seen (which you should
be doing anyway), and annotate each method with a brief
description of what that method does:
METHOD ANNOTATION
58Topic3-2
/**
* Prints the supplied number surrounded by a box.
*/
public static void printNumber(int num) {
System.out.println("+------+");
System.out.println("|" + num + "|");
System.out.println("+------+");
}
59. ASIDE: COMMENT TYPES
59
public static void printNumber(int num) {
System.out.println("+------+");
System.out.println("|" + num + "|");
System.out.println("+------+");
}
// Previously we use single line methods to annotate our code
/* We can also use multi-line comments, if we like,
* which start with a single star after a slash.
*/
/**
* For methods, we should use special documentation comments,
* which start with a double star after a slash.
*/
60. 🖥
Once you’ve typed out all the methods and added documentation
comments you should try and break things.
• Remove parameters, remove names, change names, change
return types. Call the method in different ways.
BREAKING THE RULES, AGAIN
60Topic3-2
• Use single line comments to make notes for yourself again.
// We can't call methods with a non-castable type
changeNumber(1.0);
62. So far, we’ve introduced two key methods, one for printing
Martin…
MARTIN PRINTER AND NUMBER PRINTER (1)
62
public class MartinPrinter {
public static void printMartin() {
System.out.println("+------+");
System.out.println("|Martin|");
System.out.println("+------+");
}
public static void main(String[] args) {
printMartin();
printMartin();
printMartin();
}
} MartinPrinter.java
63. …and one for printing numbers.
MARTIN PRINTER AND NUMBER PRINTER (2)
63
public class NumberPrinter {
public static void printNumber(int num) {
System.out.println("+------+");
System.out.println("|" + num + "|");
System.out.println("+------+");
}
public static void main(String[] args) {
printNumber(1);
printNumber(2);
printNumber(3);
}
}
NumberPrinter.java
64. I kept these methods in distinct classes (in different files) to
enable you to run most of the examples you find
independently, in the laboratory sessions.
But what if we wanted to call both of these methods from
the same main method?
• We want to print `Martin’ followed by his IQ (191).
MARTIN PRINTER AND NUMBER PRINTER (3)
64
printMartin();
printNumber(191);
65. SEPARATING FUNCTIONALITY
65
Because we can have as many methods as we wish in a class,
we could just move these methods into the same class and call
them from the same main method.
Issues with this? What would we call this class?
It was actually
quite nice having
separate
functionality in
different classes,
while using the
class name as a
label for that
functionality.
public class {
public static void printMartin() {
System.out.println("+------+");
System.out.println("|Martin|");
System.out.println("+------+");
}
public static void printNumber(int num) {
System.out.println("+------+");
MartinPrinterAndNumberPrinter
66. There’s also the risk of saturating a single class with too
many methods (remember we can have as many methods in
a class as we wish).
What’s the solution?
TOO MANY METHODS
66
67. 🤓
The solution is to have have neither
__________________ in the same class as the main method!
Instead, we create a new class that will only hold the main method.
We are going to call this class Driver because it is going to drive
the rest of the code in our program, and serve as a hub for making
things happen.
This class will communicate with both the and
_______________classes from which we will remove the main
method.
• If we’re trying to run multiple pieces of code in different files,
typically we can only have one main method.
SEPARATING OUT THE MAIN METHOD INTO A DRIVER CLASS (1)
67
printMartin() or
printNumber(int num)
NumberPrinter
MartinPrinter
68. Stored in a file called MartinPrinter.java
SEPARATING OUT THE MAIN METHOD INTO A DRIVER CLASS (2)
68
public class MartinPrinter {
public static void printMartin() {
System.out.println("+------+");
System.out.println("|Martin|");
System.out.println("+------+");
}
}
69. SEPARATING OUT THE MAIN METHOD INTO A DRIVER CLASS (3)
69
public class NumberPrinter {
public static void printNumber(int num) {
System.out.println("+------+");
System.out.println("|" + num + "|");
System.out.println("+------+");
}
}
Stored in a file called NumberPrinter.java
70. SEPARATING OUT THE MAIN METHOD INTO A DRIVER CLASS (4)
70
public class Driver {
public static void main(String[] args) {
}
}
Stored in a file called Driver.java
71. ASIDE: FILES, CLASSES AND FOLDERS
71
If you wish to use the code from one class in another class
without any additional code, those classes must be in the
same folder.
72. SEPARATING OUT THE MAIN METHOD INTO A DRIVER CLASS (4)
72
public class Driver {
public static void main(String[] args) {
}
}
What now?
printMartin();
printNumber(191);
Stored in a file called Driver.java
74. 🤓
If we want to access a method in another class (file), we have to go
through a very specific process.
This process involves making a copy of all the code in that class and
storing it inside a variable (!).
We can then interact with the copied code through the variable in order
to call methods within that code.
ACCESSING A METHOD IN ANOTHER CLASS (FILE)
74
75. 🙈
LET’S IMAGINE WHAT THIS MIGHT LOOK LIKE…
75
public class Driver {
public static void main(String[] args) {
copyOfMartinPrinter
}
}
Type
Driver.java
This is our special variable
declaration, which is still a type
followed by a name (we have chosen).
76. 😴
public class Driver {
public static void main(String[] args) {
copyOfMartinPrinter
}
}
Remember that for something to be a variable it must have
a type followed by a name.
Given that we have a variable, storing a copy of a class, what
should the type of this variable be?
THE VARIABLE TYPE USED TO STORE A COPY OF A CLASS (1)
76
Type
Driver.java
77. 😴
public class Driver {
public static void main(String[] args) {
copyOfMartinPrinter
}
}
The answer is the name of the class we’re copying.
This makes sense because a variable type describes (the
format of) what the variable will contain (in this case a copy of
a particular class).
THE VARIABLE TYPE USED TO STORE A COPY OF A CLASS (2)
77
TypeMartinPrinter
Driver.java
78. 🙈
public class Driver {
public static void main(String[] args) {
MartinPrinter copyOfMartinPrinter
}
}
MAKING A COPY OF A CLASS
78
new MartinPrinter();
Driver.java
=
How do we do this?
We need to request a new copy of the class. We use the labelled name of
the class so that Java is able to match the class we want.
Then we need to put this copy inside the variable, using an assignment,
in the same way that we put values inside variables.
We will call a variable that contains a copy of a class an object.
(We’ll come back to what the
brackets mean).
79. This process is called making an object of a class, and
forms the foundation of object-oriented programming.
79
80. 🤓
If we want to access a method in another class (file), we have to go
through a very specific process.
This process involves making a copy of all the code in that class and
storing it inside a variable (!).
We can then interact with the copied code through the variable in order
to call methods within that code.
ACCESSING A METHOD IN ANOTHER CLASS (FILE)
80
81. In order to interact with the code stored in a variable (object),
and thus call methods, we need to open the variable (object)
up and look inside.
To do this we write our variable (object) name and then a dot.
INTERACTING WITH COPIES OF CLASSES (OBJECTS) (1)
81
public class Driver {
public static void main(String[] args) {
MartinPrinter copyOfMartinPrinter
}
}
new MartinPrinter();=
copyOfMartinPrinter.
Driver.java
82. When we write a dot after an object (a variable containing a
copy of a class), we can see inside the object, into the
copied class, and have the option to reference any of the
(public) identifiers within it.
INTERACTING WITH COPIES OF CLASSES (OBJECTS) (2)
82
public class Driver {
public static void main(String[] args) {
MartinPrinter copyOfMartinPrinter
copyOfMartinPrinter.
}
}
new MartinPrinter();=
printMartin();
In other words, we can call any
of the methods within the copy.
Driver.java
83. INTERACTING WITH COPIES OF CLASSES (OBJECTS) (3)
83
public class MartinPrinter {
public static void printMarti
System.out.println("+-----
System.out.println("|Marti
System.out.println("+-----
}
}
copyOfMartinPrinter.
To reiterate: The dot is an
entry point through the
object into the class copy
through which we
reference items in that
copy of the class.
84. public class Driver {
public static void main(String[] args) {
MartinPrinter copyOfMartinPrinter = new MartinPrinter();
copyOfMartinPrinter.printMartin();
NumberPrinter copyOfNumberPrinter = new NumberPrinter();
copyOfNumberPrinter.printNumber(191);
}
}
Driver.java
ACHIEVING OUR GOAL
84
• We want to print `Martin’ followed by his IQ (191).
I’m using blank lines here more liberally than
usual, in order to make my code clearer.
When accessing a method through an object,
we call methods with parameters in exactly
the same way.
85. THE OUTPUT
85
Note that we only need to compile the driver class directly, the
compiler will automatically compile any other referenced classes.
86. 🙈
ASIDE: DOCUMENTING OUR CODE WITH CLASS DIAGRAMS
86
The names of the classes
You can ignore these for now
You will need to produce these diagrams (i.e. draw them yourselves) as
part of your documentation for each assignment.
Now that we have a program of reasonable structural complexity, it’s
useful to have a documentation technique to visualise our class structure.
The names of the methods
Parameters return values
87. 😴
public class MartinPrinter {
public static void printMartin() {
System.out.println("+------+");
System.out.println("|Martin|");
System.out.println("+------+");
}
}
public class NumberPrinter {
public static void printNumber(int num) {
System.out.println("+------+");
System.out.println("|" + num + "|");
System.out.println("+------+");
Methods have to be static if they are called from a method
that is also static.
ONE FINAL THING: REMEMBER OUR RULE ABOUT STATIC
87
Because these
methods are now
being called
through an object
we can drop the
static keyword.
88. Object-oriented purists would be angry that I’m only selling
classes (and their associated objects) as a way to organise
code, because the idea is much more powerful.
• But I think this is a good initial way to understand
things.
• We will gradually see more important reasons for using
classes and objects going forward.
If any of the further information on objects and classes
confuses you, just come back to this idea that an object is
just a copy of the code in a class.
CLASSES AND OBJECTS
88
89. 🤐
ASIDE: OBJECTS IN MEMORY
89
In reality, unlike primitive values, objects are stored in
another area of the JVM’s memory known as the heap. The
variable containing the copy of the class is actually a
memory reference from a variable on the stack to an object
on the heap.
We’ll look at
this in more
detail next
semester.
We will use the definition of an object quite loosely in the first
semester of PPA, in order to simplify things, and help your initial
understanding.
90. Let’s wrap the `Hello World’ functionality from Topic 1 (i.e. a
single print statement printing `Hello World’) in a method
called , within a class called ,
and then make an object of this class in a ______ class in
order to call the method.
LECTURE EXERCISE: HELLO WORLD (1)
90
printHelloWorld
Driver
HelloWorld
printHelloWorld
91. LECTURE EXERCISE: HELLO WORLD (2)
91
public class HelloWorld {
public void printHelloWorld() {
System.out.println("Hello World");
}
}
public class Driver {
public static void main(String[] args) {
HelloWorld copyOfHelloWorld = new HelloWorld();
copyOfHelloWorld.printHelloWorld();
}
}
92. Dr. Martin Chapman
programming@kcl.ac.uk
martinchapman.co.uk/teaching
Programming Practice and Applications (4CCS1PPA)
Topic 3: Organising Your Code
These slides will be available on KEATS, but will be subject to
ongoing amendments. Therefore, please always download a new
version of these slides when approaching an assessed piece of work,
or when preparing for a written assessment. 92
Thursday 6th October