Overclock.net - An Overclocking Community - View Single Post - Is there a trick to learning Java?
View Single Post
post #5 of (permalink) Old 01-09-2019, 08:53 PM
New to Overclock.net
Join Date: Jun 2018
Location: Hendersonville, NC
Posts: 100
Rep: 0
If its for personal use, you don't need to create an app to do what you want...

What I do is use Microsoft Calendar, the one included with Win 10 x64 Pro ( and home? ).. I created an event every single day for 30 days ( 30 events is tedious, but it can be turned into a batch process )... Calendars can be shared to be displayed on an Android, Apple or Windows / Microsoft device.

Medication - Day 1 - 12 AM - Replace Patch
Medication - Active Time 0 to 24 Hours
Medication - Apply Patch [ Note: 12 AM  to 12:30 AM, give 1 hour warning - I apply anywhere from 9PM to 12AM on the night in question so the active time, which takes 3 to 6 hours, has time to start working so this day is active 0 to 24 hours, etc... ]

Medication - Day 2
Medication - Active Time 24 to 48 Hours

Medication - Day 3
Medication - Active Time 0 to 24 Hours
Medication - Apply Patch

Medication - Day 4
Medication - Active Time 24 to 48 Hours

Medication - Day 5
Medication - Active Time 0 to 24 Hours
Medication - Apply Patch

Medication - Day 6
Medication - Active Time 24 to 48 Hours

Medication - Day 7
Medication - Active Time 0 to 24 Hours
Medication - Apply Patch

Medication - Day 8
Medication - Active Time 24 to 48 Hours

Medication - Day 9
Medication - Active Time 0 to 24 Hours
Medication - Apply Patch

Medication - Day 10
Medication - Active Time 24 to 48 Hours

Medication - Day 11
Medication - Active Time 0 to 24 Hours
Medication - Apply Patch

Medication - Day 12
Medication - Active Time 24 to 48 Hours

Medication - Day 13
Medication - Active Time 0 to 24 Hours
Medication - Apply Patch

Medication - Day 14
Medication - Active Time 24 to 48 Hours

Medication - Day 15
Medication - Active Time 0 to 24 Hours
Medication - Apply Patch

Medication - Day 16
Medication - Active Time 24 to 48 Hours

Medication - Day 17
Medication - Apply Patch

Medication - Day 18
Medication - Active Time 24 to 48 Hours

Medication - Day 19
Medication - Active Time 0 to 24 Hours
Medication - Apply Patch

Medication - Day 20
Medication - Active Time 24 to 48 Hours

Medication - Day 21
Medication - Active Time 0 to 24 Hours
Medication - Apply Patch

Medication - Day 22
Medication - Active Time 24 to 48 Hours

Medication - Day 23
Medication - Active Time 0 to 24 Hours
Medication - Apply Patch

Medication - Day 24
Medication - Active Time 24 to 48 Hours
Medication - Refill Week
Medication - 555.555.555 - Refill - 3 days needed!

Medication - Day 25
Medication - Active Time 0 to 24 Hours
Medication - Apply Patch
Medication - Day 25 - Refill Week

Medication - Day 26
Medication - Active Time 24 to 48 Hours
Medication - Day 26 - Refill Week

Medication - Day 27
Medication - Active Time 0 to 24 Hours
Medication - Apply Patch
Medication - Day 27 - Refill Week

Medication - Day 28
Medication - Active Time 24 to 48 Hours
Medication - Apply Patch
Medication - Day 28 - Refill Week - LAST DAY TO GET BY FINAL DAY - Call Dr. X ( 555 ) 555.5555

Medication - Day 29
Medication - Active Time 0 to 24 Hours
Medication - Apply Patch
Medication - Day 29 - Refill Week

Medication - Day 30
Medication - Active Time 24 to 48 Hours
Medication - Day 30 - Refill Week - FINAL DAY
All of them are uniquely named. After that, I created 7 more for the final week... Refill week.

Anyways, the Refill week is a plain notification that can be set to last 7 days and repeat every 30 days so that's 1x event.. 30x events, 1x for each day. 2x events for the Active times which can repeat every other day. Then 1x for the 3 days warning and phone number. 1x event / notifier for Apply Patch text repeat every other day - this gives me a 1 hour notification to apply it at 11PM on Day - 1, however I typically apply anywhere from 9PM to 12AM - typically at 11PM, or 9PM if I have to go out the following day ( it takes 3 to 6 hours to start working, then 3 to 6 hours of severe nausea which sometimes requires medication, 1 hour + to put on street clothes, and maybe more time for hygiene.

I use a full 7 day warning week / refill week to ensure I have ample notification in case it splits up over the weekend so I can call on a Friday and pick it up on a Monday ( 3 days are 3 days in general, but they aren't open over weekends ).

The medication is Schedule 2 so the physical prescription paper needs to be picked up and dropped off in person, the prescription itself goes without saying.

In short - there are approx 35 repeat-forever events I had to add to the calendar for the 30 day medication supply and protocol ( apply 1 patch every other day, wear for 48 hours then discard safely ).

It seems tedious at first, but it is very helpful.

I have looked at prescription minders in the past, but most were too much for my medication and didn't transfer to other devices easily ( a single medication for severe pain due to a broken neck, back and severe nerve damage resulting from a car accident on May 7 2011 because someone ran a stop sign and killed me [ state of living death - living for the sake of life is meaningless especially since I am unable to do anything I was able to do before in any meaningful way, for all measurable purposes, I basically died on that day and didn't know it - I am lucky in the sense that I can get about a 40 hour work-week done in 6 months to a year - the rest of the time is spent on trying to keep the pain level to about a 3.5 / 10 at the lowest which is a lot more than stubbing your toe on the corner of your bed - imagine that constantly then double it a few times - my 10 is quite high ] )...

If you make an app, I'd suggest making something with links to Windows Calendar, Android calendar, Apple Calendar and others to easily import them... Although, you could focus on Google or probably even Windows since you can import those calendars with default features in most other calendars anyways...

I get my notifications on the default Google calendar on my WiFi phone if I do go out, but I don't change it on the road ever - but in the event of an emergency it is there...

I hope this gives you some ideas for the design or how to schedule what could be considered helpful - ask simple questions - how long does your doctor take to fill prescription, include weekends?, include holidays?, requires pickup?, etc... then have it generate a batch import for whichever calendar is used - then log in to Microsoft, Google or where-ever account and then import the tasks immediately instead of developing your own calendar ( super easy to make a stock calendar ) and all of the functionality...

That way you don't have to worry about debugging, and it becomes an incredibly useful utility which anyone can use since it asks the important questions, then imports to their existing calendars... Obviously save the data if there is a change, and if there was an import, track the event ids so you can edit them on change, or erase them completely...

Also ask how often they want reminders... Per medication, per day, per mealtime, etc... Also, adding in a feature which takes their medications and reorganizes the time taken to optimize pill-taking to reduce the frequency during the day - obviously ask if there are restrictions against taking with any other...



I wanted to touch on some of what previous posts have mentioned...

Adding permissions to the app isn't difficult - this lets those that download it know what to expect. Knowing where you are doesn't need to be used from the phone permissions - you can simply ask for a zip-code, or you can ask for their pharmacy, pharmacy phone number, doctor phone number, and important info to keep on hand if someone finds it such as a medical professional if you're hurt for a medical card.... Using that info you can use online resources...

You can use the phone to get the location, but the more permissions you require of the user, the less likely they will install it. Actually, this isn't quite true. Some people don't pay attention to the permissions, but people are becoming more and more aware and are wondering why an app which does one thing requires an completely unrelated permission... I'll give an opposite example: A camera app may require location to add the proper meta-data... A shopping app would need to know the GENERAL location to show you stores which have x or y or z in your area... and so on... But an app that is a plain-text editor doesn't need your location. Neither does a recipe-minder...

Don't add permissions just to make it easier on yourself. If you read the WiKi you can see which functions / calls will require certain permissions - some calls can be linked to more than one value for a permission type.. For instance, and I'll use location again: Location permissions can ask for a GENERALIZED location for the user, this can be simple from country, state and nearest city or so... To something maybe a little more specific. This is good for dating apps. Then there is an EXACT location value which uses GPS and / or Wireless signals ( which are recorded when a Google car drives by for Street-View or other uses ) to track a more accurate location which can be accurate to 10 feet or so... A dating app does NOT need this - if someone were to crack it, such as a stalker, then that person would know where another was to within a few feet which can make for a dangerous situation.

I mention these to help you focus on what you need...

Since you deal in prescription minding, and want to have convenience to it by either notifying the pharmacy, doctor or whatever automatically ( also, a lot of pharmacies will auto notify your doctor for your prescription and have it auto filled if you ask them to - so your app doesn't need this, but to automatically fax or e-mail your doctor for a long-term schedule 2 medication wouldn't be terrible ) then you really don't need location... As I said before, you can ask them their location when they open the app - ask for a medical card worth of info such as your primary doctor, allergies, phone numbers, etc... this can help them remember and if you add in an auto notification to your doctor such as digital faxing via the app to your doctor then you can include the pharmacy, store phone number / address, etc... and not need permissions ( unless they've added a new one for internet usage - although there is one for data but that may only be for texting, I can't recall off the top of my head but the WiKis are most helpful and can answer a lot of questions )...

Anyways, before I dive to deep in all of that...

Java is a higher level language meaning its closer to English than say C++... You still need to know Logic - I'd recommend a philosophy course called Symbolic Logic which can teach you logic ( which is used everywhere ), expressions - inversions and so on..

Next, if you're having trouble with tutorials - don't feel bad. A lot of tutorials deal with specific questions to specific answers. To start with though, I'd recommend looking at object tutorials - things such as class Shape being a base class, class Square extending Shape, Class Rectangle extending Square.. Class Circle extending Shape, class Triangle extending Shape, etc.. Also things such as Class Person, class Employee extends Person, Class Business, etc...

Those simple examples will show you how objects work in Java - as Java is Object Oriented, a lot of the programming will be done using objects which need to be understood to use them properly. Other bits in coding are logic and iteration ( loops / repetition ).

Look into things such as, as said, Objects, and then, Data-Types such as Strings, Integers, Floats, Longs, Doubles, Arrays, Chars, and more. Data-Types can be simple or based on objects... For instance, in Java a simple data type such as a whole number ( integer ) will be stored in memory and the variable used to reference it will point straight to it, as is. A complex data type such as an object will be stored in memory, however the variable / reference will only store the memory address. Strings are a mix in Java between simple and complex.

Java has a Garbage Collector, which is helpful, but to a new programmer it can be a problem. It deletes things from memory ( RAM ) which have been stored, but a reference / variable reference doesn't exist anymore.. For instance if you did something like blah = String( 'A simple string' ); blah = null; in Java - blah will point to #AABBCCDD or so - a memory address with the data... But when you do blah is assigned to null ( blah = null ) then you are terminating that link. You are NOT unloading that string from memory. This is how memory leaks occur in other languages - in languages such as C++ you have to remove that data from memory PROPERLY, otherwise it stays and doesn't get removed. So, a memory leak is wasted space in memory that has been used up by code and never properly unloaded to allow other data to use that space - it's like comparing a 35mm camera roll of film to a digital camera... A 35mm camera can take a photograph and store it on the film, but it can't re-use that film ( technically you can take a photo over the photo but that results in blurring, or overlaying if I recall correctly ) meaning that photo is now there and that space can't be re-used... Consider putting a new roll of film in tantamount to removing the photo from memory. The new roll doesn't get put in.... But, with the garbage collector, since the reference / variable was nulled, there is no longer anything pointing to that piece of memory ( Java also keeps track of all memory it uses for this purpose ) so it removes it.

Another cool thing Java does with some of its data-types is prevent memory-waste / repetitions.. For instance. Lets say you have blah = 'String';, blah2 = 'String', blah3 = 'String', blah2 = 'String2'... Then you end up with blah and blah3 pointing to the exact same object.. blah2 did too, until it was changed to something which doesn't exist in memory already. So, since the string 'String' existed, when the new reference to blah 2 and 3 are made, it used the same address as was stored to blah. This means you can make 10 billion blah# references to 'String' and you'll only ever have 1 instance of 'String' in memory. That doesn't mean the references themselves don't take up memory, but the object itself isn't duplicated and the object is, more often than not, larger than the reference / address...

So, objects, data-types, simple / complex, SCOPE!!!.... Look into pass by value vs pass by reference too... That will help you understand how Java passes data through function calls. Also, HIERARCHY and INHERITANCE... VERY Important for extending objects...

Anyways... Start small.. Make simple objects, extend those, play around with them... Play around with loops, iteration... A few simple programs you should try making before going into apps:

Scope is important to lean.. It goes from the outside in.. So you have the file scope, you have whats inside any { }s so loops, if statements, more... If you create a variable outside of a { } then anything within that { } can see it, and any changes made to that variable / reference within can be seen on the outside. But, if you create a variable within { } and try printing outside, it will not exist. Read up on Scopes - I have only scraped the surface here, but it is very important... You have functions too - those are independent scopes and there are cool side effects for these... In languages where you can create a function within an if statement you can access the variables / data from outside of the function within the function as long as the vars are differently named to the arguments... You can do this with any function you define too, if you create a file-scoped var ( say a var at the top of the file ) and a function below, then call the function below that, you can read the data from within the function..

Not all languages are as lenient. I can't recall exactly how Java behaves in these cases - ie if it requires the variable to be global or if it can be a basic var... etc..

- Console out: Hello World ( Requires importing modules for system out / printing )

- Play with scope - create a var blah = 'Test' and print it out, then create if ( true ) { print( blah ) } and see what happens. Then create blah = 'Test'; print( blah ); if ( true ) { blah = 'String'; print( blah ) } print( blah ) and see what happens. Then create the same except without the blah = test outside of the if statement.. only inside and keep both prints and see what happens.

- Console In / Out: What is your name? Input > John Doe [ Enter ]. Thank you.. Your name is John Doe!

- Loop: Print 1 through 100 to console

- Loop, the same as above except use a while loop instead of for 1 to 100 style loop - use while ( true ) and inside have if ( i = 100 ) break; with i = 0 / 1 outside of the loop, i++ inside and print the i...

- Console in / Out - What is your name? This time, have the console in and out inside of loop - use a do { ... } while ( true ); style loop.. If the name is an empty string, or there are any characters other than a-z, A-Z or . in the name, print that there was an error processing the name and ask for the name again.. If it is good, then break; out of the loop and print the data - remember because of scope, initialize the variables outside of the loop so they can be used outside of the loop.

- Intro to classes - create a simple base class - call it Shape and have 1 var and call it name... Set it to 'Shape'... create a to string method and have it System.out / print( 'I am a shape - my exact shape is ' + this.name ); ( Note: I can't recall if Java uses + for String concatenation but I believe it does - if not it could be . )...

- Next step in classes - Create a new class, call it Square, have it extend Shape and add a new variable name it x - default to 1.. On initialization of the object, require x be added - use 1 as the default if not... Also override the name to 'Square'.. Create a few more functions... Area - return x * x, and other square functions you want to add...

- Next step in classes - Create a new class, call it Rectangle and have it extend Square.. Add a new variable y. Copy the Area function and change x * x to x * y. Also set the name to Rectangle or Rect. Add more rectangle functions if you want. NOTE: You can also reverse these... You could have Square extends Rect and simply ignore y, but this means you have y just hanging out so you're wasting overhead ( the amount of data required to keep in memory or on file for the structure of objects, default data, etc... )

- Next classes: Circle, Triangle, and a few more you can think of.

- Next in classes: Start adding more in-depth toString methods... When you convert one of the shape objects to a string, have it output the area, circumference, and more in a nice format... Also, start adding math logic functions... ie equals, greater than, less than, greater than or equal to, less than or equal to, and more..

Note: In some languages - you only need to set up Equals and Less than ( or greater than ) and the rest are done automatically... Because with equals and Less than you can create the others... For instance if equals is eq( ) and less than is lt( ) then lets make up the others...

Note: This code isn't exact... Consider it pseudo - the logic will work though meaning gt means not lte as long as you write that out in the proper format, you're fine.
class X
	// With < and == lets do <=, >=, >, ( I can't recall if Java has <> or not equal to neq( ) )
	// Note: The reason X( 1 ) < X( 2 ) works is because X( 1 ) < X( 2 ) calls class X function lt( X other )... That function then takes this.x ( the integer / number values of x ) and compares them, and Java has built in comparators written to handle Integers / longs / Floats / Doubles ( number types ), and others... Since we created class X we have to create our own way to handle them... Its as simple as comparing the nested data within and if each object has these then you can easily compare objects to other objects and if you then create class Y without extending to X... you can have this.x = X( 1 ) and then have class Y function lt( Y other ) simply return this.x < other.x; which goes from class Y to class X to the number comparator...
	function lt( X other ) Do something like: this.x < other.x;
	function eq( X other ) this.x == other.x;

	// Less than or equal to - we have less than, we have equal to... combine them..
	function lte( X other ) return this.lt( other ) || this.eq( other );

	// Greater than means > ... meaning NOT less than or equal to: <= or just not lte / !lte
	function gt( X other ) return !this.lte( other );

	// gte = greater than or equal to - which is the same as saying NOT less than... because not less than < means >=
	function gte( X other ) return !this.lt( other );

	// Note: GTE can also be made like this meaning Return the boolean result for the expression ( Greater Than OR Equal To )[ meaning true or false ]...
	function gte( X other ) return this.gt( other ) || this.eq( other );

	// <> or Not equal to....
	function neq( X other ) return !this.eq( other );

	// <> can also be written as Greater Than OR Less Than...
	function neq( X other ) return this.gt( other ) || this.lt( other );
- Next step, add in other math functionality... Ie what happens when +, -, *, /, ^, etc.. is called? There are functions which allow objects to be compared to one another using this.. For instance, lets say you have a Position object for 2d x and y location... You can use Add to add 2 positions together...

So, again.. Like the example above.. Instead of using return this.x < other.x... we use: this.x + other.x - no return necessary unless we want a true results... so if X( 1 )
+ X( 2 ) == X.x = 3; or X( 3 ) would be similar... We'd simply use function add( X other ) or whatever the special function name is for that functionality..

Note: For these, I used similar names to Lua and Python - Java special names may be activated differently.. It's been over 6 years since I used Java for much of anything - I've been working with a dozen other languages in the mean time so its not in the forefront of my mind... Nevertheless, I do hope at least some of this has helped.

Oh.. Quick edit 2: I didn't answer your first question, or did I???

There is no trick to learning any programming language... However, the more languages you know, the more similarities you will see making it that much easier to pick up a new language.. Also.. Logic is universal so if you can use logic properly, and manipulate it... You can put it into any language as long as you know how to form the text / code.

Also, knowing how the code is written means you can take it from one language and port it to another easily. For instance, Lua uses and, by default ( GMod Lua uses and or && ) and a lot of other languages use && for and... So, to port Lua to Java you'd replace and with &&, or with ||, not with !, and so on... then you'd also replace then with {, and end with }. You'd need ;s at the end of each expression. and more...

Understanding the syntax can be a benefit.

If you are good with puzzles, I'd recommend looking at the BNF / EBNF / ABNF - It basically defines how the code fits together... It uses keywords and defines the rules of how they fit together. For instance:

-- SNIP - Long explanation of JLS which may have been more confusing than helpful so... I've removed it. --

It can be very tricky to look at a new language this way especially if you're new to programming and understand what this is... But BNF is a way to represent how the code should be written so the compiler knows if there is an issue..

I only mention BNF in case you are the type of person that can look at this with little to know experience and understand it easier this way.. But, this will only help you spot errors when typing, so it shows how to write it, but not what anything does... If you have trouble with the syntax of something, it may help... I personally look at these occasionally if I am looking at learning a new language... Usually they're not as long as depicted here.


Ah, here: https://cui.unige.ch/isi/bnf/JAVA/AJAVA.html

That looks more like BNF

To learn about BNF - you can try here: https://rsms.me/mylang-tutorial1 - that gives an easier representation of BNF


Expression           = ExpressionGroup | Number | Text | Path | List | Map
ExpressionGroup      = "(" Expression* ")"
So an Expression can be an ExpressionGroup, number text path list or map...
An ExpressionGroup is ( and ) with 0 to many Expressions within.

They have Number defined as 3 other possible keys one being IntegerNumber

IntegerNumber        = DecimalDigit+
DecimalDigit         = 0..9
So.. They define an IntegerNumber as a DecimalDigit+ ( the + means 1 or more, * means 0 or more, or optional )... So 1 or more digit in a set from 0 to 9. ie just saying any digit between 0 or 9 and the + means you can have 12345678912345 as many as you want side by side...

The HexIntegerNumber is another which defines "0x"HexDigit+ as the next which means 0x00ABCDEF for instance... because HexDigit can be 0 through 9, a through f or A through F. HexDigit+ means as many 0..9, a..f or A..F as long as there is at least 1.. 0x is always required at the start..

It's basically like assembling a puzzle if you read it from BNF form.. To create BNF you simply define what is and / or is not allowed in the language. Just because something is allowed, doesn't mean it means anything or makes anything useful in the language - it simply helps the compiler or environment sub-component know if there is an issue with the language, but, as I've said, it is useful to understand how to write things in the code if standard examples confuse you... This simply shows WHY the language is written the way it is - but it doesn't give you the meaning behind the why so it's a stale answer...

Here's another interpretation of Java BNF: https://users-cs.au.dk/amoeller/RegAut/JavaBNF.html

Anyways... Start small, then move your way up to the app.. For now, start with the basics and move up such as hello world, working with console in / out, objects, hierarchy, inheritance, scope, data-types, implementing more and more and more...

Then design a simple console app - you can make a simple version of what you want to do have have it all text based... Ie simple menu to select the option of what you want to test such as add prescription.. Answer the questions, then output... etc..

Not all of the features need to be present, but it will help you in figuring out how things work, how to code, and let you work through some problems before making the app and having to rewrite it..

Next - I highly recommend DESIGNING the app before you create it. This goes for ANY program you create..

What I mean by this is outline it...

So, it is a prescription minder - start with those 2 words, then define what it means to be a prescription minder... Ok, It should allow adding prescriptions, providing adequate notification to the user so they can easily remember which medications to take, and when.. Maybe a description of the pill and / or the container can help more forgetful people - even being able to take a photo of the pill ( ask to take a photo of the pill the first time they take it so each time the notifications show to take x medication, it shows the pill with their unique numbering [ take front and back ] )....

And build from there..

When you have a complete list of features, design how it works...

Main app menu - Show a day style calendar sheet which shows the hours in the day with line by line agenda style...
Let user scroll up and down to go to future days, and up to x days back ( allow max of 2 days by default to go backwards - allow configuration in menu )
Show the days which have already passed in a different color.
Add color-blindness / deficit mode to show a pattern such as crossing the days out instead of the color for older days
Show past hours in the same color / pattern for the current day - do not mark 1 hour prior

Define how notifications work... Define how clicks work / respond..

As soon as a pill is marked as consumed, the color changes on the planner...

Note: Display the number of pills the person should have in their pill bottle if they've been taking them as expected BEFORE they take the medication. When the user clicks they took the medication, show an animation of 1 pill being removed ( and deduct 1 from the counter ) either numerical only or a pill being removed from a First-person shooter style individual ammo counter display ( pills in rows / columns and show it going poof when they eat it )...


Go through each and every single feature. Go through or draw what it should look like. What each button press does - or screen taps.. It's better to use 1 screen tap for most, or half the screen for yes, the other for no... A lot of people will have shaky hands so the larger the button, the easier for them to use the app.. Older folks will likely use this to manage prescriptions - likely set up by younger people.

So, make the interface as easy as possible all the way through..

For taking data such as doctor name, etc.. It may be best to display a single question at a time instead of a large form - this also means they're more likely to give information opposed to none if the form is too long - Also, it makes it easier to read than a larger form and easier to go through the form for older patients...

Last edited by Acecool; 01-09-2019 at 11:14 PM.
Acecool is offline