Core Java Flashcards
Learning Objectives
To install the JDK using Synaptic
Package Manager.
To run java program, we need to install JDK and Java development kit
Why Java?
Simple Object oriented Platform independent Safe High performance Multi-threaded
Types and applications of Java.
Types and Applications of Java JSP or Java Server Pages Java Applets J2EE or Java Enterprise Edition JavaBeans Mobile Java
Create a simple java program.
class HelloJava { public static void main(String[] args){ System.out.println("My first Java program"); } }
Description :- Public - access modifier, visible to all Static - no need to create object to invoke static method Void - return type. Main - starting point System.out.println - print statement
Naming Conventions in Java
The class name should be in CamelName Example:- PayPal, iPhone, MasterCard.
The method name should be in mixed case
Also method name should be an verb
Example :- showString(), main(),
goToHelp().
Variable name should not begin with digits
We cannot use keywords for class, method and variable name
Example:- Cannot use keywords like
public, private, void, static and many
more.
Install Eclipse on Ubuntu
Install Eclipse on Redhat
fetch software update
-> sudo apt-get update
install software -> sudo apt-get install eclipse Ubuntu - Similar OS Debian Kubuntu & Xubuntu
fetch software list
->sudo yum upate
install software
->sudo yum install eclipse
Redhat - Similar OS
Fedora
Centos
SUSE Linux
—-Introduction to Eclipse—-
What is Eclipse?
Eclipse is a Integrated development environment. One can write, debug and run Ava program with ease
Possible Errors
Missing semicolon Missing double quotes Mis-match file name and class name Typing print statement in lower case
Programming Features Used in
Eclipse IDE
Auto completion
Syntax error highlighting
Error dialog box
Shortcut keys
Data types in Java
There are in total 8 data types defined in Java programming known as the primitive type
Numerical data type
int, float
Arithmetic Operations
Addition : + Subtraction : - Multiplication : * Division : / Modulo Operation(Remainder after division) : %
String Create strings Add strings Convert to lower case Convert to upper case
String in Java, is a sequence of
characters
public class StringDemo { public static void main(String agrs[]){
String greet = "HeLlO"; String name = "JaVa"; char SPACE = ' '; greet = greet.toLowerCase(); name = name.toUpperCase(); String msg = greet + SPACE + name; System.out.println(msg); } }
Output :-
hello JAVA
Type Conversion
Converting one data type to another
Type Conversion
Converting one data type to another
Java facilitates type conversion in two forms:
Implicit (Automatic) Type Conversion
Explicit Type Conversion
Implicit type conversion
Also called as widening conversion because the compiler converts the value of (smaller size) type to the boarder(large size)
byte ——— is convertible to ————-> short, int, long, float, or double
Short ——— is convertible to ————-> int, long, float, or double
char ——— is convertible to ————-> int, long, float, or double
int ——— is convertible to ————-> long, float, or double
long ——— is convertible to ————-> float or double
float ——— is convertible to ————-> double
Explicit type conversion
It is also called as narrowing conversion(narrowing of broader data type to smaller data type). The type casting is done manually by the programmer and not by the compiler