Posts

Showing posts from 2018

Taking Input from the user in Java

Image
Taking Input From User Three ways to accept the value dynamically From Cmd prompt From keyboard From properties file Cmd prompt:  Using main method passing the input values as array of String object (String args[]) Convert the received String objects using wrapper classes as follows:               public static xxx parsexxx(String).               Ex: To convert String to integer               int a = Integer.parseInt(args[0]); From Keyboard: Use Scanner class from java.util.scanner package Scanner s = new Scanner (System.in);                 int firstNumber = s.nextInt(); From properties file: Create file name db.properties and data as key=value format as follows: Read the properties file using FileReader and properties class in main method as follows:

Control Statement in Java

Control Statement The control statement are used to control the flow of execution of the program Types of control statements               Selection Repetition Branching Selection  Statements                                if-then, if-then-else and switch Repetition Statements                                while, do-while and for Branching statements                               break, continue and return

Constant in Java

Constant in Java  A constant in java is used to map and exact and unchanging value to a variable name. Final variables are often declared with static keyword in java and treated as constant . Final keyword in variable declaration: Syntax: final datatype v 1 = val 1 , v 2 =val 2, ----------------------V n = Val n ;              Ex: public static final double PI = 3.14159; Final keyword in method level: A java method with final keyword is called final method and it cannot be overridden in sub-class . Syntax:  final returntype methodname(list of formal parameters)                       {                                    block of statements;                        }               ...

Java Keywords List

Image
Java Keywords

Enums in Java

Enums in Java Enums were introduced in java 5.0 Enums restrict a variable to have one of only few predefined values. The values in this enumerated lists are called enums. With the use of enums it is possible to reduce the number of bugs in your code. For Example, if we consider and application for fresh juice shop, it would be possible to restrict the glass size to small, medium and large. This would make sure that it would not allow anyone to order any size other than the small, medium or large.

Java Modifiers

Java Modifiers Modifiers are keywords that you add to those definitions to change their meanings. Access Modifiers: public, protected, private, default Java provides a number of access modifiers to set access levels for classes, variables, methods and constructors. The four access levels are: Visible to package, the default. No modifiers are needed. Visible to class only (private). Visible to world (public). Visible to the package and all subclasses (protected). Non-access Modifiers: static, final, abstract, strictfp Java provides a number of non-access modifiers to achieve many other functionality. The static modifiers for creating class methods and variables. The final modifiers for finalizing the implementations of classes, methods and variables. The abstract modifier for creating abstract classes and methods. The synchronized and volatile modifiers, which are used for threads.

Data Types In Java

Image
Java Data Types Primitive data types: These data types allow variable to store only one value.     Ex: double salary = 25350.56; Non-primitive or derived data types: These data types allow the variables to store multiple value of the same data type.    Data Types:    Arrays            Ex: int a[] = {10,20,30,40,50}    Strings are enclosed in ""            Ex: String printval = "welcome"; User defined data type: These are developed by programmers and whose variables allows to store multiple values wither of the same type or different type or both. Ex: classes, interfaces.

Variable in Java

Image
Variable in Java Variables is the name of  reserved area allocated in memory. Identifier are those whose value will change during execution of the program. Rules: First letter must be and alphabet. Length can be up to 32 characters. No special character is allowed except underscore (_). No keyword to be used. Local Variable: Declared within the body of method. Instance Variable: The variable which is associated with the object of that class. Static Variable: The variable which is associated with a class, not the object of the class.(Eg: used in counting of the object)

Java Basics and Naming Conventions in Java

Image
Java Basics Case Sensitivity - Java is case sensitive, which means identifier Hello and hello would have different meaning in Java. Class Names - For all class names the first letter should be in Upper Case. If several words are used to form a name of the class, each inner word's first letter should be in Upper Case. Example  : class MyFirstJavaClass Method Names - All method names should start with a Lower Case letter. If several words are used to form the name of the method, then each inner word's first letter should be in Upper Case. Example : public void myMethodName() Program File Name - Name of the program file should exactly match the class name. When saving the file, you should save it using the class name (Remember Java is case sensitive) and append '.java' to the end of the name (if the file name and the class name do not match your program will not compile). Example : Assume 'MyFirstJavaProgram' is the class name. Then the ...

Download, install and print helloworld in Eclipse on Windows(x86 and x64)

Image
Please follow the below given steps to download and install eclipse to your windows machine. Step 1 :  Open browser of your choice and got to the address " http://www.eclipse.org/ " and click on download link. Step 2 : Click on 'Download Packages'. Step 3 :  Click on 32 bit/64 bit link according to your machine from 'Eclipse IDE for Java EE Developrs'. Make sure that 'Windows' is selected in drop down. Note: If you have installed java 32 bit install 32 bit eclipse and if you have installed java 64 bit install 64 bit eclipse to avoid any error. Step 4 : Click on 'Download' button to download eclipse or you can 'Select Another Mirror' to download it from another mirror which is near to your location. Note: Once downloading starts, you will see "Thank you for downloading Eclipse" Page. Step 5 : Extract eclipse from zip. Step 6 :  Double Click on eclipse.exe or to create shortcut on d...

Java System Overview and Differences between C++ and Java

Image
Java System Overview Differences between C++ and JAVA

Difference Between Compiler and Interpreter and Difference between JDK, JRE and J VM

Image
Difference Between Compiler And Interpreter  A compiler takes entire program and converts it into object code which is typically stored in a file. The object code is also refereed as binary code and can be directly executed by the machine after linking. An Interpreter directly executes instructions written in a programming or scripting language without previously converting them to an object code or machine code. Difference Between Java Development Kit(JDK), Java Run Time Environment(JRE) And Java Virtual Machine(JVM) JVM ( Java Virtual Machine ) is an abstract machine. It is a specification that provides runtime environment in which java bytecode can be executed. JVMs are available for many hardware and software platforms. JVM, JRE and JDK are platform dependent because configuration of each OS differs. But, Java is platform independent . The JVM performs following main tasks: Loads code Verifies code Executes code Provides runtime environment ...

Java Platform and Internal Architecture of Java Virtual Machine(J VM)

Image
 Java Platform Java is a programming language and a platform. A Platform is hardware or software environment in which a program runs. Most popular platforms like Microsoft Windows, Linux, Solaris OS, and Mac OS. Java is a software-only platform that runs on top of other hardware-based platforms. The Java platform has two components:        The Java Virtual Machine( JVM )       The Java Application Programming Interface ( API ) API is grouped into libraries of related classes and interfaces, these libraries are known as packages . Java Virtual Machine(JVM) JVM is the part of Java Run Time Environment(JRE) and it is responsible to load and run the java class file. Internal Architecture of Java Virtual Machine(JVM) Class Area : It stores per-class structures such as the run time constant pool, field and method data, the code for methods. Heap : Run time data area in which objects are allo...

Java History, Features and Application types

Java History Java is just a name not an acronym. James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June 1991. The small team of sun engineers called Green Team. Firstly, it was called "Greentalk" by James Gosling and file extension was .gt. After that, it was called Oak and was developed as a part of the Green project. Java is an Island of Indonesia where first coffee was produced. Originally developed by James Gosling at Sun Microsystems (which is now a subsidiary of Oracle Corporation) and released in 1995. There are many java versions that has been released. JDK Alpha and Beta (1995) JDK 1.0 (23rd Jan, 1996) JDK 1.1 (19th Feb, 1997) J2SE 1.2 (8th Dec, 1998) J2SE 1.3 (8th May, 2000) J2SE 1.4 (6th Feb, 2002) J2SE 5.0 (30th Sep, 2004) Java SE 6 (11th Dec, 2006) Java SE 7 (28th July, 2011) Java SE 8 (18th March, 2014) Java SE 9 (21st Sept, 2017) Java SE 10(Java 18.3)about to release in March 2018 Java Feature...

Download and Install Anaconda on Windows Machine

Image
Please follow the below steps to install Anaconda Step 1 : Open browser and go to the address " https://www.anaconda.com/ " and click on 'Download' link under 'Products' in menu. Step 2 :  Scroll down and click on 'Download' to download anaconda. Step 3 :  Click on anaconda .exe file to start installation. Step 4 :  Click on 'Run'. Step 5 :   Click on 'Next'. Step 6:  Click on 'I Agree' to accept the license agreement. Step 7 : Keep Selected 'Just Me' and click 'Next'. Step 8 :  Click 'Next' if you wan't default destination folder or you can browser to select different location. Step 9 :  Customize how anaconda integrates with windows, I kept it as default Python 3.6 and click Next. Step 10 :  Installation Progress will Start. Step 11 :  Once installed click 'Finish'. Step 12 : Click on 'Anaconda ...

Download, Install and Print 'Hello World!' in Python on Windows Machine

Image
Please follow the below steps to download, install and print 'Hello World!' in python on windows machine. Step 1 :  Open browser of your choice and go to the address " https://www.python.org/ ". Step 2 : Click on 'Downloads'. Step 3 : Click on 'Python 3.6.4' or 'python 2.7.14'  to download the python for windows(please check the difference between python 3 and python 2 form the link given below the download buttons). If you are looking for specific release then scroll down and click on download to download the specific python version. Step 4: Click on python exe to start installation. Step 5 : Click on Run Step 6 :  Click on 'Install Now', once clicked on Install Now it will start 'Setup Progress' followed by 'Setup was successful' Step 7 : Click on start window button and search for 'python' and click on 'Python 3.6 (32-bit)'. Step 8: This will...