Programming Basics Flashcards
(46 cards)
How to output “ Hello World “ in CMD using Java?
public class Filename >1
{ >2
public static void main ( String[]args ) >3
{ >4
System.out.println(“Hello World”); >5
} >6
} >7
What does the world public mean in the first line of Java ?
- A keyword of Java language that indicates that the element that follows should be made available to other Java elements.
- Other class can also use it
What does the curly brackets ( {} ) do in 2nd line and the last line?
- Everything that are included in the curly brackets belongs to the class
What does the word void mean ?
- To indicate that no value is returned
- To let the program just run the program and return nothing
What does static mean ?
- To run the method without calling on the class
What does String [] args mean ?
- It is a parameter list
Why it was not advisable to create identifiers using the Java Keywords
- May lead to confusion
What is Java most concerned about ?
Case Sensitive
- for to For , it will be printing error
The most important programming tips
- Remember to semicolon ( ; )
- Remember to check if there is any word that are being written in Uppercase Letters
Java Keywords also known as
Reserved words
Statements format ( 5 )
1.Declaration Statement
- int i ;
- String name ;
- Assignment Statement
- i = 42 ;
- name = “ ADI “
- Declaration + Assignment
- int i = 42
- String name = “ ADI “
- Expression Statement
- System.out.println(“Hello World”)
- Many other more
- for
- if
Statement must type semicolon ( ; ) after finishing
- Declaration
- Expression
How can you create a block ?
- Using brace { }
Do we need to add semicolon after creating a block ?
No
Which is correct?
1. int Total
= 100;
2. int Total = 100;
Both are correct
What are double and float different ?
- double - to represent double-precision 64-bit floating-point numbers
- float - To represent single-precision 32-bit floating-point numbers
How to create a comment?
- Type // ( End-of-line Comments )
- Type /* */ ( Traditional Comments )
- ( Java DOC Comment )
All identifiers must begin with what?
Letter ( a , d , A)
What are the differences of state and behavior in Java?
- Consist data that the object might be keeping track of.
- Consists actions that the object can perform.
Key Principles of OOP
- Encapsulation
- Encapsulation is the bundling of data (attributes) and methods (functions) that operate on the data into a single unit, known as a class. - Abstraction
- Abstraction involves simplifying complex systems by modeling classes based on the essential properties and behaviors they share. - Inheritance
- Inheritance is a mechanism that allows a new class (subclass or derived class) to inherit the properties and behaviors of an existing class (superclass or base class). - Polymorphism
- Polymorphism allows objects of different classes to be treated as objects of a common superclass.
( PIEA )
What are usually used for variable names in Java ?
Camel case ( myClass1Object )
How to create another class
- Create a new class in a different file
- Then in the main file type :
Greater ( Another class file name ) myGreeterObject ( Hold the objects in the Greeter file ) = new Greeter(); ( Create new objects )
Variable must start with what first?
- Letter ( m,k,l ,small letter first [ camel case ] )
- Underscore ( _ )
- Dollar Sign ( $ )
What are class variable also known as?
Static Variables