Computational Applications in Nuclear Astrophysics using Java Java course Lecture 1 Prepared for course 160410/411 Michael C. Kunkel m.kunkel@fz-juelich.de Materials taken from; docs.oracle.com Teach Yourself Java ISBN 9780078825705
Course Outline Introduction to Java Including Installation Installing a Java IDE (Eclipse) Introduction to Github Introduction to Maven Using Java, Maven, and Github for this courses applications Java for the coding Maven for code deployment Github for code bookkeeping
Brief Intro What is Language? language is the use of words/gestures, their pronunciation, and the methods of combining them used and understood by a community Foreign language is a language that gives people a chance to communicate with foreign people Language *Foreign Language*
Brief Intro What is Programming language? Programming language a type of language, like foreign language, that gives opportunities to communicate to computers Programming Language
Brief Intro Programming language acts as a translator between humans and computers ACode.java Java Code Complier 100010010100 100011111010 101011111010 Machine Language Programming language Human readable/writeable Compiles code from programming language to machine language Native language for machines. Binary and hard to understand
Java Java is Open Source Object Oriented Platform Independent (Write once, Run anywhere) Large Scale High level (Closer to human language) Programming language Similar to C/C++, but a bit cleaner
Java vs. C ++ Java is a true object oriented language, while C ++ is the C language with an object oriented extension. Here is a list of some major C ++ features that were omitted (intentionally) from Java Java does not support operator overloading have template classes support multiple inheritance of classes support global variables use pointers use header files
Java Machine Code vs. ByteCode Machine Code Lowest level programming language that can be directly understood by a CPU. Usually long binary sequences of 0 and 1 ByteCode Compiled Java code that is created by the compiler (javac) Loaded by Java interpreter (java) in Java Virtual Machine (JVM)
Java What is JVM (Java Virtual Machine)? Java code execution environment software that interprets ByteCode for the computer Java Code Java Runtime Environment (JRE) Java Virtual Machine (JVM) Operating System (Mac OS, Windows, Linux, Solaris.) Hardware
Java Quick recap on how a Java applications work 1. Program codes saved into source code file Example: MyApp.java 2. Source code is compiled by complier 3.Compiler created ByteCode 4.ByteCode interpreted for OS platform by Java interpreter (Java) in Java Virtual Machine (JVM)
Java Quick recap on how a Java applications work Java Code Example MyApp.java Compiler (javac) Class File MyApp.class (ByteCode) Interpreter (java) JVM OS platform
Installing Java Windows 10 Find if you have Java for Windows 1. Click the Start button 2. Scroll through the applications and programs listed until you see the Java folder 3. Click on the Java folder, then About Java to see the Java version Windows 8 1. Right-click on the screen at bottom-left corner and choose the Control Panel from the pop-up menu. 2. When the Control Panel appears, select Programs 3. Click Programs and Features 4. The installed Java version(s) are listed. Windows 7 and Vista 1. Click Start 2. Select Control Panel 3. Select Programs 4. Click Programs and Features 5. The installed Java version(s) are listed. Windows XP 1. Click Start 2. Select Control Panel 3. Click the Add/Remove Programs control panel icon 4. The Add/Remove control panel displays a list of software on your system, including any Java versions that are on your computer.
Installing Java Find if you have Java for Unix (Mac or Linux) Open a terminal Mac (command + space ) to open spotlight type terminal-> open terminal Linux (depends on flavor) Ubuntu: Open Desktop application menu type terminal-> open terminal In terminal type java -version We will be using Java 8 i.e. java version 1.8.X_XX
Installing Java In web browser go to http://www.oracle.com/technetwork/java/ javase/downloads/index.html Or Google Java Download. Make sure you go to official Oracle website
Installing Java Scroll Down until Click Here
Installing Java 1.Read 2.Accept 3.Choose 4.Install per OS methods
IDE A tool to aide in coding, packaging and compiling codes in Java (also other languages) is an IDE (Integrated Development Environment.) An IDE provides features, including but not limited to: Source code editing Syntax Highlighting Debugging Automatic method completion
IDE In this course, its not mandatory to use an IDE. However, most features we will use in this course such as Github, Maven, importing external libraries are integrated into most IDE s Eclipse, Netbeans, IntelliusJ are some examples of IDE s Eclipse is the preferred IDE for this course
Eclipse Download and install Eclipse In a web browser go to http:// www.eclipse.org/ Scroll to the bottom and click Packages Choose Eclipse IDE for Java EE Developers
Eclipse 1. Go here 2. Click here
1. Click here Eclipse
Eclipse 1. Choose
Optimizing Eclipse This will be a hands on Demo and should take approximately 5 minutes Will demonstrate: Formatting source code upon save Content assistance Authoring codes
First Program Lets open Eclipse Lets make a new Java Project File->New->Other->Java Project Name it HelloWorld
Java Package: A group of related files
Java Every Java program must have a public class. A Java program can have only one public class, but can have other classes not declared public. The file name must be the same as the public class name.
Java The entrance and exit of all Java executions is in the main method
Java Public: Method can be accessed by anywhere it is called Static: This is a main method that should be loaded to memory once Void: Method will not return any value after execution main: this is where the execution of java begins String[] args Required for all main method declarations An array of command line parameters in an array of String type. These are specified when program is ran.
Java Click in here and lets play with some Eclipse content assistance Since we configured Eclipse to have content assistance lets type sys (at this point Eclipse should have a scroll down box of suggestions) syserr - Print to standard error - System.err.println() sysout - Print to standard out - System.out.println() systrace -Print current method to standard out - Scroll and tell me what it says.
Homework Lets use sysout - System.out.println() Inside the () place anything inside. It will be a string literal, while any numerical calculation from Classes, methods or input can be placed without Concatenate by using the + operator Using System.out.println() print to the screen Hello World
Homework Hit the Run button to see output Congratulations, that is your first Java Program
Next Class More Java GitHub Maven