Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12
Programming
with JAVA
Lecturer: Isuri Rajapaksha
Content • What is java • History of Java • Data Types • Variables • Value assigning • Printing assigned values What is Java?
• Java is a special language computers understand.
• Easy Language: Java is like a common language that helps us talk to computers and make them do what we want. • Works Everywhere: (Platform Independence) -Imagine writing a message that anyone can read, no matter what language they speak. Java is a bit like that—it works on many different types of computers without needing changes. • "Write Once, Run Anywhere": With Java, we write our instructions just once, and they can work on any computer that knows Java. • Java is used to make lots of things, like games, apps for phones, websites, and even big computer systems used by companies. History of Java • Creation: Java was created by James Gosling and his team at Sun Microsystems in the mid-1990s. • Purpose: It was designed to be a versatile, platform-independent language for small devices and embedded systems initially. • Evolution and Impact • Versions: Over time, Java evolved with new versions, adding features and improvements for developers. • Oracle's Involvement: Oracle Corporation acquired Sun Microsystems in 2010, taking over Java's development and support. Data Types • 1. Primitive Data Types: • Primitive data types are the basic data types that are built into the Java language. They represent single values and are not objects. There are eight primitive data types in Java. • 2. Non-Primitive (Reference) Data Types: • Non-primitive data types are not predefined in Java. They are created by the programmer and are derived from primitive types. They are also known as reference types because they reference objects. 1. Primitive Data Types: 2.Non-primitive data types • Non-primitive data types are not predefined in Java. They are created by the programmer and are derived from primitive types. They are also known as reference types because they reference objects. Some common non-primitive data types include: • Arrays: Collections of elements of the same type stored in contiguous memory locations. • Strings: Sequences of characters, treated as objects in Java, although not primitive types. • Objects: Instances of classes, comprising attributes (variables) and behaviors (methods). Variables • Declaration of Variables: • Memory Reservation: When we declare a variable in Java, we're informing the computer's memory to allocate space for that variable based on its data type. • ex: int x = 10; Variable Naming Conventions in Java: • Start with a Letter or Underscore: • Variable names must begin with a letter (A-Z or a-z) or an underscore (_). • They cannot start with a number or special characters (except underscore). • Use Alphanumeric Characters and Underscore: • After the initial letter, variable names can include letters, numbers, or underscores. • Special characters (like *, $, %, etc.) are not allowed in variable names. • No Spaces or Reserved Words: • Variable names cannot contain spaces or tabs. • Avoid using keywords(int.float) • Case sensitive Value Assigning • Assigning a value to a variable means storing a specific piece of information in that variable. • Ex : • int x = 5; • int number = 10; • double decimal = 3.14 • char letter = 'A'; Printing Assigned Values:
• System.out.println(): It's a function provided by Java to show
information or results of a program to the user. • System.out.println(“hello ,World ! “); Thank You!