1 / 29

Programming for Beginners

Programming for Beginners. Lecture 1: Introduction: Program Structure & Java Syntax. Martin Nelson Elizabeth FitzGerald. Aims & objectives of this course. Write your own programmes in a procedural language

mabyn mabyn
Download Presentation

Programming for Beginners

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming for Beginners Lecture 1: Introduction: Program Structure & Java Syntax Martin Nelson Elizabeth FitzGerald

  2. Aims & objectives of this course • Write your own programmes in a procedural language • Understand basic concepts such as procedural logic, variables, flow control, input and output principles • Identify important programming concepts

  3. Course website • Course materials, exercises and useful web links can be found at: www.maths.nottingham.ac.uk/~pmzmn/GSTPFB.html

  4. Session 1 - aims & objectives • Appreciate how computer programs are constructed • Understand the differences between: • Compiled and interpreted languages • Procedural and object-oriented languages • Find out the basics of Java programming • Write a few simple programs making use of statements, comments and basic arithmetic

  5. Computer programmes • Set of instructions for the CPU • “Switch settings” • Machine language • Assembly language • Mnemonics representing binary code • Assembler • 3rd generation languages • “High level” languages • Compiled or interpreted (or both!)

  6. High Level Languages (3GL) • Examples: • Fortran • COBOL • Pascal • C • C++ • C# • Java

  7. Program construction • Computers are 'stupid' • Mathematical and logical instructions are executed very quickly and accurately • They obediently but stupidly do what you tell them to – not necessarily what you want them to! • Tiny errors in a program can cause major problems when it is executed • Careful planning is essential • Flow charts are a useful tool to represent program flow visually

  8. Algorithms • Algorithm = how you go about solving a puzzle; your solution to a task • Example: how do you make a cup of tea? • In programming, you should plan your algorithm before you start coding • Boil kettle • Put tea in cup • Pour boiling water into cup

  9. Tea-making program – 1 No Is kettle full? Fill kettle Yes Boil kettle Pour boiling water into cup Put tea in cup

  10. Fill kettle Boil kettle Place kettle under tap Plug kettle into electrical socket Open tap Switch kettle on Wait Wait No No Is kettle full? Has kettle boiled? Yes Yes Close tap Pour water into cup Elements of tea-making program

  11. Tea-making program – 2 No Is kettle full? Yes Pour boiling water into cup Put tea in cup

  12. Now for some jargon… (… but don’t worry about this too much  ) • Compiled vs interpreted languages Handy hint:If you’re not sure what these and other words mean, look at the ‘Glossary’ section of the course website

  13. Compiled languages Data storage Source code Machine code CPU/memory Compiler Program execution

  14. Interpreted languages Data storage Source code CPU/memory Interpreter Machine code Program execution

  15. Compiled vs interpreted • Compiled • Development more cumbersome • Easy to distribute • Machine code generated at compile timee.g. most high-level languages Interpreted • Easy to develop • Distribution of interpreter required • Machine code generated at runtimee.g. BASIC, LISP, Perl

  16. The Java model • Java is an object-oriented high level language • "write once, run anywhere" • It is both compiled and interpreted • Java source code has .java extension • Source code is compiled to produce a .class file (bytecode) – not human-readable • Bytecode is interpreted by the Java VM (virtual machine)

  17. How Java works Data storage Bytecode myprogram.class Source code myprogram.java CPU/memory Interpreter Compiler Machine code Program execution

  18. A bit more jargon… (… nearly finished though  ) • Procedural vs object-oriented programmes What is all this object-oriented stuff about? Does it matter? Does it mean anything?

  19. Procedural vs object-oriented Procedural • Early high-level languages • Contain functions (or sub-routines) written and used inside the main program • Cannot use external functions easily Object-oriented (OO) • Later high-level languages • Contain methods (or functions) and variables that can be written in main or external programs • Can call external functions or variables easily

  20. Some examples Procedural • Fortran • COBOL (old versions) • Pascal • C • Perl Object-oriented (OO) • COBOL (latest version) • Delphi • C++ • C# • Java • Visual Basic • Perl

  21. What’s Java all about then? • NOT the same as JavaScript • Java SDK consists of 2 components: • Java VM (Virtual Machine) • Java API (Application Programming Interface)+ accompanying documentation • If you alter your code you need to re-compile it before you can run the program • ONLY use Java version 2 and above (Java 1.2/Java 1.3/Java 1.4 etc)

  22. On with the code! • Quick intro to using Java • Then YOU start to code your first Java program!

  23. Writing your first Java program • Use a text editor to write the source code • Save it as a .java file • Compile it using Java SDK on Granby • You need to have a Granby account before you can start writing your programs – if you haven't you will need to apply for one as soon as possible!

  24. 'Hello world' program in Java class myprog { public static void main(String[] args) { System.out.println(“Hello world!”); } }

  25. Be careful what you type! • If you type something wrong, your code will either give you an error or won’t work properly. • If you get an error, check the following: • Capital letters are different to lower case – don’t mix them up. • { }, ( ) and [ ] all do different things – have you used the right one? • Some lines need to end with a semi-colon – miss them off and your code won’t work.

  26. Code Presentation Tips – 1 • Indent code inside curly braces • Every time you open a pair of curly braces, indent the next line by 1 tab or three/four spaces. • When you close braces, unindent. • You can then see straight away if you have a brace missing. class myprog { Some code Some more code { New braces, so indent again. } More code }

  27. Code Presentation Tips – 2 • You can add comments to your code to remind you (or someone else) how the code works. • Comments are ignored by the compiler. • On a single line, anything after // will be ignored. • Over many lines, anything between /* and */ will be ignored. /* This is my first java code * I really enjoyed writing it – I hope you like it */ class myprog { public static void main(String[] args) { // The following line will say hello System.out.println(“Hello!”); } }

  28. Code Presentation Tips – 3 • Comments should be brief and helpful. • No need to add comments which state the obvious. • Blank lines help to make the code readable – use them to separate each of the code’s tasks.

  29. Coming up in Session 2... • Using variables to store information. • An introduction to the range of data types available.

More Related

玻璃钢生产厂家玻璃钢西瓜雕塑图片南通佛像玻璃钢雕塑河南大型商场美陈市场价郑州关公玻璃钢雕塑批发商场美陈 杭州招聘玻璃钢蝎子雕塑价格房山春节商场吊饰美陈玻璃钢卡通雕塑制造商吉林酒店玻璃钢雕塑公司澳门校园玻璃钢雕塑一般多少钱安宁生产玻璃钢雕塑厂家哪家好玻璃钢雕塑能电镀吗玻璃钢小熊雕塑深圳周年庆典商场美陈采购玻璃钢雕塑什么材质做的洛阳市玻璃钢雕塑生产厂家无机玻璃钢花盆制作工艺铜玻璃钢雕塑安徽创意玻璃钢雕塑多少钱眉山玻璃钢动物雕塑佛像玻璃钢雕塑厂家四川室内商场美陈销售宁江玻璃钢花盆花器景观校园玻璃钢景观雕塑定做草地玻璃钢雕塑定做深圳公园玻璃钢雕塑销售厂家玻璃钢花盆久了会裂开吗河源仿铜西式玻璃钢雕塑文山玻璃钢雕塑厂家直供江苏几何景观玻璃钢雕塑生产香港通过《维护国家安全条例》两大学生合买彩票中奖一人不认账让美丽中国“从细节出发”19岁小伙救下5人后溺亡 多方发声单亲妈妈陷入热恋 14岁儿子报警汪小菲曝离婚始末遭遇山火的松茸之乡雅江山火三名扑火人员牺牲系谣言何赛飞追着代拍打萧美琴窜访捷克 外交部回应卫健委通报少年有偿捐血浆16次猝死手机成瘾是影响睡眠质量重要因素高校汽车撞人致3死16伤 司机系学生315晚会后胖东来又人满为患了小米汽车超级工厂正式揭幕中国拥有亿元资产的家庭达13.3万户周杰伦一审败诉网易男孩8年未见母亲被告知被遗忘许家印被限制高消费饲养员用铁锨驱打大熊猫被辞退男子被猫抓伤后确诊“猫抓病”特朗普无法缴纳4.54亿美元罚金倪萍分享减重40斤方法联合利华开始重组张家界的山上“长”满了韩国人?张立群任西安交通大学校长杨倩无缘巴黎奥运“重生之我在北大当嫡校长”黑马情侣提车了专访95后高颜值猪保姆考生莫言也上北大硕士复试名单了网友洛杉矶偶遇贾玲专家建议不必谈骨泥色变沉迷短剧的人就像掉进了杀猪盘奥巴马现身唐宁街 黑色着装引猜测七年后宇文玥被薅头发捞上岸事业单位女子向同事水杯投不明物质凯特王妃现身!外出购物视频曝光河南驻马店通报西平中学跳楼事件王树国卸任西安交大校长 师生送别恒大被罚41.75亿到底怎么缴男子被流浪猫绊倒 投喂者赔24万房客欠租失踪 房东直发愁西双版纳热带植物园回应蜉蝣大爆发钱人豪晒法院裁定实锤抄袭外国人感慨凌晨的中国很安全胖东来员工每周单休无小长假白宫:哈马斯三号人物被杀测试车高速逃费 小米:已补缴老人退休金被冒领16年 金额超20万

玻璃钢生产厂家 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化